mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Export a function in server.js and test teardown
This commit is contained in:
parent
6b216be05c
commit
ec9c205bee
@ -1,5 +1,20 @@
|
|||||||
import { request } from 'graphql-request'
|
import { request } from 'graphql-request'
|
||||||
import server from './server'
|
import createServer from './server'
|
||||||
|
|
||||||
|
let getHost
|
||||||
|
let app
|
||||||
|
let port
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const server = createServer()
|
||||||
|
app = await server.start({ port: 0 })
|
||||||
|
port = app.address().port
|
||||||
|
getHost = () => `http://127.0.0.1:${port}`
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await app.close()
|
||||||
|
})
|
||||||
|
|
||||||
describe('login', () => {
|
describe('login', () => {
|
||||||
describe('asking for a `token`', () => {
|
describe('asking for a `token`', () => {
|
||||||
@ -15,14 +30,6 @@ describe('login', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('with a non-existing email', () => {
|
describe('with a non-existing email', () => {
|
||||||
let getHost
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const app = await server.start({ port: 0 })
|
|
||||||
const { port } = app.address()
|
|
||||||
getHost = () => `http://127.0.0.1:${port}`
|
|
||||||
})
|
|
||||||
|
|
||||||
const mutation = `
|
const mutation = `
|
||||||
mutation {
|
mutation {
|
||||||
login(email:"user@example.com", password:"asdfasd"){
|
login(email:"user@example.com", password:"asdfasd"){
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import server from './server'
|
import createServer from './server'
|
||||||
|
|
||||||
const serverConfig = {
|
const serverConfig = {
|
||||||
port: process.env.GRAPHQL_PORT || 4000
|
port: process.env.GRAPHQL_PORT || 4000
|
||||||
@ -8,6 +8,7 @@ const serverConfig = {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const server = createServer()
|
||||||
server.start(serverConfig, options => {
|
server.start(serverConfig, options => {
|
||||||
/* eslint-disable-next-line no-console */
|
/* eslint-disable-next-line no-console */
|
||||||
console.log(`Server ready at ${process.env.GRAPHQL_URI} 🚀`)
|
console.log(`Server ready at ${process.env.GRAPHQL_URI} 🚀`)
|
||||||
|
|||||||
@ -22,10 +22,6 @@ let schema = makeExecutableSchema({
|
|||||||
|
|
||||||
const driver = neo4j().getDriver()
|
const driver = neo4j().getDriver()
|
||||||
|
|
||||||
const MOCK = (process.env.MOCK === 'true')
|
|
||||||
/* eslint-disable-next-line no-console */
|
|
||||||
console.log('MOCK:', MOCK)
|
|
||||||
|
|
||||||
schema = augmentSchema(schema, {
|
schema = augmentSchema(schema, {
|
||||||
query: {
|
query: {
|
||||||
exclude: ['Statistics', 'LoggedInUser']
|
exclude: ['Statistics', 'LoggedInUser']
|
||||||
@ -36,7 +32,8 @@ schema = augmentSchema(schema, {
|
|||||||
})
|
})
|
||||||
schema = applyScalars(applyDirectives(schema))
|
schema = applyScalars(applyDirectives(schema))
|
||||||
|
|
||||||
const server = new GraphQLServer({
|
const createServer = (options) => {
|
||||||
|
const defaults = {
|
||||||
context: async (req) => {
|
context: async (req) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
driver,
|
driver,
|
||||||
@ -55,12 +52,15 @@ const server = new GraphQLServer({
|
|||||||
schema: schema,
|
schema: schema,
|
||||||
tracing: true,
|
tracing: true,
|
||||||
middlewares: middleware(schema),
|
middlewares: middleware(schema),
|
||||||
mocks: MOCK ? mocks : false
|
mocks: (process.env.MOCK === 'true') ? mocks : false
|
||||||
})
|
}
|
||||||
|
const server = new GraphQLServer(Object.assign({}, defaults, options))
|
||||||
|
|
||||||
passport.use('jwt', jwtStrategy())
|
passport.use('jwt', jwtStrategy())
|
||||||
server.express.use(passport.initialize())
|
server.express.use(passport.initialize())
|
||||||
|
|
||||||
server.express.post('/graphql', passport.authenticate(['jwt'], { session: false }))
|
server.express.post('/graphql', passport.authenticate(['jwt'], { session: false }))
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
export default server
|
export default createServer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user