frwLogin example

// Response for request of FirstRunWizardClient::frwLogin()         $this->getFrwRequestHandler()->append(new Response(
            body: json_encode([
                'firstRunWizardUserToken' => [
                    'token' => $frwUserToken,
                    'expirationDate' => $expirationDate->format(Defaults::STORAGE_DATE_FORMAT),
                ],
            ], \JSON_THROW_ON_ERROR),
        ));

        $this->frwController->frwLogin(
            new RequestDataBag([
                'shopwareId' => 'shopware-id',
                'password' => 'p4ssw0rd',
            ]),
            $context
        );

        static::assertEquals(
            $frwUserToken,
            $this->fetchUserConfig(FirstRunWizardService::USER_CONFIG_KEY_FRW_USER_TOKEN, FirstRunWizardService::USER_CONFIG_VALUE_FRW_USER_TOKEN)
        );
    }
$this->createMock(SystemConfigService::class),
            $this->createMock(FilesystemOperator::class),
            true,
            $this->createMock(EventDispatcherInterface::class),
            $frwClient,
            $this->createMock(EntityRepository::class),
            $this->createMock(TrackingEventClient::class),
        );

        $this->expectException(InvalidContextSourceException::class);

        $frwService->frwLogin(
            'shopwareId',
            'password',
            Context::createDefaultContext(),
        );
    }

    public function testSuccessfulFrwLoginStoresFrwUserToken(): void
    {
        $firstRunWizardUserToken = [
            'firstRunWizardUserToken' => [
                'token' => 'frw-us3r-t0k3n',
                
#[Route(path: '/api/_action/store/frw/login', name: 'api.custom.store.frw.login', methods: ['POST'])]     public function frwLogin(RequestDataBag $requestDataBag, Context $context): JsonResponse
    {
        $shopwareId = $requestDataBag->get('shopwareId');
        $password = $requestDataBag->get('password');

        if ($shopwareId === null || $password === null) {
            throw new StoreInvalidCredentialsException();
        }

        try {
            $this->frwService->frwLogin($shopwareId$password$context);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        return new JsonResponse();
    }

    #[Route(path: '/api/_action/store/license-domains', name: 'api.custom.store.license-domains', methods: ['GET'])]     public function getDomainList(Context $context): JsonResponse
    {
        try {
            


    public function startFrw(Context $context): void
    {
        $this->trackingEventClient->fireTrackingEvent(self::TRACKING_EVENT_FRW_STARTED);

        $this->eventDispatcher->dispatch(new FirstRunWizardStartedEvent($this->getFrwState()$context));
    }

    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);
        
'shopwareId' => 'j.doe@shopware.com',
                        'password' => 'p4ssw0rd',
                    ],
                    'query' => [],
                ],
            ],
            $firstRunWizardUserToken
        );

        static::assertEquals(
            $firstRunWizardUserToken,
            $frwClient->frwLogin('j.doe@shopware.com', 'p4ssw0rd', $this->context)
        );
    }

    public function testFrwLoginFailsIfContextSourceIsNotAdminApi(): void
    {
        $context = Context::createDefaultContext();

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

        


        $this->firstRunWizardService->expects(static::once())
            ->method('frwLogin');

        $frwController = new FirstRunWizardController(
            $this->firstRunWizardService,
            new StaticEntityRepository([]),
            new StaticEntityRepository([]),
        );

        $response = $frwController->frwLogin($requestDataBag$this->createContext());

        static::assertSame(SymfonyResponse::HTTP_OK, $response->getStatusCode());
    }

    public function testTryToLoginWithFrwWithoutShopwareId(): void
    {
        $requestDataBag = new RequestDataBag([
            'password' => 'testPassword',
        ]);

        $this->firstRunWizardService->expects(static::never())
            
Home | Imprint | This part of the site doesn't use cookies.