Skip to content

Instantly share code, notes, and snippets.

@PCreations
Created September 3, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PCreations/c20e14b45b0b09697633807148acb217 to your computer and use it in GitHub Desktop.
Save PCreations/c20e14b45b0b09697633807148acb217 to your computer and use it in GitHub Desktop.
import { createTestServer } from "./test-server";
import {
createExecuteLatestArticlesQuery,
createFakeExecuteLatestArticlesQuery,
GraphQLError,
} from "../execute-latest-articles-query";
import { createTestArticlePublishedOneDayAgo } from "./data/create-test-article";
describe("executeLatestArticlesQuery", () => {
let testServer;
beforeAll([...]);
afterAll([...]);
it("executes the correct request", async () => {...});
it("get the latest articles from the graphQL response", async () => {...});
it("fails with a GraphQLError if there are graphQL errors in the response", async () => {...});
it("response can be faked with predefined articles for a specific domain", async () => {
// arrange
expect.assertions(2);
const domainA = "www.domain-a.co.uk";
const expectedArticlesForDomainA = [
createTestArticlePublishedOneDayAgo(),
createTestArticlePublishedOneDayAgo(),
createTestArticlePublishedOneDayAgo(),
];
const domainB = "www.domain-b.co.uk";
const expectedArticlesForDomainB = [
createTestArticlePublishedOneDayAgo(),
createTestArticlePublishedOneDayAgo(),
createTestArticlePublishedOneDayAgo(),
];
const executeLatestArticlesQuery = createFakeExecuteLatestArticlesQuery({
[domainA]: expectedArticlesForDomainA,
[domainB]: expectedArticlesForDomainB,
});
// act
const receivedArticlesForDomainA = await executeLatestArticlesQuery({
domain: domainA,
});
const receivedArticlesForDomainB = await executeLatestArticlesQuery({
domain: domainB,
});
// assert
expect(receivedArticlesForDomainA).toEqual(expectedArticlesForDomainA);
expect(receivedArticlesForDomainB).toEqual(expectedArticlesForDomainB);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment