Skip to content

Commit

Permalink
separate mock from app (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
csaltmountain authored Sep 17, 2024
1 parent 2f8cdbc commit bb537fe
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 23 deletions.
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ALL_SCHEMA_ON=true

# Mock server
PORT_MOCK=4100
ENABLE_MOCK_SERVER=true

# Turn on all fields for local development
MOCK_SERVER_COLLECTION=all #options: all, rural-payments-portal, release-1
Expand Down
10 changes: 0 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { apolloServer } from './graphql/server.js'
import { server } from './server.js'
import { logger } from './utils/logger.js'

let mockServer
if (process.env.ENABLE_MOCK_SERVER) {
mockServer = await import('../mocks/server.js')
}

const init = async () => {
await apolloServer.start()

Expand All @@ -24,11 +19,6 @@ const init = async () => {

await server.start()
logger.info(`Server running on ${server.info.uri}`)

if (process.env.ENABLE_MOCK_SERVER && mockServer) {
const url = await mockServer.default.start()
logger.info(`Mock server running ${url}`)
}
}

process.on('unhandledRejection', err => {
Expand Down
6 changes: 0 additions & 6 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
"cobertura",
"lcov"
],
"setupFiles": [
"<rootDir>/test/test-setup.js"
],
"setupFilesAfterEnv": [
"<rootDir>/jest.init.js"
],
"reporters": [
"default",
[
Expand Down
2 changes: 0 additions & 2 deletions mocks/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const release1Routes = [
'rural-payments-organisation-get-by-sbi:default',
'rural-payments-organisation-get-people-by-org-id:default',

'rural-payments-organisation-get-person-summary-by-person-id:default',

'rural-payments-lms-get-covers-summary:default',
'rural-payments-lms-get-land-covers:default',
'rural-payments-lms-get-parcels:default',
Expand Down
3 changes: 2 additions & 1 deletion mocks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import server from './server.js'

server.start()
const url = await server.start()
console.log(`Mock server running ${url}`)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fcp-data-access-layer-api",
"version": "1.3.9",
"version": "1.3.10",
"description": "Customer Registry GraphQL Service",
"homepage": "https://github.com/DEFRA/fcp-data-access-layer-api",
"main": "app/index.js",
Expand All @@ -15,6 +15,7 @@
"start:debug": "nodemon --inspect-brk=0.0.0.0 --ext js --legacy-watch app/index.js",
"start:dev": "nodemon -r dotenv/config --ext js,gql app/index.js",
"start:watch": "nodemon --inspect=0.0.0.0 --ext js --legacy-watch app/index.js",
"start:mock": "nodemon ./mocks --watch ./mocks",
"test": "NODE_OPTIONS=--experimental-vm-modules DOTENV_CONFIG_PATH=./.env.test jest --runInBand --detectOpenHandles --setupFiles dotenv/config",
"test:contract": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=test/contract --setupFiles dotenv/config",
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=test/integration --setupFiles dotenv/config",
Expand Down
4 changes: 4 additions & 0 deletions test/integration/graphql/business-applications.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { graphql } from 'graphql/index.js'
import { schema } from '../../../app/graphql/server.js'
import { fakeContext } from '../../test-setup.js'
import mockServer from '../../../mocks/server'

beforeAll(mockServer.start)
afterAll(mockServer.stop)

describe('Query business.applications', () => {
it('should return application data', async () => {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/graphql/business.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ import {
transformOrganisationToBusiness
} from '../../../app/transformers/rural-payments/business.js'
import { NotFound } from '../../../app/errors/graphql.js'
import mockServer from '../../../mocks/server'

const organisationFixture = organisationByOrgId('5565448')._data
const { totalArea, totalParcels } = parcelSummary('5565448')
const organisationCPHInfoFixture = organisationCPHInfo('5565448').data
const organisationCPHFixture = organisationCPH('5565448').data

beforeAll(mockServer.start)
afterAll(mockServer.stop)

describe('Query.business', () => {
it('should return business data', async () => {
const transformedOrganisation =
Expand Down
3 changes: 3 additions & 0 deletions test/integration/graphql/customer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { fakeContext } from '../../test-setup.js'

const personFixture = personById({ id: '5007136' })

beforeAll(mockServer.start)
afterAll(mockServer.stop)

describe('Query.customer', () => {
it('should return customer data', async () => {
const customerInfo = ruralPaymentsPortalCustomerTransformer(
Expand Down
4 changes: 4 additions & 0 deletions test/integration/graphql/permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { graphql } from 'graphql'

import { schema } from '../../../app/graphql/server.js'
import { fakeContext } from '../../test-setup.js'
import mockServer from '../../../mocks/server'

beforeAll(mockServer.start)
afterAll(mockServer.stop)

describe('Query.permissionGroups', () => {
it('should return permissions', async () => {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/graphql/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
getIntrospectionQuery,
graphql
} from 'graphql'
import mockServer from '../../../mocks/server'

beforeAll(mockServer.start)
afterAll(mockServer.stop)

describe('schema', () => {
beforeEach(() => {
Expand Down

0 comments on commit bb537fe

Please sign in to comment.