mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Getting strange non-deterministic errors
This commit is contained in:
parent
6bbc76911a
commit
d0b975e782
@ -25,7 +25,9 @@
|
||||
"license": "MIT",
|
||||
"jest": {
|
||||
"verbose": true,
|
||||
"testMatch": ["**/src/**/?(*.)+(spec|test).js?(x)" ],
|
||||
"testMatch": [
|
||||
"**/src/**/?(*.)+(spec|test).js?(x)"
|
||||
],
|
||||
"globalSetup": "<rootDir>/src/jest/globalSetup",
|
||||
"globalTeardown": "<rootDir>/src/jest/globalTeardown"
|
||||
},
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { request } from 'graphql-request'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import fetch from 'node-fetch'
|
||||
|
||||
export const host = 'http://127.0.0.1:3123'
|
||||
|
||||
export async function getJWT({ email, password }) {
|
||||
export async function authenticatedHeaders ({ email, password }) {
|
||||
const mutation = `
|
||||
mutation {
|
||||
login(email:"${email}", password:"${password}"){
|
||||
@ -12,16 +12,27 @@ export async function getJWT({ email, password }) {
|
||||
}`
|
||||
const response = await request(host, mutation)
|
||||
const { token } = response.login
|
||||
if(!token) throw `Could not get a JWT token from the backend:\n${response}`
|
||||
return token
|
||||
if (!token) throw new Error(`Could not get a JWT token from the backend:\n${response}`)
|
||||
return {
|
||||
authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
export async function authenticatedGraphQLClient(params){
|
||||
const jwt = await getJWT(params)
|
||||
const options = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${jwt}`
|
||||
}
|
||||
export async function queryServer ({ headers, query, variables }) {
|
||||
const defaultHeaders = {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
return new GraphQLClient(host, options)
|
||||
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,5 @@
|
||||
import { create, cleanDatabase } from '../seed/factories'
|
||||
import { authenticatedGraphQLClient } from '../jest/helpers'
|
||||
import { authenticatedHeaders, queryServer } from '../jest/helpers'
|
||||
|
||||
describe('authorization', () => {
|
||||
describe('given two existing users', () => {
|
||||
@ -19,25 +19,27 @@ describe('authorization', () => {
|
||||
})
|
||||
|
||||
describe('logged in', () => {
|
||||
let graphQLClient
|
||||
let headers = {}
|
||||
|
||||
beforeEach(async () => {
|
||||
graphQLClient = await authenticatedGraphQLClient({ email: 'test@example.org', password: '1234' })
|
||||
// headers = authenticatedHeaders({
|
||||
// email: 'test@example.org',
|
||||
// password: '1234'
|
||||
// })
|
||||
})
|
||||
|
||||
describe('query email', () => {
|
||||
const query = (params) => {
|
||||
const { email } = params
|
||||
return `{
|
||||
User(email: "${email}") {
|
||||
describe('query email', async () => {
|
||||
it('exposes the owner\'s email address', async () => {
|
||||
const options = {
|
||||
headers,
|
||||
query: `{
|
||||
User(email: "test@example.org") {
|
||||
email
|
||||
}
|
||||
}`
|
||||
}
|
||||
|
||||
it('exposes the owner\'s email address', async () => {
|
||||
const data = await graphQLClient.request(query({ email: 'test@example.org' }))
|
||||
expect(data).toEqual({ User: [ { email: 'test@example.org' } ] })
|
||||
}
|
||||
const json = await queryServer(options)
|
||||
expect(json).toEqual({ User: [ { email: 'test@example.org' } ] })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -4,7 +4,6 @@ import dotenv from 'dotenv'
|
||||
import { HttpLink } from 'apollo-link-http'
|
||||
import { InMemoryCache } from 'apollo-cache-inmemory'
|
||||
import neo4j from '../../bootstrap/neo4j'
|
||||
import { query } from '../../graphql-schema'
|
||||
import fetch from 'node-fetch'
|
||||
|
||||
dotenv.config()
|
||||
@ -19,7 +18,6 @@ const client = new ApolloClient({
|
||||
})
|
||||
|
||||
const driver = neo4j().getDriver()
|
||||
const session = driver.session()
|
||||
|
||||
const builders = {
|
||||
'user': require('./users.js').default
|
||||
@ -34,7 +32,16 @@ const create = (model, parameters) => {
|
||||
}
|
||||
|
||||
const cleanDatabase = () => {
|
||||
return query('MATCH (n) DETACH DELETE n', session)
|
||||
const session = driver.session()
|
||||
const cypher = 'MATCH (n) DETACH DELETE n'
|
||||
return session
|
||||
.run(cypher)
|
||||
.then(function (result) {
|
||||
session.close()
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@ -5420,7 +5420,7 @@ node-fetch@2.1.2:
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
|
||||
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
|
||||
|
||||
node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@~2.3.0:
|
||||
node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
|
||||
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user