diff --git a/src/jest/helpers.js b/src/jest/helpers.js index 06cfc0e0b..cd66a9d04 100644 --- a/src/jest/helpers.js +++ b/src/jest/helpers.js @@ -11,28 +11,7 @@ export async function authenticatedHeaders ({ email, password }) { } }` const response = await request(host, mutation) - const { token } = response.login - if (!token) throw new Error(`Could not get a JWT token from the backend:\n${response}`) return { - authorization: `Bearer ${token}` + authorization: `Bearer ${response.login.token}` } } - -export async function queryServer ({ headers, query, variables }) { - const defaultHeaders = { - Accept: 'application/json', - 'Content-Type': 'application/json' - } - const response = await fetch(host, { - method: 'POST', - authenticatedHeaders, - headers: Object.assign({}, defaultHeaders, headers), - body: JSON.stringify({ - operationName: null, - query, - variables - }) - }) - const json = await response.json() - return json.data -} diff --git a/src/middleware/permissionsMiddleware.spec.js b/src/middleware/permissionsMiddleware.spec.js index 3ea3f9e55..50f6ebadd 100644 --- a/src/middleware/permissionsMiddleware.spec.js +++ b/src/middleware/permissionsMiddleware.spec.js @@ -1,5 +1,6 @@ import { create, cleanDatabase } from '../seed/factories' -import { authenticatedHeaders, queryServer } from '../jest/helpers' +import { host, authenticatedHeaders, queryServer } from '../jest/helpers' +import { GraphQLClient } from 'graphql-request' describe('authorization', () => { describe('given two existing users', () => { @@ -21,15 +22,12 @@ describe('authorization', () => { describe('access email address', () => { let headers = {} const action = async (headers) => { - const options = { - headers, - query: `{ - User(email: "owner@example.org") { - email - } - }` - } - return await queryServer(options) + const graphQLClient = new GraphQLClient(host, { headers }) + return await graphQLClient.request(`{ + User(email: "owner@example.org") { + email + } + }`) } describe('not logged in', async () => {