ShopServiceTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Unit\Service\Shop;
  4. use App\ApiResources\Organization\OrganizationCreationRequest;
  5. use App\ApiResources\Shop\NewStructureArtistPremiumTrialRequest;
  6. use App\Entity\Organization\Organization;
  7. use App\Entity\Shop\ShopRequest;
  8. use App\Enum\Organization\LegalEnum;
  9. use App\Enum\Organization\PrincipalTypeEnum;
  10. use App\Enum\Organization\SettingsProductEnum;
  11. use App\Enum\Shop\ShopRequestStatus;
  12. use App\Enum\Shop\ShopRequestType;
  13. use App\Message\Message\Shop\NewStructureArtistPremiumTrial;
  14. use App\Service\Mailer\Mailer;
  15. use App\Service\Organization\OrganizationFactory;
  16. use App\Service\Shop\ShopService;
  17. use App\Service\Shop\Trial;
  18. use App\Service\Utils\DatesUtils;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use libphonenumber\PhoneNumber;
  21. use libphonenumber\PhoneNumberUtil;
  22. use PHPUnit\Framework\MockObject\MockObject;
  23. use PHPUnit\Framework\TestCase;
  24. use Psr\Log\LoggerInterface;
  25. use Symfony\Component\Messenger\Envelope;
  26. use Symfony\Component\Messenger\MessageBusInterface;
  27. use Symfony\Component\Serializer\SerializerInterface;
  28. class TestableShopService extends ShopService
  29. {
  30. public PhoneNumberUtil $phoneNumberUtil;
  31. public function controlShopRequestData(ShopRequestType $type, array $data): void
  32. {
  33. parent::controlShopRequestData($type, $data);
  34. }
  35. public function createRequest(ShopRequestType $type, array $data): ShopRequest
  36. {
  37. return parent::createRequest($type, $data);
  38. }
  39. public function sendRequestValidationLink(ShopRequest $shopRequest): void
  40. {
  41. parent::sendRequestValidationLink($shopRequest);
  42. }
  43. public function handleNewStructureArtistPremiumTrialRequest(string $token): void
  44. {
  45. parent::handleNewStructureArtistPremiumTrialRequest($token);
  46. }
  47. public function createOrganization(NewStructureArtistPremiumTrialRequest $trialRequest): Organization
  48. {
  49. return parent::createOrganization($trialRequest);
  50. }
  51. public function generateSubdomain(string $name): string
  52. {
  53. return parent::generateSubdomain($name);
  54. }
  55. public function validateNewStructureArtistPremiumTrialRequest(array $data): void
  56. {
  57. parent::validateNewStructureArtistPremiumTrialRequest($data);
  58. }
  59. public function createOrganizationCreationRequestFromTrialRequest(
  60. NewStructureArtistPremiumTrialRequest $trialRequest,
  61. ): OrganizationCreationRequest {
  62. return parent::createOrganizationCreationRequestFromTrialRequest($trialRequest);
  63. }
  64. public function sendMailToSalesAdministration(NewStructureArtistPremiumTrialRequest $trialRequest): void
  65. {
  66. parent::sendMailToSalesAdministration($trialRequest);
  67. }
  68. public function sendConfirmationMailToRepresentative(NewStructureArtistPremiumTrialRequest $trialRequest): void
  69. {
  70. parent::sendConfirmationMailToRepresentative($trialRequest);
  71. }
  72. }
  73. /**
  74. * Unit tests for ShopService.
  75. */
  76. class ShopServiceTest extends TestCase
  77. {
  78. private readonly MockObject|EntityManagerInterface $entityManager;
  79. private readonly MockObject|Mailer $mailer;
  80. private string $publicBaseUrl;
  81. private string $adminBaseUrl;
  82. private readonly MockObject|OrganizationFactory $organizationFactory;
  83. private readonly MockObject|SerializerInterface $serializer;
  84. private readonly MockObject|LoggerInterface $logger;
  85. private readonly MockObject|MessageBusInterface $messageBus;
  86. private readonly MockObject|Trial $trial;
  87. private string $faqUrl;
  88. private string $softwareWebsiteUrl;
  89. public function setUp(): void
  90. {
  91. $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
  92. $this->mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
  93. $this->publicBaseUrl = 'https://example.com';
  94. $this->adminBaseUrl = 'https://admin.example.com';
  95. $this->organizationFactory = $this->getMockBuilder(OrganizationFactory::class)->disableOriginalConstructor()->getMock();
  96. $this->serializer = $this->getMockBuilder(SerializerInterface::class)->disableOriginalConstructor()->getMock();
  97. $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
  98. $this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
  99. $this->trial = $this->getMockBuilder(Trial::class)->disableOriginalConstructor()->getMock();
  100. $this->faqUrl = 'https://faq.example.com';
  101. $this->softwareWebsiteUrl = 'https://software.example.com';
  102. }
  103. private function getShopServiceMockFor(string $methodName): TestableShopService|MockObject
  104. {
  105. $shopService = $this
  106. ->getMockBuilder(TestableShopService::class)
  107. ->setConstructorArgs(
  108. [
  109. $this->entityManager,
  110. $this->mailer,
  111. $this->publicBaseUrl,
  112. $this->adminBaseUrl,
  113. $this->organizationFactory,
  114. $this->serializer,
  115. $this->logger,
  116. $this->messageBus,
  117. $this->trial,
  118. $this->faqUrl,
  119. $this->softwareWebsiteUrl,
  120. ]
  121. )
  122. ->setMethodsExcept([$methodName])
  123. ->getMock();
  124. return $shopService;
  125. }
  126. public function tearDown(): void
  127. {
  128. DatesUtils::clearFakeDatetime();
  129. }
  130. /**
  131. * Test registerNewShopRequest method.
  132. */
  133. public function testRegisterNewShopRequest(): void
  134. {
  135. $shopService = $this->getShopServiceMockFor('registerNewShopRequest');
  136. $type = ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL;
  137. $data = [
  138. 'representativeEmail' => 'test@example.com',
  139. 'representativeFirstName' => 'John',
  140. 'representativeLastName' => 'Doe',
  141. 'structureName' => 'Test Structure',
  142. ];
  143. $shopRequest = $this->getMockBuilder(ShopRequest::class)->getMock();
  144. $shopService->expects(self::once())
  145. ->method('controlShopRequestData')
  146. ->with($type, $data);
  147. $shopService->expects(self::once())
  148. ->method('createRequest')
  149. ->with($type, $data)
  150. ->willReturn($shopRequest);
  151. $shopService->expects(self::once())
  152. ->method('sendRequestValidationLink')
  153. ->with($shopRequest);
  154. $result = $shopService->registerNewShopRequest($type, $data);
  155. $this->assertSame($shopRequest, $result);
  156. }
  157. /**
  158. * Test controlShopRequestData method for NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL type.
  159. */
  160. public function testControlShopRequestDataForNewStructureArtistPremiumTrial(): void
  161. {
  162. $shopService = $this->getShopServiceMockFor('controlShopRequestData');
  163. $type = ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL;
  164. $data = [
  165. 'representativeEmail' => 'test@example.com',
  166. 'representativeFirstName' => 'John',
  167. 'representativeLastName' => 'Doe',
  168. 'structureName' => 'Test Structure',
  169. ];
  170. $shopService->expects(self::once())
  171. ->method('validateNewStructureArtistPremiumTrialRequest')
  172. ->with($data);
  173. $shopService->controlShopRequestData($type, $data);
  174. }
  175. /**
  176. * Test processShopRequest method for NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL type.
  177. */
  178. public function testProcessShopRequest(): void
  179. {
  180. $shopService = $this->getShopServiceMockFor('processShopRequest');
  181. $shopRequest = $this->getMockBuilder(ShopRequest::class)->getMock();
  182. $shopRequest->method('getType')->willReturn(ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL);
  183. $shopRequest->method('getToken')->willReturn('test-token');
  184. $this->messageBus
  185. ->expects(self::once())
  186. ->method('dispatch')
  187. ->with(self::callback(function ($message) {
  188. return $message instanceof NewStructureArtistPremiumTrial
  189. && $message->getToken() === 'test-token';
  190. }))
  191. ->willReturn(new Envelope(new NewStructureArtistPremiumTrial('azerty')));
  192. $shopRequest
  193. ->expects(self::once())
  194. ->method('setStatus')
  195. ->with(ShopRequestStatus::VALIDATED);
  196. $this->entityManager->expects(self::once())
  197. ->method('persist')
  198. ->with($shopRequest);
  199. $this->entityManager->expects(self::once())
  200. ->method('flush');
  201. $shopService->processShopRequest($shopRequest);
  202. }
  203. /**
  204. * Test createRequest method.
  205. */
  206. public function testCreateRequest(): void
  207. {
  208. $shopService = $this->getShopServiceMockFor('createRequest');
  209. $uuidRx = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i';
  210. $type = ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL;
  211. $data = [
  212. 'representativeEmail' => 'test@example.com',
  213. 'representativeFirstName' => 'John',
  214. 'representativeLastName' => 'Doe',
  215. 'structureName' => 'Test Structure',
  216. ];
  217. $this->entityManager->expects(self::once())
  218. ->method('persist')
  219. ->with(self::callback(function ($shopRequest) use ($type, $data, $uuidRx) {
  220. return $shopRequest instanceof ShopRequest
  221. && $shopRequest->getType() === $type
  222. && $shopRequest->getData() === $data
  223. && preg_match($uuidRx, $shopRequest->getToken());
  224. }));
  225. $this->entityManager->expects(self::once())
  226. ->method('flush');
  227. $result = $shopService->createRequest($type, $data);
  228. $this->assertInstanceOf(ShopRequest::class, $result);
  229. $this->assertSame($type, $result->getType());
  230. $this->assertSame($data, $result->getData());
  231. $this->assertMatchesRegularExpression($uuidRx, $result->getToken());
  232. }
  233. /**
  234. * Test sendRequestValidationLink method.
  235. */
  236. public function testSendRequestValidationLink(): void
  237. {
  238. $shopService = $this->getShopServiceMockFor('sendRequestValidationLink');
  239. $token = 'test-token';
  240. $data = [
  241. 'representativeEmail' => 'test@example.com',
  242. 'representativeFirstName' => 'John',
  243. 'representativeLastName' => 'Doe',
  244. 'structureName' => 'Test Structure',
  245. ];
  246. $shopRequest = $this->getMockBuilder(ShopRequest::class)->getMock();
  247. $shopRequest->method('getToken')->willReturn($token);
  248. $shopRequest->method('getData')->willReturn($data);
  249. $this->mailer
  250. ->expects(self::once())
  251. ->method('main')
  252. ->with(self::callback(function ($model) use ($token, $data) {
  253. return $model->getToken() === $token
  254. && $model->getRepresentativeEmail() === $data['representativeEmail']
  255. && $model->getRepresentativeFirstName() === $data['representativeFirstName']
  256. && $model->getRepresentativeLastName() === $data['representativeLastName']
  257. && $model->getStructureName() === $data['structureName']
  258. && $model->getValidationUrl() === 'https://software.example.com/shop/try/validation?token='.$token;
  259. }));
  260. $shopRequest->expects(self::once())
  261. ->method('setStatus')
  262. ->with(ShopRequestStatus::ACTIVATION_LINK_SENT);
  263. $this->entityManager->expects(self::once())
  264. ->method('persist')
  265. ->with($shopRequest);
  266. $this->entityManager->expects(self::once())
  267. ->method('flush');
  268. $shopService->sendRequestValidationLink($shopRequest);
  269. }
  270. /**
  271. * Test handleNewStructureArtistPremiumTrialRequest method.
  272. */
  273. public function testHandleNewStructureArtistPremiumTrialRequest(): void
  274. {
  275. $shopService = $this->getShopServiceMockFor('handleNewStructureArtistPremiumTrialRequest');
  276. $token = 'test-token';
  277. $data = [
  278. 'representativeEmail' => 'test@example.com',
  279. 'representativeFirstName' => 'John',
  280. 'representativeLastName' => 'Doe',
  281. 'structureName' => 'Test Structure',
  282. ];
  283. $shopRequest = $this->getMockBuilder(ShopRequest::class)->getMock();
  284. $shopRequest->method('getToken')->willReturn($token);
  285. $shopRequest->method('getData')->willReturn($data);
  286. $this->entityManager
  287. ->expects(self::once())
  288. ->method('find')
  289. ->with(ShopRequest::class, $token)
  290. ->willReturn($shopRequest);
  291. $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  292. ->getMock();
  293. $this->serializer
  294. ->expects(self::once())
  295. ->method('deserialize')
  296. ->with(json_encode($data), NewStructureArtistPremiumTrialRequest::class, 'json')
  297. ->willReturn($trialRequest);
  298. $organization = $this->getMockBuilder(Organization::class)->getMock();
  299. $shopService
  300. ->expects(self::once())
  301. ->method('createOrganization')
  302. ->with($trialRequest)
  303. ->willReturn($organization);
  304. // Add expectation for password setting
  305. $trialRequest->method('getPassword')->willReturn('Password123!');
  306. $this->organizationFactory
  307. ->expects(self::once())
  308. ->method('setAdminAccountPassword')
  309. ->with($organization, 'Password123!');
  310. $this->trial
  311. ->expects(self::once())
  312. ->method('startArtistPremiumTrialForNewStructure')
  313. ->with($organization, $trialRequest);
  314. // Mock the sendMailToSalesAdministration and sendConfirmationMailToRepresentative methods
  315. $shopService->expects(self::once())
  316. ->method('sendMailToSalesAdministration')
  317. ->with($trialRequest);
  318. $shopService->expects(self::once())
  319. ->method('sendConfirmationMailToRepresentative')
  320. ->with($trialRequest);
  321. $this->logger->expects(self::once())
  322. ->method('info')
  323. ->with('Successfully processed NewStructureArtistPremiumTrial for token: '.$token);
  324. $shopService->handleNewStructureArtistPremiumTrialRequest($token);
  325. }
  326. /**
  327. * Test handleNewStructureArtistPremiumTrialRequest method with non-existent token.
  328. */
  329. public function testHandleNewStructureArtistPremiumTrialRequestWithNonExistentToken(): void
  330. {
  331. $shopService = $this->getShopServiceMockFor('handleNewStructureArtistPremiumTrialRequest');
  332. $this->entityManager->expects(self::once())
  333. ->method('find')
  334. ->with(ShopRequest::class, 'non-existent-token')
  335. ->willReturn(null);
  336. $this->logger->expects(self::once())
  337. ->method('error')
  338. ->with('Cannot find ShopRequest with token: non-existent-token');
  339. $shopService->handleNewStructureArtistPremiumTrialRequest('non-existent-token');
  340. }
  341. /**
  342. * Test handleNewStructureArtistPremiumTrialRequest method when an exception occurs.
  343. */
  344. public function testHandleNewStructureArtistPremiumTrialRequestWithException(): void
  345. {
  346. $shopService = $this->getShopServiceMockFor('handleNewStructureArtistPremiumTrialRequest');
  347. $token = 'test-token';
  348. $data = [
  349. 'representativeEmail' => 'test@example.com',
  350. 'representativeFirstName' => 'John',
  351. 'representativeLastName' => 'Doe',
  352. 'structureName' => 'Test Structure',
  353. ];
  354. $shopRequest = $this->getMockBuilder(ShopRequest::class)->getMock();
  355. $shopRequest->method('getToken')->willReturn($token);
  356. $shopRequest->method('getData')->willReturn($data);
  357. // Expect setStatus to be called with ERROR
  358. $shopRequest->expects(self::once())
  359. ->method('setStatus')
  360. ->with(ShopRequestStatus::ERROR);
  361. $this->entityManager
  362. ->expects(self::once())
  363. ->method('find')
  364. ->with(ShopRequest::class, $token)
  365. ->willReturn($shopRequest);
  366. // Simulate an exception during deserialization
  367. $this->serializer
  368. ->expects(self::once())
  369. ->method('deserialize')
  370. ->willThrowException(new \Exception('Test exception'));
  371. // Expect persist and flush to be called to save the ERROR status
  372. $this->entityManager
  373. ->expects(self::once())
  374. ->method('persist')
  375. ->with($shopRequest);
  376. $this->entityManager
  377. ->expects(self::once())
  378. ->method('flush');
  379. // Expect error to be logged
  380. $this->logger->expects(self::once())
  381. ->method('error')
  382. ->with(self::stringContains('Error processing NewStructureArtistPremiumTrial for token: '.$token));
  383. // Expect the exception to be re-thrown
  384. $this->expectException(\Exception::class);
  385. $this->expectExceptionMessage('Test exception');
  386. $shopService->handleNewStructureArtistPremiumTrialRequest($token);
  387. }
  388. /**
  389. * Test createOrganization method.
  390. */
  391. public function testCreateOrganization(): void
  392. {
  393. $shopService = $this->getShopServiceMockFor('createOrganization');
  394. $trialRequest = $this
  395. ->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  396. ->getMock();
  397. $organizationCreationRequest = $this
  398. ->getMockBuilder(OrganizationCreationRequest::class)
  399. ->getMock();
  400. $organization = $this->getMockBuilder(Organization::class)->getMock();
  401. $shopService->expects(self::once())
  402. ->method('createOrganizationCreationRequestFromTrialRequest')
  403. ->with($trialRequest)
  404. ->willReturn($organizationCreationRequest);
  405. $this->organizationFactory
  406. ->expects(self::once())
  407. ->method('create')
  408. ->with($organizationCreationRequest)
  409. ->willReturn($organization);
  410. $result = $shopService->createOrganization($trialRequest);
  411. $this->assertSame($organization, $result);
  412. }
  413. /**
  414. * Test validateNewStructureArtistPremiumTrialRequest method with valid data.
  415. */
  416. public function testValidateNewStructureArtistPremiumTrialRequest(): void
  417. {
  418. $shopService = $this->getShopServiceMockFor('validateNewStructureArtistPremiumTrialRequest');
  419. $trialRequest = $this
  420. ->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  421. ->getMock();
  422. $organizationCreationRequest = $this
  423. ->getMockBuilder(OrganizationCreationRequest::class)
  424. ->getMock();
  425. $shopService->expects(self::once())
  426. ->method('createOrganizationCreationRequestFromTrialRequest')
  427. ->with($trialRequest)
  428. ->willReturn($organizationCreationRequest);
  429. $this->organizationFactory->expects(self::once())
  430. ->method('interruptIfOrganizationExists')
  431. ->with($organizationCreationRequest);
  432. // Convert the trial request to an array for validation
  433. $data = [
  434. 'representativePhone' => '+33123456789',
  435. ];
  436. $this->serializer->expects(self::once())
  437. ->method('deserialize')
  438. ->with(json_encode($data), NewStructureArtistPremiumTrialRequest::class, 'json')
  439. ->willReturn($trialRequest);
  440. $shopService->validateNewStructureArtistPremiumTrialRequest($data);
  441. }
  442. /**
  443. * Test createOrganizationCreationRequestFromTrialRequest method with forValidationOnly=false.
  444. */
  445. public function testCreateOrganizationCreationRequestFromTrialRequestComplete(): void
  446. {
  447. $shopService = $this->getShopServiceMockFor('createOrganizationCreationRequestFromTrialRequest');
  448. $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  449. ->getMock();
  450. $phoneNumber = $this->createMock(PhoneNumber::class);
  451. $trialRequest->method('getStructureName')->willReturn('Test Structure');
  452. $trialRequest->method('getCity')->willReturn('Test City');
  453. $trialRequest->method('getPostalCode')->willReturn('12345');
  454. $trialRequest->method('getAddress')->willReturn('Test Address');
  455. $trialRequest->method('getAddressComplement')->willReturn('Test Address Complement');
  456. $trialRequest->method('getRepresentativePhone')->willReturn($phoneNumber);
  457. $trialRequest->method('getStructureEmail')->willReturn('structure@example.com');
  458. $trialRequest->method('getStructureType')->willReturn(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY);
  459. $trialRequest->method('getLegalStatus')->willReturn(LegalEnum::ASSOCIATION_LAW_1901);
  460. $trialRequest->method('getSiren')->willReturn('123456789');
  461. $trialRequest->method('getStructureIdentifier')->willReturn('test-structure');
  462. // Set a fake date for testing
  463. $fakeDate = '2023-05-15 10:30:00';
  464. DatesUtils::setFakeDatetime($fakeDate);
  465. // Create the organization creation request
  466. $result = $shopService->createOrganizationCreationRequestFromTrialRequest($trialRequest);
  467. // Verify that all fields are set
  468. $this->assertEquals('Test Structure', $result->getName());
  469. $this->assertEquals('Test City', $result->getCity());
  470. $this->assertEquals('12345', $result->getPostalCode());
  471. $this->assertEquals('Test Address', $result->getStreetAddress1());
  472. $this->assertEquals('Test Address Complement', $result->getStreetAddress2());
  473. $this->assertEquals('structure@example.com', $result->getEmail());
  474. $this->assertEquals(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY, $result->getPrincipalType());
  475. $this->assertEquals(LegalEnum::ASSOCIATION_LAW_1901, $result->getLegalStatus());
  476. $this->assertEquals('123456789', $result->getSiretNumber());
  477. $this->assertEquals($phoneNumber, $result->getPhoneNumber());
  478. $this->assertEquals('test-structure', $result->getSubdomain());
  479. $this->assertEquals(SettingsProductEnum::FREEMIUM, $result->getProduct());
  480. $this->assertFalse($result->getCreateWebsite());
  481. $this->assertFalse($result->isClient());
  482. $this->assertEquals(new \DateTime($fakeDate), $result->getCreationDate());
  483. }
  484. /**
  485. * Test sendMailToSalesAdministration method.
  486. */
  487. public function testSendMailToSalesAdministration(): void
  488. {
  489. $shopService = $this->getShopServiceMockFor('sendMailToSalesAdministration');
  490. $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  491. ->getMock();
  492. $this->mailer
  493. ->expects(self::once())
  494. ->method('main')
  495. ->with(self::callback(function ($model) use ($trialRequest) {
  496. return $model instanceof \App\Service\Mailer\Model\Shop\NewStructureArtistPremium\NotificationToSalesAdminModel
  497. && $model->getTrialRequest() === $trialRequest
  498. && $model->getSenderId() === \App\Enum\Access\AccessIdsEnum::ADMIN_2IOPENSERVICE->value;
  499. }));
  500. $shopService->sendMailToSalesAdministration($trialRequest);
  501. }
  502. /**
  503. * Test sendConfirmationMailToRepresentative method.
  504. */
  505. public function testSendConfirmationMailToRepresentative(): void
  506. {
  507. $shopService = $this->getShopServiceMockFor('sendConfirmationMailToRepresentative');
  508. $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
  509. ->getMock();
  510. $trialRequest->method('getStructureIdentifier')->willReturn('test-structure');
  511. $this->mailer
  512. ->expects(self::once())
  513. ->method('main')
  514. ->with(self::callback(function ($model) use ($trialRequest) {
  515. return $model instanceof \App\Service\Mailer\Model\Shop\NewStructureArtistPremium\ConfirmationToRepresentativeModel
  516. && $model->getTrialRequest() === $trialRequest
  517. && $model->getSenderId() === \App\Enum\Access\AccessIdsEnum::ADMIN_2IOPENSERVICE->value
  518. && $model->getAccountCreationUrl() === 'https://example.com/account/create'
  519. && $model->getFaqUrl() === 'https://faq.example.com'
  520. && $model->getAdminUsername() === 'admintest-structure'
  521. && $model->getAdminLoginUrl() === 'https://admin.example.com/#/login/';
  522. }));
  523. $shopService->sendConfirmationMailToRepresentative($trialRequest);
  524. }
  525. }