diff --git a/src/Shop/Http/Responses/ShopSetupResponse.php b/src/Shop/Http/Responses/ShopSetupResponse.php index a838e87..4f05624 100644 --- a/src/Shop/Http/Responses/ShopSetupResponse.php +++ b/src/Shop/Http/Responses/ShopSetupResponse.php @@ -6,26 +6,29 @@ use Illuminate\Contracts\Support\Responsable; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Response; -use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class ShopSetupResponse implements Responsable { + /** + * @param string|null $authorizationUrl URL to external authorization service. + * @param bool $showConfiguration Instruction to the client of the response to display configuration form + */ public function __construct( private readonly ?string $authorizationUrl = null, + private readonly bool $showConfiguration = false, ) { } - public function toResponse($request): SymfonyResponse + public function toResponse($request): JsonResponse { - if (!$this->authorizationUrl) { - return new Response('', SymfonyResponse::HTTP_NO_CONTENT); + $responseData = [ + 'show_configuration' => $this->showConfiguration, + ]; + + if ($this->authorizationUrl) { + $responseData['authorization_url'] = $this->authorizationUrl; } - return new JsonResponse([ - 'data' => [ - 'authorization_url' => $this->authorizationUrl, - ], - ]); + return new JsonResponse(['data' => $responseData]); } } diff --git a/tests/Shops/ShopSetupResponseTest.php b/tests/Shops/ShopSetupResponseTest.php new file mode 100644 index 0000000..225174c --- /dev/null +++ b/tests/Shops/ShopSetupResponseTest.php @@ -0,0 +1,67 @@ +toResponse(Mockery::mock(Request::class)) + ->getData(true), + ); + } + + public static function setupProvider(): array + { + return [ + [ + 'authorizationUrl' => null, + 'showConfiguration' => false, + 'responseData' => [ + 'data' => [ + 'show_configuration' => false, + ], + ], + ], + [ + 'authorizationUrl' => null, + 'showConfiguration' => true, + 'responseData' => [ + 'data' => [ + 'show_configuration' => true, + ], + ], + ], + [ + 'authorizationUrl' => 'http://localhost', + 'showConfiguration' => false, + 'responseData' => [ + 'data' => [ + 'show_configuration' => false, + 'authorization_url' => 'http://localhost', + ], + ], + ], + ]; + } +}