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

improve test

This commit is contained in:
Samuel Štancl 2022-08-30 15:30:27 +02:00 committed by GitHub
parent e219bf8943
commit c6a565295c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Stancl\Tenancy\Tests\Etc\User;
beforeEach(function () { beforeEach(function () {
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
@ -179,7 +180,7 @@ test('run command with array of tenants works', function () {
->expectsOutput('Tenant: ' . $tenantId2); ->expectsOutput('Tenant: ' . $tenantId2);
}); });
test('run command works when sub command asks question and accepts argument', closure: function () { test('run command works when sub command asks question and accepts argument', function () {
$tenant = Tenant::create(); $tenant = Tenant::create();
$id = $tenant->getTenantKey(); $id = $tenant->getTenantKey();
@ -191,13 +192,16 @@ test('run command works when sub command asks question and accepts argument', cl
->expectsOutput("Tenant: $id") ->expectsOutput("Tenant: $id")
->expectsOutput("User created: Abrar(email@localhost)"); ->expectsOutput("User created: Abrar(email@localhost)");
// Assert we are in central context
expect(tenancy()->initialized)->toBeFalse();
// Assert users table does not exist in the central context // Assert users table does not exist in the central context
expect(Schema::hasTable('users'))->toBeFalse(); expect(Schema::hasTable('users'))->toBeFalse();
// Assert user created in tenant context // Assert user created in tenant context
tenancy()->initialize($tenant); tenancy()->initialize($tenant);
expect(Schema::hasTable('users'))->toBeTrue(); expect(Schema::hasTable('users'))->toBeTrue();
$user = \Stancl\Tenancy\Tests\Etc\User::first(); $user = User::first();
// Assert user is same as provided using command // Assert user is same as provided using command
expect($user->name)->toBe('Abrar'); expect($user->name)->toBe('Abrar');