1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00

Test that the context is central after jobs get processed

This commit is contained in:
lukinovec 2023-06-22 10:28:47 +02:00
parent bd9bbe8b41
commit d5d2c2475e

View file

@ -86,7 +86,7 @@ test('tenant id is not passed to central queues', function () {
});
});
test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) {
test('tenancy is initialized inside queues', function () {
withTenantDatabases();
withFailedJobs();
@ -104,12 +104,11 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) {
expect(pest()->valuestore->has('tenant_id'))->toBeFalse();
if ($shouldEndTenancy) {
tenancy()->end();
}
pest()->artisan('queue:work --once');
// Tenancy should not be initialized after the jobs get processed
expect(tenancy()->initialized)->toBeFalse();
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0);
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id);
@ -117,9 +116,9 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) {
$tenant->run(function () use ($user) {
expect($user->fresh()->name)->toBe('Bar');
});
})->with([true, false]);;
});
test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenancy) {
test('tenancy is initialized when retrying jobs', function () {
withFailedJobs();
withTenantDatabases();
@ -138,18 +137,18 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan
expect(pest()->valuestore->has('tenant_id'))->toBeFalse();
if ($shouldEndTenancy) {
tenancy()->end();
}
pest()->artisan('queue:work --once');
expect(tenancy()->initialized)->toBeFalse();
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(1);
expect(pest()->valuestore->get('tenant_id'))->toBeNull(); // job failed
pest()->artisan('queue:retry all');
pest()->artisan('queue:work --once');
expect(tenancy()->initialized)->toBeFalse();
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0);
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id); // job succeeded
@ -157,7 +156,7 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan
$tenant->run(function () use ($user) {
expect($user->fresh()->name)->toBe('Bar');
});
})->with([true, false]);
});
test('the tenant used by the job doesnt change when the current tenant changes', function () {
withTenantDatabases();