-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83314c9
commit 570dabc
Showing
7 changed files
with
184 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
tests/Feature/Controllers/Admin/Nodes/IsoControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
use Convoy\Jobs\Node\MonitorIsoDownloadJob; | ||
use Convoy\Models\ISO; | ||
use Convoy\Models\Location; | ||
use Convoy\Models\Node; | ||
use Convoy\Models\User; | ||
|
||
beforeEach(function () { | ||
$this->user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
$this->location = Location::factory()->create(); | ||
$this->node = Node::factory()->for($this->location)->create(); | ||
}); | ||
|
||
it('can fetch ISOs', function () { | ||
$response = $this->actingAs($this->user)->getJson( | ||
"/api/admin/nodes/{$this->node->id}/isos", | ||
); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can create an ISO', function () { | ||
Http::fake([ | ||
'*/download-url' => Http::response( | ||
file_get_contents( | ||
base_path('tests/Fixtures/Repositories/Node/Storage/DownloadIsoData.json'), | ||
), | ||
200, | ||
), | ||
'*/query-url-metadata*' => Http::response( | ||
file_get_contents( | ||
base_path('tests/Fixtures/Repositories/Node/Storage/QueryIsoData.json'), | ||
), | ||
200, | ||
), | ||
]); | ||
|
||
$response = $this->actingAs($this->user)->postJson( | ||
"/api/admin/nodes/{$this->node->id}/isos", | ||
[ | ||
'name' => 'Test ISO', | ||
'file_name' => 'test.iso', | ||
'link' => 'https://example.com/test.iso', | ||
'should_download' => true, | ||
'hidden' => false, | ||
], | ||
); | ||
|
||
Queue::assertPushed(MonitorIsoDownloadJob::class); | ||
$response->assertOk(); | ||
}); | ||
|
||
it("can't create an ISO with file_name taken", function () { | ||
ISO::factory()->for($this->node)->create([ | ||
'file_name' => 'duplicate.iso', | ||
]); | ||
|
||
$response = $this->actingAs($this->user)->postJson( | ||
"/api/admin/nodes/{$this->node->id}/isos", | ||
[ | ||
'name' => 'Test ISO', | ||
'file_name' => 'duplicate.iso', | ||
'link' => 'https://example.com/duplicate.iso', | ||
'should_download' => true, | ||
'hidden' => false, | ||
], | ||
); | ||
|
||
$response->assertStatus(422); | ||
}); | ||
|
||
it('can update an ISO', function () { | ||
$iso = ISO::factory()->for($this->node)->create(); | ||
|
||
$response = $this->actingAs($this->user)->putJson( | ||
"/api/admin/nodes/{$this->node->id}/isos/{$iso->uuid}", | ||
[ | ||
'name' => 'Updated ISO', | ||
], | ||
); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can delete an ISO', function () { | ||
Http::fake([ | ||
'*/storage/*/content/*' => Http::response( | ||
file_get_contents( | ||
base_path('tests/Fixtures/Repositories/Node/Storage/DeleteIsoData.json'), | ||
), 200, | ||
), | ||
]); | ||
$iso = ISO::factory()->for($this->node)->create(); | ||
|
||
$response = $this->actingAs($this->user)->deleteJson( | ||
"/api/admin/nodes/{$this->node->id}/isos/{$iso->uuid}", | ||
); | ||
|
||
$response->assertNoContent(); | ||
}); | ||
|
||
it('can query link', function () { | ||
Http::fake([ | ||
'*/query-url-metadata*' => Http::response( | ||
file_get_contents( | ||
base_path('tests/Fixtures/Repositories/Node/Storage/QueryIsoData.json'), | ||
), | ||
200, | ||
), | ||
]); | ||
|
||
$response = $this->actingAs($this->user)->getJson( | ||
'/tools/query-remote-file?link=' . urlencode( | ||
'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso', | ||
), | ||
); | ||
|
||
$response->assertOk(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"success": 1, | ||
"data": null | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/Fixtures/Repositories/Node/Storage/DownloadIsoData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"data": "UPID:us-southeast:001BE662:04671913:65CF8596:download:virtio-win.iso:root@pam:", | ||
"success": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"data": { | ||
"filename": "virtio-win.iso", | ||
"size": 627519488, | ||
"mimetype": "application/octet-stream" | ||
}, | ||
"success": 1 | ||
} |