Browse Source

fix unit tests

Olivier Massot 7 months ago
parent
commit
966463cdbb

+ 1 - 1
src/Service/ApiResourceBuilder/Mobyt/MobytUserStatusBuilder.php

@@ -45,7 +45,7 @@ class MobytUserStatusBuilder
         foreach ($userStatusData['sms'] as $_ => $smsTypeData) {
             // we only retrieve the 'top quality sms', which are identified by the letter N in the mobyt api
             if ($smsTypeData['type'] === 'N') {
-                $topQualitySmsAmount = $smsTypeData['quantity'];
+                $topQualitySmsAmount = (int)$smsTypeData['quantity'];
             }
         }
         $userStatus->setAmount($topQualitySmsAmount);

+ 0 - 1
src/Service/Dolibarr/DolibarrSyncService.php

@@ -61,7 +61,6 @@ class DolibarrSyncService
     public function __construct(
         private OrganizationRepository $organizationRepository,
         private AccessRepository $accessRepository,
-        private FunctionTypeRepository $functionTypeRepository,
         private DolibarrApiService $dolibarrApiService,
         private AddressPostalUtils $addressPostalUtils,
         private ArrayUtils $arrayUtils,

+ 15 - 12
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -126,7 +126,6 @@ class DolibarrSyncServiceTest extends TestCase
 {
     private MockObject|OrganizationRepository $organizationRepository;
     private MockObject|AccessRepository $accessRepository;
-    private MockObject|FunctionTypeRepository $functionTypeRepository;
     private MockObject|DolibarrApiService $dolibarrApiService;
     private MockObject|AddressPostalUtils $addressPostalUtils;
     private MockObject|ArrayUtils $arrayUtils;
@@ -142,9 +141,6 @@ class DolibarrSyncServiceTest extends TestCase
         $this->accessRepository = $this->getMockBuilder(AccessRepository::class)
             ->disableOriginalConstructor()
             ->getMock();
-        $this->functionTypeRepository = $this->getMockBuilder(FunctionTypeRepository::class)
-            ->disableOriginalConstructor()
-            ->getMock();
         $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
             ->disableOriginalConstructor()
             ->getMock();
@@ -178,7 +174,7 @@ class DolibarrSyncServiceTest extends TestCase
     private function getMockForMethod(string $method)
     {
         $dolibarrSyncService = $this->getMockBuilder(TestableDolibarrSyncService::class)
-            ->setConstructorArgs([$this->organizationRepository, $this->accessRepository, $this->functionTypeRepository,
+            ->setConstructorArgs([$this->organizationRepository, $this->accessRepository,
                 $this->dolibarrApiService, $this->addressPostalUtils, $this->arrayUtils, $this->translator, $this->organizationUtils])
             ->setMethodsExcept([$method, 'setLoggerInterface'])
             ->getMock();
@@ -406,11 +402,6 @@ class DolibarrSyncServiceTest extends TestCase
         $functionType1->method('getMission')->willReturn(FunctionEnum::DIRECTOR);
         $functionType2 = $this->getMockBuilder(FunctionType::class)->getMock();
         $functionType2->method('getMission')->willReturn(FunctionEnum::PRESIDENT);
-        $this->functionTypeRepository
-            ->expects($this->once())
-            ->method('findBy')
-            ->with(['roleByDefault' => RoleEnum::ROLE_ADMIN])
-            ->willReturn([$functionType1, $functionType2]);
 
         // Get CMF and FFEC ids
         $this->dolibarrApiService->method('getSociety')->willReturnMap(
@@ -499,12 +490,24 @@ class DolibarrSyncServiceTest extends TestCase
             [$organization2, true],
         ]);
 
+        $adminFunctions = [
+            FunctionEnum::NETWORK_ANIMATOR->value, FunctionEnum::ARCHIVIST->value, FunctionEnum::COM_STAFF->value, FunctionEnum::ACCOUNTANT->value,
+            FunctionEnum::COORDINATOR->value, FunctionEnum::CORRESPONDING->value, FunctionEnum::ADMINISTRATIVE_DIRECTOR->value,
+            FunctionEnum::ADMINISTRATIVE_DIRECTOR_ASSISTANT->value, FunctionEnum::ADMINISTRATIVE_STAFF->value, FunctionEnum::TECHNICAL_STAFF->value,
+            FunctionEnum::PRESENTER->value, FunctionEnum::ADMINISTRATIVE_OFFICER->value, FunctionEnum::ADMINISTRATIVE_SECRETARY->value,
+            FunctionEnum::ACTIVE_MEMBER_OF_THE_CA->value, FunctionEnum::ACTIVE_COOPTED_MEMBER_OF_THE_CA->value, FunctionEnum::ACTIVE_SUBSTITUTE_MEMBER_OF_THE_CA->value,
+            FunctionEnum::MEMBER_OF_THE_BOARD->value, FunctionEnum::PRESIDENT->value, FunctionEnum::PRESIDENT_ASSISTANT->value, FunctionEnum::SECRETARY->value,
+            FunctionEnum::ASSISTANT_SECRETARY->value, FunctionEnum::TREASURER->value, FunctionEnum::TREASURER_ASSISTANT->value,
+            FunctionEnum::VICE_PRESIDENT->value, FunctionEnum::ARTISTIC_DIRECTOR->value, FunctionEnum::ARTISTIC_DIRECTOR_ASSISTANT->value,
+            FunctionEnum::DIRECTOR->value, FunctionEnum::DIRECTOR_ASSISTANT->value
+        ];
+
         $dolibarrSyncService->method('countWithMission')->willReturnMap([
             [[FunctionEnum::STUDENT->value], $activeMembers1, 1],
             [[FunctionEnum::ADHERENT->value], $activeMembers1, 2],
             [[FunctionEnum::ADHERENT->value], $activeMembers2, 0],
-            [[FunctionEnum::DIRECTOR->value, FunctionEnum::PRESIDENT->value], $activeMembers1, 1],
-            [[FunctionEnum::DIRECTOR->value, FunctionEnum::PRESIDENT->value], $activeMembers2, 2],
+            [$adminFunctions, $activeMembers1, 1],
+            [$adminFunctions, $activeMembers2, 2],
         ]);
 
         $this->arrayUtils

+ 7 - 4
tests/Unit/Service/Organization/OrganizationProfileCreatorTest.php

@@ -13,6 +13,7 @@ use App\Enum\Organization\PrincipalTypeEnum;
 use App\Enum\Organization\SettingsProductEnum;
 use App\Service\Network\Tree;
 use App\Service\Organization\OrganizationProfileCreator;
+use App\Service\Organization\Trial;
 use App\Service\Organization\Utils as OrganizationUtils;
 use App\Service\Security\Module;
 use Doctrine\Common\Collections\ArrayCollection;
@@ -23,12 +24,14 @@ class OrganizationProfileCreatorTest extends TestCase
     private Module $module;
     private Tree $tree;
     private OrganizationUtils $organizationUtils;
+    private Trial $trialService;
 
     public function setUp(): void
     {
         $this->module = $this->getMockBuilder(Module::class)->disableOriginalConstructor()->getMock();
         $this->tree = $this->getMockBuilder(Tree::class)->disableOriginalConstructor()->getMock();
         $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
+        $this->trialService = $this->getMockBuilder(Trial::class)->disableOriginalConstructor()->getMock();
     }
 
     /**
@@ -37,7 +40,7 @@ class OrganizationProfileCreatorTest extends TestCase
     public function testCreateCompleteOrganizationProfile(): void
     {
         $organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)
-            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils])
+            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils, $this->trialService])
             ->setMethodsExcept(['createCompleteOrganizationProfile'])
             ->getMock();
 
@@ -121,7 +124,7 @@ class OrganizationProfileCreatorTest extends TestCase
     public function testCreateOrganizationProfileWithoutAdherentListBecauseOfPrincipalType(): void
     {
         $organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)
-            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils])
+            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils, $this->trialService])
             ->setMethodsExcept(['createCompleteOrganizationProfile'])
             ->getMock();
 
@@ -154,7 +157,7 @@ class OrganizationProfileCreatorTest extends TestCase
     public function testCreateOrganizationProfileWithoutAdherentList(): void
     {
         $organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)
-            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils])
+            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils, $this->trialService])
             ->setMethodsExcept(['createCompleteOrganizationProfile'])
             ->getMock();
 
@@ -185,7 +188,7 @@ class OrganizationProfileCreatorTest extends TestCase
     public function testCreateLightOrganizationProfile(): void
     {
         $organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)
-            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils])
+            ->setConstructorArgs([$this->module, $this->tree, $this->organizationUtils, $this->trialService])
             ->setMethodsExcept(['createLightOrganizationProfile'])
             ->getMock();