Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(APQ): Simplify test case by using query helper method #1393

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions tests/src/Kernel/Framework/AutomaticPersistedQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ public function testAutomaticPersistedQueries(): void {
$this->server->addPersistedQueryInstance($this->pluginApq);
$this->server->save();

$endpoint = $this->server->get('endpoint');

$query = 'query { field_one } ';
$parameters['extensions']['persistedQuery']['sha256Hash'] = 'some random hash';
$extensions = ['persistedQuery' => ['sha256Hash' => 'some random hash']];

// Check we get PersistedQueryNotFound.
$request = Request::create($endpoint, 'GET', $parameters);
$result = $this->container->get('http_kernel')->handle($request);
$result = $this->query('', $this->server, [], $extensions);

$this->assertSame(200, $result->getStatusCode());
$this->assertSame([
'errors' => [
Expand All @@ -71,9 +69,8 @@ public function testAutomaticPersistedQueries(): void {
], json_decode($result->getContent(), TRUE));

// Post query to endpoint with a not matching hash.
$content = json_encode(['query' => $query] + $parameters);
$request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content);
$result = $this->container->get('http_kernel')->handle($request);
$result = $this->query($query, $this->server, [], $extensions, FALSE, Request::METHOD_POST);

$this->assertSame(200, $result->getStatusCode());
$this->assertSame([
'errors' => [
Expand All @@ -85,17 +82,14 @@ public function testAutomaticPersistedQueries(): void {
], json_decode($result->getContent(), TRUE));

// Post query to endpoint to get the result and cache it.
$parameters['extensions']['persistedQuery']['sha256Hash'] = hash('sha256', $query);
$extensions['persistedQuery']['sha256Hash'] = hash('sha256', $query);
$result = $this->query($query, $this->server, [], $extensions, FALSE, Request::METHOD_POST);

$content = json_encode(['query' => $query] + $parameters);
$request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content);
$result = $this->container->get('http_kernel')->handle($request);
$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['field_one' => 'this is the field one']], json_decode($result->getContent(), TRUE));

// Execute first request again.
$request = Request::create($endpoint, 'GET', $parameters);
$result = $this->container->get('http_kernel')->handle($request);
// Execute first GET request again.
$result = $this->query($query, $this->server, [], $extensions);
$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['field_one' => 'this is the field one']], json_decode($result->getContent(), TRUE));
}
Expand Down