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

update comments

This commit is contained in:
Abrar Ahmad 2022-10-17 11:24:22 +05:00
parent 93efa56f59
commit a67b5b1f88

View file

@ -131,7 +131,6 @@ test('only the synced columns are updated in the central db', function () {
// Those two don't depend on each other, we're just testing having each option on each side
// using tests that combine the two, to avoid having an excessively long and complex test suite
test('sync resource creation works when central model provides attributes and resource model provides default values', function () {
// when central model provides attributes => resoucre model will be created from the attribute values
[$tenant1, $tenant2] = createTenantsAndRunMigrations();
$centralUser = CentralUserProvidingAttributeNames::create([
@ -147,10 +146,10 @@ test('sync resource creation works when central model provides attributes and re
expect(ResourceUserProvidingDefaultValues::all())->toHaveCount(0);
});
// When central model provides the list of attributes, resource model will be created from the provided list of attributes' values
$centralUser->tenants()->attach('t1');
$tenant1->run(function () {
// assert resource model created with provided attributes
$resourceUser = ResourceUserProvidingDefaultValues::all();
expect($resourceUser)->toHaveCount(1);
expect($resourceUser->first()->global_id)->toBe('acme');
@ -159,10 +158,9 @@ test('sync resource creation works when central model provides attributes and re
expect($resourceUser->first()->foo)->toBeNull();
});
// when resource model provides default values => central model will be created using the default values
tenancy()->initialize($tenant2);
// Create the user in tenant DB
// When resource model provides the list of default values, central model will be created from the provided list of default values
ResourceUserProvidingDefaultValues::create([
'global_id' => 'asdf',
'name' => 'John Doe',
@ -173,7 +171,7 @@ test('sync resource creation works when central model provides attributes and re
tenancy()->end();
// Assert central user was created using the default values
// Assert central user was created using the list of default values
$centralUser = CentralUserProvidingAttributeNames::whereGlobalId('asdf')->first();
expect($centralUser)->not()->toBeNull();
expect($centralUser->name)->toBe('Default Name');
@ -187,7 +185,6 @@ test('sync resource creation works when central model provides attributes and re
// Those two don't depend on each other, we're just testing having each option on each side
// using tests that combine the two, to avoid having an excessively long and complex test suite
test('sync resource creation works when central model provides default values and resource model provides attributes', function () {
// when central model provides default values => resource model will be created using the default values
[$tenant1, $tenant2] = createTenantsAndRunMigrations();
$centralUser = CentralUserProvidingDefaultValues::create([
@ -203,10 +200,11 @@ test('sync resource creation works when central model provides default values an
expect(ResourceUserProvidingDefaultValues::all())->toHaveCount(0);
});
// When central model provides the list of default values, resource model will be created from the provided list of default values
$centralUser->tenants()->attach('t1');
$tenant1->run(function () {
// assert resource model created with provided default values
// Assert resource user was created using the list of default values
$resourceUser = ResourceUserProvidingDefaultValues::first();
expect($resourceUser)->not()->toBeNull();
expect($resourceUser->global_id)->toBe('acme');
@ -215,10 +213,9 @@ test('sync resource creation works when central model provides default values an
expect($resourceUser->role)->toBe('admin');
});
// when resource model provides attributes => central model will be created from the attribute values
tenancy()->initialize($tenant2);
// Create the user in tenant DB
// When resource model provides the list of attributes, central model will be created from the provided list of attributes' values
ResourceUserProvidingAttributeNames::create([
'global_id' => 'asdf',
'name' => 'John Doe',
@ -229,7 +226,7 @@ test('sync resource creation works when central model provides default values an
tenancy()->end();
// Assert central user was created using the provided attributes
// Assert central user was created using the list of provided attributes
$centralUser = CentralUserProvidingAttributeNames::whereGlobalId('asdf')->first();
expect($centralUser)->not()->toBeNull();
expect($centralUser->email)->toBe('john@localhost');
@ -242,7 +239,6 @@ test('sync resource creation works when central model provides default values an
// Those two don't depend on each other, we're just testing having each option on each side
// using tests that combine the two, to avoid having an excessively long and complex test suite
test('sync resource creation works when central model provides mixture and resource model provides nothing using different schemas', function () {
// when central model provides mix of attribute and default values => resource model will be created using the mix of attribute values and default values
[$tenant1, $tenant2] = createTenantsAndRunMigrationsForDifferentSchema();
$centralUser = CentralUserProvidingMixture::create([
@ -256,6 +252,7 @@ test('sync resource creation works when central model provides mixture and resou
expect(ResourceUserForDifferentSchema::all())->toHaveCount(0);
});
// When central model provides the list of a mixture (attributes and default values), resource model will be created from the provided list of mixture (attributes and default values)
$centralUser->tenants()->attach('t1');
$tenant1->run(function () {
@ -265,15 +262,12 @@ test('sync resource creation works when central model provides mixture and resou
expect($resourceUser->global_id)->toBe('acme');
expect($resourceUser->name)->toBe('John Doe');
expect($resourceUser->email)->toBe('john@localhost');
// provided default values
expect($resourceUser->password)->toBe('secret');
expect($resourceUser->password)->toBe('secret'); // default value
});
// when central model provides nothing => resoucre model will be 1:1 copy
tenancy()->initialize($tenant2);
// Create the user in tenant DB
// When resource model provides nothing/null, the central model will be created as a 1:1 copy of resource model
$resourceUser = ResourceUserForDifferentSchema::create([
'global_id' => 'acmey',
'name' => 'John Doe',
@ -291,7 +285,7 @@ test('sync resource creation works when central model provides mixture and resou
unset($centralUser['id']);
unset($resourceUser['id']);
// assert central user created as 1:1 copy of resoucre model except "id"
// Assert central user created as 1:1 copy of resource model except "id"
expect($centralUser)->toBe($resourceUser);
});
@ -299,7 +293,6 @@ test('sync resource creation works when central model provides mixture and resou
// Those two don't depend on each other, we're just testing having each option on each side
// using tests that combine the two, to avoid having an excessively long and complex test suite
test('sync resource creation works when central model provides nothing and resource model provides mixture using different schemas', function () {
// when central model provides nothing => resoucre model will be 1:1 copy
[$tenant1, $tenant2] = createTenantsAndRunMigrationsForDifferentSchema();
$centralUser = CentralUserForDifferentSchema::create([
@ -313,6 +306,7 @@ test('sync resource creation works when central model provides nothing and resou
expect(ResourceUserProvidingMixture::all())->toHaveCount(0);
});
// When central model provides nothing/null, the resource model will be created as a 1:1 copy of central model
$centralUser->tenants()->attach('t1');
expect($centralUser->getSyncedCreationAttributes())->toBeNull();
@ -327,10 +321,9 @@ test('sync resource creation works when central model provides nothing and resou
expect($resourceUser)->toBe($centralUser);
});
// when resource model provides mix of attribute and default values => central model will be created using the mix of attribute values and default values
tenancy()->initialize($tenant2);
// Create the user in tenant DB
// When resource model provides the list of a mixture (attributes and default values), central model will be created from the provided list of mixture (attributes and default values)
ResourceUserProvidingMixture::create([
'global_id' => 'absd',
'name' => 'John Doe',
@ -342,12 +335,10 @@ test('sync resource creation works when central model provides nothing and resou
$centralUser = CentralUserForDifferentSchema::whereGlobalId('absd')->first();
// Assert central user was created using the provided attributes and default values
// Assert central user was created using the provided list of attributes and default values
expect($centralUser->name)->toBe('John Doe');
expect($centralUser->email)->toBe('john@localhost');
// Provided default values
expect($centralUser->password)->toBe('secret');
expect($centralUser->password)->toBe('secret'); // default value
});
test('creating the resource in tenant database creates it in central database and creates the mapping', function () {