mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Clean up helper.js
This commit is contained in:
parent
6f487e2687
commit
9d541d8f27
@ -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
|
||||
}
|
||||
|
||||
@ -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 () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user