From fea50de023c02565d50ae64b5dcb4dcbf6c930b6 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:57:34 +0100 Subject: [PATCH 1/5] add refactored test_get_drafts_by_type_and_between_months_old --- .../EloquentIntegrationRepositoryTest.php | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php index 1655e74bc..f60600609 100644 --- a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php +++ b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php @@ -765,6 +765,67 @@ public function test_get_drafts_by_type_and_between_months_old( ); } + public function test_get_drafts_by_type_and_between_months_old_refactor(): void + { + $integrations = $this->dataProviderForGetDraftsByTypeAndBetweenMonthsOldRefactor(); + + foreach ($integrations as $integrationName => $integration) { + $integrationId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $integrationId, + 'type' => $integration['type'], + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => $integrationName, + 'description' => 'test', + 'status' => $integration['status'], + 'created_at' => $integration['created_at'], + ]); + + if ($integration['mail_already_sent']) { + DB::table('integrations_mails')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $integrationId, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER->value, + ]); + } + + if ($integration['has_contact']) { + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $integrationId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + } + + if ($integration['on_hold']) { + DB::table('admin_information')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $integrationId, + 'on_hold' => true, + 'comment' => 'Integration is on hold', + ]); + } + } + + $actual = $this->integrationRepository->getDraftsByTypeAndBetweenMonthsOld( + IntegrationType::SearchApi, + 12, + 24, + TemplateName::INTEGRATION_ACTIVATION_REMINDER, + ); + + $this->assertEquals( + [ + 0 => 'Should also be selected!', + 1 => 'Should be selected!', + ], + $actual->map(fn ($item) => $item->name)->toArray() + ); + } + public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOld(): array { return [ @@ -861,6 +922,112 @@ public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOld(): arra ]; } + public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOldRefactor(): array + { + return [ + 'Should not be selected: wrong type' => [ + 'type' => IntegrationType::EntryApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: already active' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Active, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: No contacts' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => null, + 'has_contact' => false, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: Created too recently' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(11), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: Mail already sent' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => Carbon::now(), + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: Too old' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(50), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should not be selected: has an admin hold state' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => true, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 0, + ], + 'Should be selected!' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 1, + ], + 'Should also be selected!' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(15), + 'mail_already_sent' => null, + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, + 'expectedCount' => 1, + ], + 'A different type of email has been sent, should be selected' => [ + 'type' => IntegrationType::SearchApi, + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + 'mail_already_sent' => Carbon::now(), + 'has_contact' => true, + 'on_hold' => false, + 'template_name' => TemplateName::INTEGRATION_CREATED, + 'expectedCount' => 1, + ], + ]; + } + private function givenThereIsASubscription( ?UuidInterface $id = null, ?string $name = null, From 1313d34a29a8e380bb649e36edfa277b3a0ac70c Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:03:05 +0100 Subject: [PATCH 2/5] Remove old logic --- .../EloquentIntegrationRepositoryTest.php | 168 +----------------- 1 file changed, 5 insertions(+), 163 deletions(-) diff --git a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php index f60600609..81d88d77a 100644 --- a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php +++ b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php @@ -31,7 +31,6 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; -use PHPUnit\Framework\Attributes\DataProvider; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; use Tests\TestCase; @@ -704,70 +703,9 @@ public function test_it_can_not_save_integration_with_subscription_with_differen ); } - #[DataProvider('dataProviderForGetDraftsByTypeAndBetweenMonthsOld')] - public function test_get_drafts_by_type_and_between_months_old( - IntegrationType $integrationType, - IntegrationStatus $status, - Carbon $date, - ?Carbon $mailAlreadySent, - bool $hasContact, - bool $onHold, - TemplateName $templateName, - int $expectedCount, - ): void { - $integrationId = Uuid::uuid4()->toString(); - DB::table('integrations')->insert([ - 'id' => $integrationId, - 'type' => $integrationType->value, - 'subscription_id' => Uuid::uuid4()->toString(), - 'name' => 'Test', - 'description' => 'test', - 'status' => $status, - 'created_at' => $date, - ]); - - if ($mailAlreadySent) { - DB::table('integrations_mails')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER->value, - ]); - } - - if ($hasContact) { - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); - } - - if ($onHold) { - DB::table('admin_information')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'on_hold' => true, - 'comment' => 'Integration is on hold', - ]); - } - - $this->assertCount( - $expectedCount, - $this->integrationRepository->getDraftsByTypeAndBetweenMonthsOld( - IntegrationType::SearchApi, - 12, - 24, - $templateName, - ) - ); - } - - public function test_get_drafts_by_type_and_between_months_old_refactor(): void + public function test_get_drafts_by_type_and_between_months_old(): void { - $integrations = $this->dataProviderForGetDraftsByTypeAndBetweenMonthsOldRefactor(); + $integrations = $this->dataProviderForGetDraftsByTypeAndBetweenMonthsOld(); foreach ($integrations as $integrationName => $integration) { $integrationId = Uuid::uuid4()->toString(); @@ -817,112 +755,16 @@ public function test_get_drafts_by_type_and_between_months_old_refactor(): void TemplateName::INTEGRATION_ACTIVATION_REMINDER, ); - $this->assertEquals( + $this->assertEqualsCanonicalizing( [ - 0 => 'Should also be selected!', - 1 => 'Should be selected!', + 'Should be selected!', + 'Should also be selected!', ], $actual->map(fn ($item) => $item->name)->toArray() ); } public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOld(): array - { - return [ - 'Should not be selected: wrong type' => [ - IntegrationType::EntryApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - null, - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: already active' => [ - IntegrationType::SearchApi, - IntegrationStatus::Active, - Carbon::now()->subMonths(14), - null, - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: No contacts' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - null, - false, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: Created too recently' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(11), - null, - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: Mail already sent' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - Carbon::now(), - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: Too old' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(50), - null, - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should not be selected: has an admin hold state' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - null, - true, - true, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 0, - ], - 'Should be selected!' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - null, - true, - false, - TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 1, - ], - 'A different type of email has been sent, should be selected' => [ - IntegrationType::SearchApi, - IntegrationStatus::Draft, - Carbon::now()->subMonths(14), - Carbon::now(), - true, - false, - TemplateName::INTEGRATION_CREATED, - 1, - ], - ]; - } - - public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOldRefactor(): array { return [ 'Should not be selected: wrong type' => [ From d5dd6c7a4b2bc68f0c0930c05d618afb2e23d1b6 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:01:24 +0100 Subject: [PATCH 3/5] refactor Database Setup --- .../EloquentIntegrationRepositoryTest.php | 345 ++++++++++-------- 1 file changed, 200 insertions(+), 145 deletions(-) diff --git a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php index 81d88d77a..2bfd56962 100644 --- a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php +++ b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php @@ -705,48 +705,7 @@ public function test_it_can_not_save_integration_with_subscription_with_differen public function test_get_drafts_by_type_and_between_months_old(): void { - $integrations = $this->dataProviderForGetDraftsByTypeAndBetweenMonthsOld(); - - foreach ($integrations as $integrationName => $integration) { - $integrationId = Uuid::uuid4()->toString(); - DB::table('integrations')->insert([ - 'id' => $integrationId, - 'type' => $integration['type'], - 'subscription_id' => Uuid::uuid4()->toString(), - 'name' => $integrationName, - 'description' => 'test', - 'status' => $integration['status'], - 'created_at' => $integration['created_at'], - ]); - - if ($integration['mail_already_sent']) { - DB::table('integrations_mails')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER->value, - ]); - } - - if ($integration['has_contact']) { - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); - } - - if ($integration['on_hold']) { - DB::table('admin_information')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $integrationId, - 'on_hold' => true, - 'comment' => 'Integration is on hold', - ]); - } - } + $this->setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(); $actual = $this->integrationRepository->getDraftsByTypeAndBetweenMonthsOld( IntegrationType::SearchApi, @@ -757,6 +716,7 @@ public function test_get_drafts_by_type_and_between_months_old(): void $this->assertEqualsCanonicalizing( [ + 'A different type of email has been sent, should be selected', 'Should be selected!', 'Should also be selected!', ], @@ -764,110 +724,205 @@ public function test_get_drafts_by_type_and_between_months_old(): void ); } - public static function dataProviderForGetDraftsByTypeAndBetweenMonthsOld(): array + public static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): void { - return [ - 'Should not be selected: wrong type' => [ - 'type' => IntegrationType::EntryApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: already active' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Active, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: No contacts' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => null, - 'has_contact' => false, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: Created too recently' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(11), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: Mail already sent' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => Carbon::now(), - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: Too old' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(50), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should not be selected: has an admin hold state' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => true, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 0, - ], - 'Should be selected!' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 1, - ], - 'Should also be selected!' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(15), - 'mail_already_sent' => null, - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER, - 'expectedCount' => 1, - ], - 'A different type of email has been sent, should be selected' => [ - 'type' => IntegrationType::SearchApi, - 'status' => IntegrationStatus::Draft, - 'created_at' => Carbon::now()->subMonths(14), - 'mail_already_sent' => Carbon::now(), - 'has_contact' => true, - 'on_hold' => false, - 'template_name' => TemplateName::INTEGRATION_CREATED, - 'expectedCount' => 1, - ], - ]; + $wrongTypeId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $wrongTypeId, + 'type' => IntegrationType::EntryApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: wrong type', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $wrongTypeId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $alreadyActiveId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $alreadyActiveId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: already active', + 'description' => 'test', + 'status' => IntegrationStatus::Active, + 'created_at' => Carbon::now()->subMonths(14), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $alreadyActiveId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $noContactsId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $noContactsId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: No contacts', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + ]); + + $createdToRecentlyId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $createdToRecentlyId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: Created too recently', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(11), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $createdToRecentlyId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $mailAlreadySentId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $mailAlreadySentId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: Created too recently', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(11), + ]); + DB::table('integrations_mails')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $mailAlreadySentId, + 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER->value, + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $mailAlreadySentId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $tooOldId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $tooOldId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: Too old', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(50), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $tooOldId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $hasAdminHoldId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $hasAdminHoldId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should not be selected: has an admin hold state', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $hasAdminHoldId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + DB::table('admin_information')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $hasAdminHoldId, + 'on_hold' => true, + 'comment' => 'Integration is on hold', + ]); + + $shouldBeSelectedId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $shouldBeSelectedId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should be selected!', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(14), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $shouldBeSelectedId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $shouldAlsoBeSelectedId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $shouldAlsoBeSelectedId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'Should also be selected!', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(15), + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $shouldAlsoBeSelectedId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); + + $differentTypeOfMailId = Uuid::uuid4()->toString(); + DB::table('integrations')->insert([ + 'id' => $differentTypeOfMailId, + 'type' => IntegrationType::SearchApi, + 'subscription_id' => Uuid::uuid4()->toString(), + 'name' => 'A different type of email has been sent, should be selected', + 'description' => 'test', + 'status' => IntegrationStatus::Draft, + 'created_at' => Carbon::now()->subMonths(15), + ]); + DB::table('integrations_mails')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $differentTypeOfMailId, + 'template_name' => TemplateName::INTEGRATION_CREATED->value, + ]); + DB::table('contacts')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'integration_id' => $differentTypeOfMailId, + 'email' => 'grote.smurf@example.com', + 'type' => ContactType::Technical->value, + 'first_name' => 'Grote', + 'last_name' => 'Smurf', + ]); } private function givenThereIsASubscription( From cd7863a062e3b9a85fe98aa1642808415a2b549a Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:21:08 +0100 Subject: [PATCH 4/5] make function private --- .../Repositories/EloquentIntegrationRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php index 2bfd56962..c3c7336f2 100644 --- a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php +++ b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php @@ -724,7 +724,7 @@ public function test_get_drafts_by_type_and_between_months_old(): void ); } - public static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): void + private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): void { $wrongTypeId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ From 3e8e208c63528183648552c8a584dea8a4727348 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:29:48 +0100 Subject: [PATCH 5/5] use separate function setUpContact() --- .../EloquentIntegrationRepositoryTest.php | 81 ++++--------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php index c3c7336f2..51d63ef36 100644 --- a/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php +++ b/tests/Domain/Integrations/Repositories/EloquentIntegrationRepositoryTest.php @@ -724,7 +724,7 @@ public function test_get_drafts_by_type_and_between_months_old(): void ); } - private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): void + private function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): void { $wrongTypeId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -736,14 +736,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(14), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $wrongTypeId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($wrongTypeId); $alreadyActiveId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -755,14 +748,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Active, 'created_at' => Carbon::now()->subMonths(14), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $alreadyActiveId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($alreadyActiveId); $noContactsId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -785,14 +771,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(11), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $createdToRecentlyId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($createdToRecentlyId); $mailAlreadySentId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -809,14 +788,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'integration_id' => $mailAlreadySentId, 'template_name' => TemplateName::INTEGRATION_ACTIVATION_REMINDER->value, ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $mailAlreadySentId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($mailAlreadySentId); $tooOldId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -828,14 +800,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(50), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $tooOldId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($tooOldId); $hasAdminHoldId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -847,14 +812,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(14), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $hasAdminHoldId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($hasAdminHoldId); DB::table('admin_information')->insert([ 'id' => Uuid::uuid4()->toString(), 'integration_id' => $hasAdminHoldId, @@ -872,14 +830,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(14), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $shouldBeSelectedId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($shouldBeSelectedId); $shouldAlsoBeSelectedId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -891,14 +842,7 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'status' => IntegrationStatus::Draft, 'created_at' => Carbon::now()->subMonths(15), ]); - DB::table('contacts')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $shouldAlsoBeSelectedId, - 'email' => 'grote.smurf@example.com', - 'type' => ContactType::Technical->value, - 'first_name' => 'Grote', - 'last_name' => 'Smurf', - ]); + $this->setUpContact($shouldAlsoBeSelectedId); $differentTypeOfMailId = Uuid::uuid4()->toString(); DB::table('integrations')->insert([ @@ -915,9 +859,14 @@ private static function setUpDatabaseForGetDraftsByTypeAndBetweenMonthsOld(): vo 'integration_id' => $differentTypeOfMailId, 'template_name' => TemplateName::INTEGRATION_CREATED->value, ]); + $this->setUpContact($differentTypeOfMailId); + } + + private function setUpContact(string $integrationId): void + { DB::table('contacts')->insert([ 'id' => Uuid::uuid4()->toString(), - 'integration_id' => $differentTypeOfMailId, + 'integration_id' => $integrationId, 'email' => 'grote.smurf@example.com', 'type' => ContactType::Technical->value, 'first_name' => 'Grote',