From 5f399d5873721eea8f99ff1320bec5986eab65aa Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Mon, 29 Apr 2024 08:37:10 -0700 Subject: [PATCH] Update @acusti/post tests to rely on a single API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit halve our dependencies on external resources (2 → 1) --- packages/post/src/index.test.ts | 38 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/packages/post/src/index.test.ts b/packages/post/src/index.test.ts index 03b14651..9ad11b51 100644 --- a/packages/post/src/index.test.ts +++ b/packages/post/src/index.test.ts @@ -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 }>; }; 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: { @@ -50,8 +42,8 @@ describe('post', () => { }; }; errors?: Array<{ message: string }>; - }>(url, { - query: `query Query { + }>(URL, { + query: `query { country(code: "MX") { name native