admin.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { ApolloServer } from 'apollo-server-express'
  2. import { Mongoose } from 'mongoose'
  3. import { Aggregates } from '../src/types'
  4. import { createMutationFn, createQueryFn, MutationFn, QueryFn } from './helpers'
  5. import { buildAggregates, connectMongoose, createServer } from '../src/server'
  6. import { GetKillSwitch, GET_KILL_SWITCH, SetKillSwitch, SET_KILL_SWITCH, SetKillSwitchArgs } from './queries/admin'
  7. import { AdminModel } from '../src/models/Admin'
  8. describe('Kill switch resolver', () => {
  9. let server: ApolloServer
  10. let mongoose: Mongoose
  11. let aggregates: Aggregates
  12. let query: QueryFn
  13. let mutate: MutationFn
  14. beforeEach(async () => {
  15. mongoose = await connectMongoose(process.env.MONGO_URL!)
  16. aggregates = await buildAggregates()
  17. server = await createServer(mongoose, aggregates, process.env.ORION_QUERY_NODE_URL!)
  18. await server.start()
  19. query = createQueryFn(server)
  20. mutate = createMutationFn(server)
  21. })
  22. afterEach(async () => {
  23. await server.stop()
  24. await AdminModel.deleteMany({})
  25. await mongoose.disconnect()
  26. })
  27. const getKillSwitch = async () => {
  28. const result = await query<GetKillSwitch>({
  29. query: GET_KILL_SWITCH,
  30. })
  31. expect(result.errors).toBeUndefined()
  32. return result.data?.admin.isKilled
  33. }
  34. it('should return isKilled set to false', async () => {
  35. const isKilled = await getKillSwitch()
  36. expect(isKilled).toEqual(false)
  37. })
  38. it('should set isKilled to true', async () => {
  39. await mutate<SetKillSwitch, SetKillSwitchArgs>({ mutation: SET_KILL_SWITCH, variables: { isKilled: true } })
  40. const isKilled = await getKillSwitch()
  41. expect(isKilled).toEqual(true)
  42. })
  43. })