-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
Showing
13 changed files
with
135 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ jobs: | |
os: | ||
- "ubuntu-latest" | ||
php: | ||
- '8.0' | ||
- 8.1 | ||
- 8.2 | ||
- 8.3 | ||
experimental: | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,44 @@ | ||
<?php | ||
|
||
namespace NovaKit\NovaQueuedExportAsCsv\Tests\Feature; | ||
|
||
use Illuminate\Support\Facades\Queue; | ||
use NovaKit\NovaQueuedExportAsCsv\Actions\QueuedExportAsCsv as QueuedExportAsCsvAction; | ||
use NovaKit\NovaQueuedExportAsCsv\Jobs\QueuedExportAsCsv as QueuedExportAsCsvJob; | ||
use NovaKit\NovaQueuedExportAsCsv\Tests\TestCase; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class QueuedExportAsCsvActionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_generate_queued_action() | ||
{ | ||
Queue::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
|
||
$response = $this->withoutMix() | ||
->actingAs($user) | ||
->post('/nova-api/users/action?action='.(new QueuedExportAsCsvAction)->uriKey(), [ | ||
'resources' => 'all', | ||
]); | ||
|
||
$response->assertOk() | ||
->assertJson(['message' => 'The action was executed successfully.']); | ||
|
||
Queue::assertPushed(function (QueuedExportAsCsvJob $job) use ($user) { | ||
return $job->userId === $user->id; | ||
}); | ||
} | ||
|
||
#[Test] | ||
public function it_can_generate_queued_action_with_custom_response() | ||
{ | ||
Queue::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
|
||
$response = $this->withoutMix() | ||
->actingAs($user) | ||
->post('/nova-api/subscribers/action?action='.(new QueuedExportAsCsvAction)->uriKey(), [ | ||
'resources' => 'all', | ||
]); | ||
|
||
$response->assertOk() | ||
->assertJson(['message' => 'Action has been queued!']); | ||
|
||
Queue::assertPushed(function (QueuedExportAsCsvJob $job) use ($user) { | ||
return $job->userId === $user->id; | ||
}); | ||
} | ||
} | ||
|
||
it('can generate queued action', function () { | ||
Queue::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
|
||
$response = $this->withoutMix() | ||
->actingAs($user) | ||
->post('/nova-api/users/action?action='.(new QueuedExportAsCsvAction)->uriKey(), [ | ||
'resources' => 'all', | ||
]); | ||
|
||
$response->assertOk() | ||
->assertJson(['message' => 'The action was executed successfully.']); | ||
|
||
Queue::assertPushed(function (QueuedExportAsCsvJob $job) use ($user) { | ||
return $job->userId === $user->id; | ||
}); | ||
}); | ||
|
||
it('can generate queued action with custom response', function () { | ||
Queue::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
|
||
$response = $this->withoutMix() | ||
->actingAs($user) | ||
->post('/nova-api/subscribers/action?action='.(new QueuedExportAsCsvAction)->uriKey(), [ | ||
'resources' => 'all', | ||
]); | ||
|
||
$response->assertOk() | ||
->assertJson(['message' => 'Action has been queued!']); | ||
|
||
Queue::assertPushed(function (QueuedExportAsCsvJob $job) use ($user) { | ||
return $job->userId === $user->id; | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,42 +1,33 @@ | ||
<?php | ||
|
||
namespace NovaKit\NovaQueuedExportAsCsv\Tests\Feature; | ||
|
||
use Illuminate\Foundation\Auth\User; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Storage; | ||
use NovaKit\NovaQueuedExportAsCsv\Events\QueuedCsvExported; | ||
use NovaKit\NovaQueuedExportAsCsv\Jobs\QueuedExportAsCsv as QueuedExportAsCsvJob; | ||
use NovaKit\NovaQueuedExportAsCsv\Tests\TestCase; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
use function Laravie\SerializesQuery\serialize; | ||
|
||
class QueuedExportAsCsvJobTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_generate_export_file_from_job() | ||
{ | ||
Event::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
UserFactory::new()->times(10)->create(); | ||
|
||
$query = serialize(User::query()); | ||
$options = [ | ||
'storageDisk' => 'local', | ||
'filename' => 'users.csv', | ||
]; | ||
|
||
dispatch(new QueuedExportAsCsvJob($query, $user->id, null, $options)); | ||
|
||
Event::assertDispatched(function (QueuedCsvExported $event) use ($user) { | ||
return $event->user->id === $user->id | ||
&& $event->filename === 'nova-actions-export-as-csv/users.csv' | ||
&& $event->storageDisk === 'local'; | ||
}); | ||
|
||
$this->assertTrue(Storage::disk('local')->exists('nova-actions-export-as-csv/users.csv')); | ||
} | ||
} | ||
it('can generate export file from job', function () { | ||
Event::fake(); | ||
|
||
$user = UserFactory::new()->create(); | ||
UserFactory::new()->times(10)->create(); | ||
|
||
$query = serialize(User::query()); | ||
$options = [ | ||
'storageDisk' => 'local', | ||
'filename' => 'users.csv', | ||
]; | ||
|
||
dispatch(new QueuedExportAsCsvJob($query, $user->id, null, $options)); | ||
|
||
Event::assertDispatched(function (QueuedCsvExported $event) use ($user) { | ||
return $event->user->id === $user->id | ||
&& $event->filename === 'nova-actions-export-as-csv/users.csv' | ||
&& $event->storageDisk === 'local'; | ||
}); | ||
|
||
$this->assertTrue(Storage::disk('local')->exists('nova-actions-export-as-csv/users.csv')); | ||
}); |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
expect()->extend('toBeOne', function () { | ||
return $this->toBe(1); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
function something() | ||
{ | ||
// .. | ||
} |
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 |
---|---|---|
@@ -1,30 +1,14 @@ | ||
<?php | ||
|
||
namespace NovaKit\NovaQueuedExportAsCsv\Tests; | ||
namespace Tests; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Http; | ||
use Orchestra\Testbench\Attributes\WithMigration; | ||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase; | ||
use Laravel\Nova\Testing\Concerns\InteractsWithNova; | ||
use Orchestra\Testbench\Concerns\WithWorkbench; | ||
|
||
#[WithMigration] | ||
class TestCase extends \Orchestra\Testbench\TestCase | ||
abstract class TestCase extends \Orchestra\Testbench\TestCase | ||
{ | ||
use RefreshDatabase; | ||
use InteractsWithNova; | ||
use LazilyRefreshDatabase; | ||
use WithWorkbench; | ||
|
||
/** | ||
* Setup the test environment. | ||
*/ | ||
#[\Override] | ||
protected function setUp(): void | ||
{ | ||
$this->afterApplicationCreated(function () { | ||
Http::fake([ | ||
'nova.laravel.com/*' => Http::response([], 200), | ||
]); | ||
}); | ||
|
||
parent::setUp(); | ||
} | ||
} |
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
Oops, something went wrong.