|
@@ -32,7 +32,7 @@ class TestableShopService extends ShopService
|
|
|
{
|
|
{
|
|
|
public PhoneNumberUtil $phoneNumberUtil;
|
|
public PhoneNumberUtil $phoneNumberUtil;
|
|
|
|
|
|
|
|
- public function controlShopRequestData(ShopRequestType $type, NewStructureArtistPremiumTrialRequest|array $data): void
|
|
|
|
|
|
|
+ public function controlShopRequestData(ShopRequestType $type, array $data): void
|
|
|
{
|
|
{
|
|
|
parent::controlShopRequestData($type, $data);
|
|
parent::controlShopRequestData($type, $data);
|
|
|
}
|
|
}
|
|
@@ -62,16 +62,25 @@ class TestableShopService extends ShopService
|
|
|
return parent::generateSubdomain($name);
|
|
return parent::generateSubdomain($name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function validateNewStructureArtistPremiumTrialRequest($request): void
|
|
|
|
|
|
|
+ public function validateNewStructureArtistPremiumTrialRequest(array $data): void
|
|
|
{
|
|
{
|
|
|
- parent::validateNewStructureArtistPremiumTrialRequest($request);
|
|
|
|
|
|
|
+ parent::validateNewStructureArtistPremiumTrialRequest($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function createOrganizationCreationRequestFromTrialRequest(
|
|
public function createOrganizationCreationRequestFromTrialRequest(
|
|
|
NewStructureArtistPremiumTrialRequest $trialRequest,
|
|
NewStructureArtistPremiumTrialRequest $trialRequest,
|
|
|
- bool $forValidationOnly = false,
|
|
|
|
|
): OrganizationCreationRequest {
|
|
): OrganizationCreationRequest {
|
|
|
- return parent::createOrganizationCreationRequestFromTrialRequest($trialRequest, $forValidationOnly);
|
|
|
|
|
|
|
+ return parent::createOrganizationCreationRequestFromTrialRequest($trialRequest);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function sendMailToSalesAdministration(NewStructureArtistPremiumTrialRequest $trialRequest): void
|
|
|
|
|
+ {
|
|
|
|
|
+ parent::sendMailToSalesAdministration($trialRequest);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function sendConfirmationMailToRepresentative(NewStructureArtistPremiumTrialRequest $trialRequest): void
|
|
|
|
|
+ {
|
|
|
|
|
+ parent::sendConfirmationMailToRepresentative($trialRequest);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -83,22 +92,28 @@ class ShopServiceTest extends TestCase
|
|
|
private readonly MockObject|EntityManagerInterface $entityManager;
|
|
private readonly MockObject|EntityManagerInterface $entityManager;
|
|
|
private readonly MockObject|Mailer $mailer;
|
|
private readonly MockObject|Mailer $mailer;
|
|
|
private string $publicBaseUrl;
|
|
private string $publicBaseUrl;
|
|
|
|
|
+ private string $adminBaseUrl;
|
|
|
private readonly MockObject|OrganizationFactory $organizationFactory;
|
|
private readonly MockObject|OrganizationFactory $organizationFactory;
|
|
|
private readonly MockObject|SerializerInterface $serializer;
|
|
private readonly MockObject|SerializerInterface $serializer;
|
|
|
private readonly MockObject|LoggerInterface $logger;
|
|
private readonly MockObject|LoggerInterface $logger;
|
|
|
private readonly MockObject|MessageBusInterface $messageBus;
|
|
private readonly MockObject|MessageBusInterface $messageBus;
|
|
|
private readonly MockObject|Trial $trial;
|
|
private readonly MockObject|Trial $trial;
|
|
|
|
|
+ private string $faqUrl;
|
|
|
|
|
+ private string $softwareWebsiteUrl;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
public function setUp(): void
|
|
|
{
|
|
{
|
|
|
$this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
|
|
$this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
|
|
$this->mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->publicBaseUrl = 'https://example.com';
|
|
$this->publicBaseUrl = 'https://example.com';
|
|
|
|
|
+ $this->adminBaseUrl = 'https://admin.example.com';
|
|
|
$this->organizationFactory = $this->getMockBuilder(OrganizationFactory::class)->disableOriginalConstructor()->getMock();
|
|
$this->organizationFactory = $this->getMockBuilder(OrganizationFactory::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->serializer = $this->getMockBuilder(SerializerInterface::class)->disableOriginalConstructor()->getMock();
|
|
$this->serializer = $this->getMockBuilder(SerializerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
|
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
|
|
$this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->trial = $this->getMockBuilder(Trial::class)->disableOriginalConstructor()->getMock();
|
|
$this->trial = $this->getMockBuilder(Trial::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->faqUrl = 'https://faq.example.com';
|
|
|
|
|
+ $this->softwareWebsiteUrl = 'https://software.example.com';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function getShopServiceMockFor(string $methodName): TestableShopService|MockObject
|
|
private function getShopServiceMockFor(string $methodName): TestableShopService|MockObject
|
|
@@ -110,11 +125,14 @@ class ShopServiceTest extends TestCase
|
|
|
$this->entityManager,
|
|
$this->entityManager,
|
|
|
$this->mailer,
|
|
$this->mailer,
|
|
|
$this->publicBaseUrl,
|
|
$this->publicBaseUrl,
|
|
|
|
|
+ $this->adminBaseUrl,
|
|
|
$this->organizationFactory,
|
|
$this->organizationFactory,
|
|
|
$this->serializer,
|
|
$this->serializer,
|
|
|
$this->logger,
|
|
$this->logger,
|
|
|
$this->messageBus,
|
|
$this->messageBus,
|
|
|
$this->trial,
|
|
$this->trial,
|
|
|
|
|
+ $this->faqUrl,
|
|
|
|
|
+ $this->softwareWebsiteUrl,
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
->setMethodsExcept([$methodName])
|
|
->setMethodsExcept([$methodName])
|
|
@@ -280,14 +298,12 @@ class ShopServiceTest extends TestCase
|
|
|
->expects(self::once())
|
|
->expects(self::once())
|
|
|
->method('main')
|
|
->method('main')
|
|
|
->with(self::callback(function ($model) use ($token, $data) {
|
|
->with(self::callback(function ($model) use ($token, $data) {
|
|
|
- var_dump($model);
|
|
|
|
|
-
|
|
|
|
|
return $model->getToken() === $token
|
|
return $model->getToken() === $token
|
|
|
&& $model->getRepresentativeEmail() === $data['representativeEmail']
|
|
&& $model->getRepresentativeEmail() === $data['representativeEmail']
|
|
|
&& $model->getRepresentativeFirstName() === $data['representativeFirstName']
|
|
&& $model->getRepresentativeFirstName() === $data['representativeFirstName']
|
|
|
&& $model->getRepresentativeLastName() === $data['representativeLastName']
|
|
&& $model->getRepresentativeLastName() === $data['representativeLastName']
|
|
|
&& $model->getStructureName() === $data['structureName']
|
|
&& $model->getStructureName() === $data['structureName']
|
|
|
- && $model->getValidationUrl() === 'https://example.com/api/public/shop/validate/'.$token;
|
|
|
|
|
|
|
+ && $model->getValidationUrl() === 'https://software.example.com/shop/try/validation?token='.$token;
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
$shopRequest->expects(self::once())
|
|
$shopRequest->expects(self::once())
|
|
@@ -359,6 +375,15 @@ class ShopServiceTest extends TestCase
|
|
|
->method('startArtistPremiumTrialForNewStructure')
|
|
->method('startArtistPremiumTrialForNewStructure')
|
|
|
->with($organization, $trialRequest);
|
|
->with($organization, $trialRequest);
|
|
|
|
|
|
|
|
|
|
+ // Mock the sendMailToSalesAdministration and sendConfirmationMailToRepresentative methods
|
|
|
|
|
+ $shopService->expects(self::once())
|
|
|
|
|
+ ->method('sendMailToSalesAdministration')
|
|
|
|
|
+ ->with($trialRequest);
|
|
|
|
|
+
|
|
|
|
|
+ $shopService->expects(self::once())
|
|
|
|
|
+ ->method('sendConfirmationMailToRepresentative')
|
|
|
|
|
+ ->with($trialRequest);
|
|
|
|
|
+
|
|
|
$this->logger->expects(self::once())
|
|
$this->logger->expects(self::once())
|
|
|
->method('info')
|
|
->method('info')
|
|
|
->with('Successfully processed NewStructureArtistPremiumTrial for token: '.$token);
|
|
->with('Successfully processed NewStructureArtistPremiumTrial for token: '.$token);
|
|
@@ -512,7 +537,16 @@ class ShopServiceTest extends TestCase
|
|
|
->method('interruptIfOrganizationExists')
|
|
->method('interruptIfOrganizationExists')
|
|
|
->with($organizationCreationRequest);
|
|
->with($organizationCreationRequest);
|
|
|
|
|
|
|
|
- $shopService->validateNewStructureArtistPremiumTrialRequest($trialRequest);
|
|
|
|
|
|
|
+ // Convert the trial request to an array for validation
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'representativePhone' => '+33123456789',
|
|
|
|
|
+ ];
|
|
|
|
|
+ $this->serializer->expects(self::once())
|
|
|
|
|
+ ->method('deserialize')
|
|
|
|
|
+ ->with(json_encode($data), NewStructureArtistPremiumTrialRequest::class, 'json')
|
|
|
|
|
+ ->willReturn($trialRequest);
|
|
|
|
|
+
|
|
|
|
|
+ $shopService->validateNewStructureArtistPremiumTrialRequest($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -538,10 +572,19 @@ class ShopServiceTest extends TestCase
|
|
|
->with('invalid-phone')
|
|
->with('invalid-phone')
|
|
|
->willReturn(false);
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
|
|
+ // Convert the trial request to an array for validation
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'representativePhone' => 'invalid-phone',
|
|
|
|
|
+ ];
|
|
|
|
|
+ $this->serializer->expects(self::once())
|
|
|
|
|
+ ->method('deserialize')
|
|
|
|
|
+ ->with(json_encode($data), NewStructureArtistPremiumTrialRequest::class, 'json')
|
|
|
|
|
+ ->willReturn($trialRequest);
|
|
|
|
|
+
|
|
|
$this->expectException(\RuntimeException::class);
|
|
$this->expectException(\RuntimeException::class);
|
|
|
$this->expectExceptionMessage('Invalid phone number');
|
|
$this->expectExceptionMessage('Invalid phone number');
|
|
|
|
|
|
|
|
- $shopService->validateNewStructureArtistPremiumTrialRequest($trialRequest);
|
|
|
|
|
|
|
+ $shopService->validateNewStructureArtistPremiumTrialRequest($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -569,7 +612,7 @@ class ShopServiceTest extends TestCase
|
|
|
$fakeDate = '2023-05-15 10:30:00';
|
|
$fakeDate = '2023-05-15 10:30:00';
|
|
|
DatesUtils::setFakeDatetime($fakeDate);
|
|
DatesUtils::setFakeDatetime($fakeDate);
|
|
|
|
|
|
|
|
- // Test with forValidationOnly = false (default)
|
|
|
|
|
|
|
+ // Create the organization creation request
|
|
|
$result = $shopService->createOrganizationCreationRequestFromTrialRequest($trialRequest);
|
|
$result = $shopService->createOrganizationCreationRequestFromTrialRequest($trialRequest);
|
|
|
|
|
|
|
|
// Verify that all fields are set
|
|
// Verify that all fields are set
|
|
@@ -589,4 +632,53 @@ class ShopServiceTest extends TestCase
|
|
|
$this->assertFalse($result->isClient());
|
|
$this->assertFalse($result->isClient());
|
|
|
$this->assertEquals(new \DateTime($fakeDate), $result->getCreationDate());
|
|
$this->assertEquals(new \DateTime($fakeDate), $result->getCreationDate());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Test sendMailToSalesAdministration method.
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testSendMailToSalesAdministration(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $shopService = $this->getShopServiceMockFor('sendMailToSalesAdministration');
|
|
|
|
|
+
|
|
|
|
|
+ $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
|
|
|
|
|
+ ->getMock();
|
|
|
|
|
+
|
|
|
|
|
+ $this->mailer
|
|
|
|
|
+ ->expects(self::once())
|
|
|
|
|
+ ->method('main')
|
|
|
|
|
+ ->with(self::callback(function ($model) use ($trialRequest) {
|
|
|
|
|
+ return $model instanceof \App\Service\Mailer\Model\Shop\NewStructureArtistPremium\NotificationToSalesAdminModel
|
|
|
|
|
+ && $model->getTrialRequest() === $trialRequest
|
|
|
|
|
+ && $model->getSenderId() === \App\Enum\Access\AccessIdsEnum::ADMIN_2IOPENSERVICE->value;
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ $shopService->sendMailToSalesAdministration($trialRequest);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Test sendConfirmationMailToRepresentative method.
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testSendConfirmationMailToRepresentative(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $shopService = $this->getShopServiceMockFor('sendConfirmationMailToRepresentative');
|
|
|
|
|
+
|
|
|
|
|
+ $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
|
|
|
|
|
+ ->getMock();
|
|
|
|
|
+ $trialRequest->method('getStructureIdentifier')->willReturn('test-structure');
|
|
|
|
|
+
|
|
|
|
|
+ $this->mailer
|
|
|
|
|
+ ->expects(self::once())
|
|
|
|
|
+ ->method('main')
|
|
|
|
|
+ ->with(self::callback(function ($model) use ($trialRequest) {
|
|
|
|
|
+ return $model instanceof \App\Service\Mailer\Model\Shop\NewStructureArtistPremium\ConfirmationToRepresentativeModel
|
|
|
|
|
+ && $model->getTrialRequest() === $trialRequest
|
|
|
|
|
+ && $model->getSenderId() === \App\Enum\Access\AccessIdsEnum::ADMIN_2IOPENSERVICE->value
|
|
|
|
|
+ && $model->getAccountCreationUrl() === 'https://example.com/account/create'
|
|
|
|
|
+ && $model->getFaqUrl() === 'https://faq.example.com'
|
|
|
|
|
+ && $model->getAdminUsername() === 'admintest-structure'
|
|
|
|
|
+ && $model->getAdminLoginUrl() === 'https://admin.example.com/#/login/';
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ $shopService->sendConfirmationMailToRepresentative($trialRequest);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|