1313use  PrestaShop \Module \PsAccounts \Service \Accounts \AccountsService ;
1414use  PrestaShop \Module \PsAccounts \Provider \ShopProvider ;
1515use  PrestaShop \Module \PsAccounts \Service \OAuth2 \OAuth2Service ;
16+ use  PrestaShop \Module \PsAccounts \Service \UpgradeService ;
1617use  PrestaShop \Module \PsAccounts \Tests \TestCase ;
1718
1819class  MigrateOrCreateIdentityV8HandlerTest extends  TestCase
@@ -55,6 +56,11 @@ class MigrateOrCreateIdentityV8HandlerTest extends TestCase
5556     */ 
5657    public  $ statusManager
5758
59+     /** 
60+      * @var UpgradeService 
61+      */ 
62+     public  $ upgradeService
63+ 
5864    /** 
5965     * @inject 
6066     * 
@@ -94,6 +100,7 @@ public function set_up()
94100        $ this oAuth2Client  = $ this createMock (Client::class);
95101        $ this accountsService ->setClient ($ this accountsClient );
96102        $ this oAuth2Service ->setHttpClient ($ this oAuth2Client );
103+         $ this upgradeService  = new  UpgradeService ($ this configurationRepository );
97104
98105//        $this->accountsService = $this->createMock(AccountsService::class); 
99106//        $this->oAuth2Service = $this->createMock(OAuth2Service::class); 
@@ -113,7 +120,8 @@ public function itShouldMigrateIdentityFromV7()
113120        $ tokenAudience'shop_ '  . $ cloudShopId
114121
115122        // introduced in v7 
116-         $ this configurationRepository ->updateLastUpgrade ('7.2.0 ' );
123+         //$this->configurationRepository->updateLastUpgrade('7.2.0'); 
124+         $ this upgradeService ->setRegisteredVersion ('7.2.0 ' );
117125
118126        $ this configurationRepository ->updateShopUuid ($ cloudShopId
119127
@@ -149,7 +157,8 @@ public function itShouldMigrateIdentityFromV7()
149157                $ this assertArrayHasKey ('frontendUrl ' , $ optionsJSON ]);
150158                $ this assertArrayHasKey ('multiShopId ' , $ optionsJSON ]);
151159                $ this assertEquals ($ this proofManager ->getProof (), $ optionsJSON ]['proof ' ]);
152-                 $ this assertEquals ((string ) $ this configurationRepository ->getLastUpgrade (), $ optionsJSON ]['fromVersion ' ]);
160+                 //$this->assertEquals((string) $this->configurationRepository->getLastUpgrade(), $options[Request::JSON]['fromVersion']); 
161+                 $ this assertEquals ((string ) $ this upgradeService ->getRegisteredVersion (), $ optionsJSON ]['fromVersion ' ]);
153162
154163                return  $ this createResponse ([
155164                    'clientId '  => $ clientId
@@ -160,6 +169,7 @@ public function itShouldMigrateIdentityFromV7()
160169
161170        $ this getHandler ()->handle (new  MigrateOrCreateIdentityV8Command ($ this shopId ));
162171
172+         $ this assertEquals (\Ps_accounts::VERSION , $ this upgradeService ->getRegisteredVersion ());
163173        $ this assertEmpty ($ this configurationRepository ->getAccessToken ());
164174        $ this assertTrue ($ this statusManager ->cacheInvalidated ());
165175        $ this assertEquals ($ cloudShopId$ this statusManager ->getCloudShopId ());
@@ -237,7 +247,12 @@ public function itShouldMigrateIdentityFromV5AndV6()
237247        $ token$ this faker ->uuid ;
238248
239249        // introduced in v7 
240-         $ this configurationRepository ->updateLastUpgrade (null );
250+         //$this->configurationRepository->updateLastUpgrade(null); 
251+ 
252+         $ fromVersion'5.6.2 ' ;
253+         $ this upgradeService ->setCoreRegisteredVersion ($ fromVersion
254+         // FIXME: not working with null on v9 
255+         $ this upgradeService ->setRegisteredVersion ('0 ' );
241256
242257        $ this configurationRepository ->updateShopUuid ($ cloudShopId
243258
@@ -258,14 +273,15 @@ public function itShouldMigrateIdentityFromV5AndV6()
258273                $ this matches ('/v1/shop-identities/ '  . $ cloudShopId'/migrate ' ),
259274                $ this isType ('array ' )
260275            )
261-             ->willReturnCallback (function  ($ route$ optionsuse  ($ cloudShopId$ clientId$ clientSecret$ token
276+             ->willReturnCallback (function  ($ route$ optionsuse  ($ cloudShopId$ clientId$ clientSecret$ token,  $ fromVersion 
262277
263278                $ this assertEquals ('Bearer  '  . $ token$ optionsHEADERS ]['Authorization ' ]);
264279                $ this assertArrayHasKey ('backOfficeUrl ' , $ optionsJSON ]);
265280                $ this assertArrayHasKey ('frontendUrl ' , $ optionsJSON ]);
266281                $ this assertArrayHasKey ('multiShopId ' , $ optionsJSON ]);
267282                $ this assertEquals ($ this proofManager ->getProof (), $ optionsJSON ]['proof ' ]);
268-                 $ this assertEquals ((string ) $ this configurationRepository ->getLastUpgrade (), $ optionsJSON ]['fromVersion ' ]);
283+                 //$this->assertEquals((string) $this->configurationRepository->getLastUpgrade(), $options[Request::JSON]['fromVersion']); 
284+                 $ this assertEquals ($ fromVersion$ optionsJSON ]['fromVersion ' ]);
269285
270286                return  $ this createResponse ([
271287                    'clientId '  => $ clientId
@@ -276,6 +292,7 @@ public function itShouldMigrateIdentityFromV5AndV6()
276292
277293        $ this getHandler ()->handle (new  MigrateOrCreateIdentityV8Command ($ this shopId ));
278294
295+         $ this assertEquals (\Ps_accounts::VERSION , $ this upgradeService ->getRegisteredVersion ());
279296        $ this assertTrue ($ this statusManager ->cacheInvalidated ());
280297        $ this assertEquals ($ cloudShopId$ this statusManager ->getCloudShopId ());
281298        $ this assertEquals ($ clientId$ this oAuth2Service ->getOAuth2Client ()->getClientId ());
@@ -294,7 +311,9 @@ public function itShouldNotMigrateOnError()
294311        $ tokenAudience'shop_ '  . $ cloudShopId
295312
296313        // introduced in v7 
297-         $ this configurationRepository ->updateLastUpgrade ('7.2.0 ' );
314+         //$this->configurationRepository->updateLastUpgrade('7.2.0'); 
315+         $ fromVersion'7.2.0 ' ;
316+         $ this upgradeService ->setRegisteredVersion ($ fromVersion
298317
299318        $ this configurationRepository ->updateShopUuid ($ cloudShopId
300319
@@ -330,7 +349,8 @@ public function itShouldNotMigrateOnError()
330349                $ this assertArrayHasKey ('frontendUrl ' , $ optionsJSON ]);
331350                $ this assertArrayHasKey ('multiShopId ' , $ optionsJSON ]);
332351                $ this assertEquals ($ this proofManager ->getProof (), $ optionsJSON ]['proof ' ]);
333-                 $ this assertEquals ((string ) $ this configurationRepository ->getLastUpgrade (), $ optionsJSON ]['fromVersion ' ]);
352+                 //$this->assertEquals((string) $this->configurationRepository->getLastUpgrade(), $options[Request::JSON]['fromVersion']); 
353+                 $ this assertEquals ((string ) $ this upgradeService ->getRegisteredVersion (), $ optionsJSON ]['fromVersion ' ]);
334354
335355                return  $ this createResponse ([
336356                    "error "  => 'store-identity/migration-failed ' ,
@@ -340,6 +360,7 @@ public function itShouldNotMigrateOnError()
340360
341361        $ this getHandler ()->handle (new  MigrateOrCreateIdentityV8Command ($ this shopId ));
342362
363+         $ this assertEquals ($ fromVersion$ this upgradeService ->getRegisteredVersion ());
343364        $ this assertTrue ($ this statusManager ->cacheInvalidated ());
344365        $ this assertEquals ($ cloudShopId$ this statusManager ->getCloudShopId ());
345366
0 commit comments