| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace Webkul\BagistoApi\Tests;
- use Illuminate\Testing\TestResponse;
- use Webkul\Customer\Models\Customer;
- /**
- * Base test case for GraphQL API tests.
- *
- * Provides convenience methods for public and authenticated
- * GraphQL requests with storefront key handling.
- */
- abstract class GraphQLTestCase extends BagistoApiTestCase
- {
- /** GraphQL endpoint URL */
- protected string $graphqlUrl = '/api/graphql';
- /**
- * Execute a public GraphQL query (storefront key only, no auth)
- */
- protected function graphQL(string $query, array $variables = [], array $headers = []): TestResponse
- {
- $payload = ['query' => $query];
- if (! empty($variables)) {
- $payload['variables'] = $variables;
- }
- $headers = array_merge($this->storefrontHeaders(), $headers);
- return $this->postJson($this->graphqlUrl, $payload, $headers);
- }
- /**
- * Execute an authenticated GraphQL query (storefront key + customer token)
- */
- protected function authenticatedGraphQL(Customer $customer, string $query, array $variables = []): TestResponse
- {
- $payload = ['query' => $query];
- if (! empty($variables)) {
- $payload['variables'] = $variables;
- }
- return $this->actingAs($customer)
- ->withHeaders($this->authHeaders($customer))
- ->postJson($this->graphqlUrl, $payload);
- }
- }
|