mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Try to expose bug #106
It does not work as we have PERMISSIONS=disabled also in the server we're trying to test.
This commit is contained in:
parent
9262fbb44f
commit
0893d3740e
@ -1,8 +1,7 @@
|
||||
import { request } from 'graphql-request'
|
||||
import { create, cleanDatabase } from './seed/factories'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
let getHost = () => 'http://127.0.0.1:3123'
|
||||
import { host } from './jest/helpers'
|
||||
|
||||
describe('login', () => {
|
||||
const mutation = (params) => {
|
||||
@ -30,7 +29,7 @@ describe('login', () => {
|
||||
describe('asking for a `token`', () => {
|
||||
describe('with valid email/password combination', () => {
|
||||
it('responds with a JWT token', async () => {
|
||||
const data = await request(getHost(), mutation({ email: 'test@example.org', password: '1234' }))
|
||||
const data = await request(host, mutation({ email: 'test@example.org', password: '1234' }))
|
||||
const { token } = data.login
|
||||
jwt.verify(token, process.env.JWT_SECRET, (err, data) => {
|
||||
expect(data.email).toEqual('test@example.org')
|
||||
@ -42,7 +41,7 @@ describe('login', () => {
|
||||
describe('with a valid email but incorrect password', () => {
|
||||
it('responds with "Incorrect email address or password."', async () => {
|
||||
try {
|
||||
await request(getHost(), mutation({ email: 'test@example.org', password: 'wrong' }))
|
||||
await request(host, mutation({ email: 'test@example.org', password: 'wrong' }))
|
||||
} catch (error) {
|
||||
expect(error.response.errors[0].message).toEqual('Incorrect email address or password.')
|
||||
}
|
||||
@ -52,7 +51,7 @@ describe('login', () => {
|
||||
describe('with a non-existing email', () => {
|
||||
it('responds with "Incorrect email address or password."', async () => {
|
||||
try {
|
||||
await request(getHost(), mutation({ email: 'non-existent@example.org', password: 'wrong' }))
|
||||
await request(host, mutation({ email: 'non-existent@example.org', password: 'wrong' }))
|
||||
} catch (error) {
|
||||
expect(error.response.errors[0].message).toEqual('Incorrect email address or password.')
|
||||
}
|
||||
|
||||
15
src/jest/helpers.js
Normal file
15
src/jest/helpers.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { request } from 'graphql-request'
|
||||
|
||||
export const host = 'http://127.0.0.1:3123'
|
||||
|
||||
export async function login ({ email, password }) {
|
||||
const mutation = `
|
||||
mutation {
|
||||
login(email:"${email}", password:"${password}"){
|
||||
token
|
||||
}
|
||||
}`
|
||||
const data = await request(host, mutation)
|
||||
const { token } = data.login
|
||||
return token
|
||||
}
|
||||
@ -1,31 +1,50 @@
|
||||
import { request } from 'graphql-request'
|
||||
import createServer from '../server'
|
||||
import mocks from '../mocks'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { create, cleanDatabase } from '../seed/factories'
|
||||
import generateJwt from '../jwt/generateToken'
|
||||
import { host, login } from '../jest/helpers'
|
||||
|
||||
describe('authorization', () => {
|
||||
describe('given an existing user', () => {
|
||||
|
||||
describe('logged in', () => {
|
||||
let jwt
|
||||
beforeEach(() => {
|
||||
// jwt = generateJwt(user)
|
||||
describe('given two existing users', () => {
|
||||
beforeEach(async () => {
|
||||
await create('user', {
|
||||
email: 'test@example.org',
|
||||
password: '1234'
|
||||
})
|
||||
await create('user', {
|
||||
email: 'someone@example.org',
|
||||
password: 'hello'
|
||||
})
|
||||
})
|
||||
|
||||
describe('query own user profile', () => {
|
||||
const mutation = (params) => {
|
||||
const { email, password } = params
|
||||
afterEach(async () => {
|
||||
await cleanDatabase()
|
||||
})
|
||||
|
||||
describe('logged in', () => {
|
||||
let jwt, graphQLClient
|
||||
|
||||
beforeEach(async () => {
|
||||
jwt = await login({ email: 'test@example.org', password: '1234' })
|
||||
graphQLClient = new GraphQLClient(host, {
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('query email', () => {
|
||||
const query = (params) => {
|
||||
const { email } = params
|
||||
return `{
|
||||
User(email: "${email}") {
|
||||
name
|
||||
email
|
||||
}
|
||||
}`
|
||||
}
|
||||
|
||||
it('returns the owner\'s email address', async () => {
|
||||
// const data = await request(getHost(), mutation({ email: 'test@example.org' }))
|
||||
console.log('it runs')
|
||||
it('exposes the owner\'s email address', async () => {
|
||||
const data = await graphQLClient.request(query({ email: 'test@example.org' }))
|
||||
console.log(process.env)
|
||||
expect(data).toEqual({ User: [ { email: 'test@example.org' } ] })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -29,12 +29,12 @@ const buildMutation = (model, parameters) => {
|
||||
return builders[model](parameters)
|
||||
}
|
||||
|
||||
const create = async (model, parameters) => {
|
||||
await client.mutate({ mutation: gql(buildMutation(model, parameters)) })
|
||||
const create = (model, parameters) => {
|
||||
return client.mutate({ mutation: gql(buildMutation(model, parameters)) })
|
||||
}
|
||||
|
||||
const cleanDatabase = async () => {
|
||||
await query('MATCH (n) DETACH DELETE n', session)
|
||||
const cleanDatabase = () => {
|
||||
return query('MATCH (n) DETACH DELETE n', session)
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user