refactor(integration): enhance association logic to delete unused instances and improve transaction handling
This commit is contained in:
@@ -126,6 +126,36 @@ class IntegrationInstanceTest extends TestCase
|
||||
self::assertSame('changed', $this->probe()->forClient($b)->setting());
|
||||
}
|
||||
|
||||
public function test_reconfiguring_deletes_the_previous_instance_when_it_is_no_longer_used(): void
|
||||
{
|
||||
$client = Client::create(['code' => 'acme', 'name' => 'Acme']);
|
||||
$associations = new IntegrationAssociationService;
|
||||
$previous = $this->makeInstance('previous');
|
||||
|
||||
$associations->associate($client, 'test', $previous);
|
||||
$current = $associations->configure($client, $this->integration, ['api_key' => 'current']);
|
||||
|
||||
$this->assertDatabaseMissing('integration_instances', ['id' => $previous->id]);
|
||||
$this->assertDatabaseHas('integration_instances', ['id' => $current->integration_instance_id]);
|
||||
}
|
||||
|
||||
public function test_an_instance_is_deleted_only_after_its_last_association_is_removed(): void
|
||||
{
|
||||
$client = Client::create(['code' => 'acme', 'name' => 'Acme']);
|
||||
$type = WebsiteType::create(['codigo' => 'demo', 'nombre' => 'Demo']);
|
||||
$shared = $this->makeInstance('shared');
|
||||
$associations = new IntegrationAssociationService;
|
||||
|
||||
$associations->associate($client, 'test', $shared);
|
||||
$associations->associate($type, 'test', $shared);
|
||||
|
||||
$associations->detach($client, 'test');
|
||||
$this->assertDatabaseHas('integration_instances', ['id' => $shared->id]);
|
||||
|
||||
$associations->detach($type, 'test');
|
||||
$this->assertDatabaseMissing('integration_instances', ['id' => $shared->id]);
|
||||
}
|
||||
|
||||
public function test_telepagos_shares_tokens_by_instance_and_refreshes_after_credential_changes(): void
|
||||
{
|
||||
Integration::create(['integration_code' => 'telepagos_homo', 'name' => 'Telepagos', 'url' => 'https://payments.test']);
|
||||
|
||||
Reference in New Issue
Block a user