Skip to content

Commit

Permalink
Update @acusti/post tests to rely on a single API
Browse files Browse the repository at this point in the history
halve our dependencies on external resources (2 → 1)
  • Loading branch information
acusti committed Apr 29, 2024
1 parent 0f8e51e commit 5f399d5
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions packages/post/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@ import { post } from './index.js';

// To find open GraphQL APIs for testing:
// https://www.apollographql.com/blog/community/backend/8-free-to-use-graphql-apis-for-your-projects-and-demos/
const URL = 'https://countries.trevorblades.com/graphql';

describe('post', () => {
it('performs a POST request to a GraphQL API for a List query and returns the response as JSON', async () => {
const url = 'https://swapi-graphql.netlify.app/.netlify/functions/index';
const result = await post<{
data?: {
allFilms: {
edges: Array<{
node: { director: string; episodeID: string; title: string };
}>;
};
countries: Array<{ name: string; capital: string; emoji: string }>;

Check failure on line 13 in packages/post/src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected interface keys to be in ascending order. 'capital' should be before 'name'

Check failure on line 13 in packages/post/src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected interface keys to be in ascending order. 'capital' should be before 'name'
};
errors?: Array<{ message: string }>;
}>(url, {
query: `query Query {
allFilms {
edges {
node {
director
episodeID
title
}
}
}>(URL, {
query: `query {
countries {
name
capital
emoji
}
}`,
});

const firstFilm = result.data!.allFilms.edges[0].node;
expect(firstFilm.title).toBeTruthy();
expect(firstFilm.episodeID).toBeTruthy();
expect(firstFilm.director).toBeTruthy();
const first = result.data!.countries[0];
expect(first.name.length).toBeGreaterThan(1);
expect(first.capital.length).toBeGreaterThan(1);
expect(first.emoji).toBeTruthy();
});

it('performs a POST request to a GraphQL API for a Get query and returns the response as JSON', async () => {
const url = 'https://countries.trevorblades.com/graphql';
const result = await post<{
data?: {
country: {
Expand All @@ -50,8 +42,8 @@ describe('post', () => {
};
};
errors?: Array<{ message: string }>;
}>(url, {
query: `query Query {
}>(URL, {
query: `query {
country(code: "MX") {
name
native
Expand Down

0 comments on commit 5f399d5

Please sign in to comment.