Skip to content

Commit

Permalink
test: Add a test for preview env key
Browse files Browse the repository at this point in the history
  • Loading branch information
flacial committed Sep 26, 2022
1 parent 2e1990f commit bd435cd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions __tests__/pages/api/graphql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ session.mockImplementation(() => {
})

describe('Graphql Api', () => {
const OLD_ENV = process.env
let apolloServerInput

beforeEach(() => {
process.env = { ...OLD_ENV, VERCEL_ENV: 'preview' }

nextConnect.mockImplementation(() => {
return {
use: returnHandler,
Expand All @@ -42,6 +46,10 @@ describe('Graphql Api', () => {
}
})

afterEach(() => {
process.env = OLD_ENV
})

test('Should have correct config object', async () => {
const { config } = require('../../../pages/api/graphql.ts')
expect(config).toEqual({
Expand All @@ -51,6 +59,13 @@ describe('Graphql Api', () => {
})
})

test('Should have correct config object when deployed as a preview deployment', async () => {
require('../../../pages/api/graphql.ts')
expect(
apolloServerInput.playground && apolloServerInput.introspection
).toBeTruthy()
})

test('Should call context', () => {
const contextInput = { req: {} }
require('../../../pages/api/graphql.ts')
Expand Down

0 comments on commit bd435cd

Please sign in to comment.