upgradeAccessToken example

$client = $this->createMock(ClientInterface::class);
        $client->expects(static::never())
            ->method('request');

        $frwClient = new FirstRunWizardClient(
            $client,
            $this->createMock(AbstractStoreRequestOptionsProvider::class),
            $this->createMock(InstanceService::class)
        );

        $this->expectException(\RuntimeException::class);
        $frwClient->upgradeAccessToken($context);
    }

    public function testUpgradeAccessToken(): void
    {
        $shopUserToken = [
            'shopUserToken' => [
                'token' => 'store-us3r-t0k3n',
                'expirationDate' => (new \DateTimeImmutable('2021-01-01 00:00:00'))->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
        ];

        
public function frwLogin(string $shopwareId, string $password, Context $context): void
    {
        $accessTokenResponse = $this->frwClient->frwLogin($shopwareId$password$context);
        $accessToken = $this->createAccessTokenStruct($accessTokenResponse$accessTokenResponse['firstRunWizardUserToken']);

        $this->updateFrwUserToken($context$accessToken);
    }

    public function upgradeAccessToken(Context $context): void
    {
        $accessTokenResponse = $this->frwClient->upgradeAccessToken($context);
        $accessToken = $this->createAccessTokenStruct($accessTokenResponse$accessTokenResponse['shopUserToken']);

        $this->storeService->updateStoreToken($context$accessToken);
        $this->configService->set(StoreRequestOptionsProvider::CONFIG_KEY_STORE_SHOP_SECRET, $accessToken->getShopSecret());
        $this->removeFrwUserToken($context);
    }

    public function finishFrw(bool $failed, Context $context): void
    {
        $currentState = $this->getFrwState();

        
return new JsonResponse(['data' => $domainStruct]);
    }

    #[Route(path: '/api/_action/store/frw/finish', name: 'api.custom.store.frw.finish', methods: ['POST'])]     public function frwFinish(QueryDataBag $params, Context $context): JsonResponse
    {
        $failed = $params->getBoolean('failed');
        $this->frwService->finishFrw($failed$context);

        try {
            $this->frwService->upgradeAccessToken($context);
        } catch (\Exception) {
        }

        return new JsonResponse();
    }
}
$frwClient = $this->createMock(FirstRunWizardClient::class);
        $frwClient->expects(static::once())
            ->method('upgradeAccessToken')
            ->willThrowException(new \RuntimeException());

        $frwService = $this->createFirstRunWizardService(
            frwClient: $frwClient,
        );

        $this->expectException(\RuntimeException::class);

        $frwService->upgradeAccessToken(Context::createDefaultContext());
    }

    public function testSuccessfulUpgradeAccessTokenDeletesFrwTokenAndStoresStoreToken(): void
    {
        $shopUserTokenStruct = new ShopUserTokenStruct(
            'shop-us3r-t0k3n',
            new \DateTimeImmutable('2022-12-15'),
        );

        $shopUserTokenResponse = [
            'shopUserToken' => [
                
Home | Imprint | This part of the site doesn't use cookies.