From f20a9d1b74acc90cd810850b7300c29971b85034 Mon Sep 17 00:00:00 2001 From: Harm Meijer Date: Mon, 16 Sep 2024 16:02:19 +0200 Subject: [PATCH] fix(templates): mock config.utils --- .../javascript/event/src/utils/__mocks__/config.utils.js | 7 +++++++ .../javascript/event/tests/integration/routes.spec.js | 6 ++++++ .../javascript/job/src/utils/__mocks__/config.utils.js | 7 +++++++ .../javascript/job/tests/integration/orders.spec.js | 6 ++++++ .../javascript/service/src/utils/__mocks__/config.utils.js | 7 +++++++ .../javascript/service/tests/integration/routes.spec.js | 6 ++++++ .../typescript/event/src/utils/__mocks__/config.utils.ts | 7 +++++++ application-templates/typescript/event/tests/event.spec.ts | 6 ++++++ .../typescript/job/src/utils/__mocks__/config.utils.ts | 7 +++++++ application-templates/typescript/job/tests/routes.spec.ts | 6 ++++++ .../typescript/service/src/utils/__mocks__/config.utils.ts | 7 +++++++ .../typescript/service/tests/service.spec.ts | 6 ++++++ 12 files changed, 78 insertions(+) create mode 100644 application-templates/javascript/event/src/utils/__mocks__/config.utils.js create mode 100644 application-templates/javascript/job/src/utils/__mocks__/config.utils.js create mode 100644 application-templates/javascript/service/src/utils/__mocks__/config.utils.js create mode 100644 application-templates/typescript/event/src/utils/__mocks__/config.utils.ts create mode 100644 application-templates/typescript/job/src/utils/__mocks__/config.utils.ts create mode 100644 application-templates/typescript/service/src/utils/__mocks__/config.utils.ts diff --git a/application-templates/javascript/event/src/utils/__mocks__/config.utils.js b/application-templates/javascript/event/src/utils/__mocks__/config.utils.js new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/javascript/event/src/utils/__mocks__/config.utils.js @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/javascript/event/tests/integration/routes.spec.js b/application-templates/javascript/event/tests/integration/routes.spec.js index 06ab3c4..a772b1d 100644 --- a/application-templates/javascript/event/tests/integration/routes.spec.js +++ b/application-templates/javascript/event/tests/integration/routes.spec.js @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../../src/app'; import * as eventController from '../../src/controllers/event.controller'; +import { readConfiguration } from '../../src/utils/config.utils'; +jest.mock('../../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + readConfiguration.mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -36,6 +41,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(eventController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + readConfiguration.mockClear(); }); afterEach(() => { diff --git a/application-templates/javascript/job/src/utils/__mocks__/config.utils.js b/application-templates/javascript/job/src/utils/__mocks__/config.utils.js new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/javascript/job/src/utils/__mocks__/config.utils.js @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/javascript/job/tests/integration/orders.spec.js b/application-templates/javascript/job/tests/integration/orders.spec.js index 7f552f9..24b5b67 100644 --- a/application-templates/javascript/job/tests/integration/orders.spec.js +++ b/application-templates/javascript/job/tests/integration/orders.spec.js @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../../src/app'; import * as jobController from '../../src/controllers/job.controller'; +import { readConfiguration } from '../../src/utils/config.utils'; +jest.mock('../../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + readConfiguration.mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -20,6 +25,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(jobController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + readConfiguration.mockClear(); }); afterEach(() => { diff --git a/application-templates/javascript/service/src/utils/__mocks__/config.utils.js b/application-templates/javascript/service/src/utils/__mocks__/config.utils.js new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/javascript/service/src/utils/__mocks__/config.utils.js @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/javascript/service/tests/integration/routes.spec.js b/application-templates/javascript/service/tests/integration/routes.spec.js index 0e8ab4d..6c01c88 100644 --- a/application-templates/javascript/service/tests/integration/routes.spec.js +++ b/application-templates/javascript/service/tests/integration/routes.spec.js @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../../src/app'; import * as serviceController from '../../src/controllers/service.controller'; +import { readConfiguration } from '../../src/utils/config.utils'; +jest.mock('../../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + readConfiguration.mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -36,6 +41,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(serviceController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + readConfiguration.mockClear(); }); afterEach(() => { diff --git a/application-templates/typescript/event/src/utils/__mocks__/config.utils.ts b/application-templates/typescript/event/src/utils/__mocks__/config.utils.ts new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/typescript/event/src/utils/__mocks__/config.utils.ts @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/typescript/event/tests/event.spec.ts b/application-templates/typescript/event/tests/event.spec.ts index f16396f..5b467f9 100644 --- a/application-templates/typescript/event/tests/event.spec.ts +++ b/application-templates/typescript/event/tests/event.spec.ts @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../src/app'; import * as enventController from '../src/controllers/event.controller'; +import { readConfiguration } from '../src/utils/config.utils'; +jest.mock('../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + (readConfiguration as jest.Mock).mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -36,6 +41,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(enventController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + (readConfiguration as jest.Mock).mockClear(); }); afterEach(() => { diff --git a/application-templates/typescript/job/src/utils/__mocks__/config.utils.ts b/application-templates/typescript/job/src/utils/__mocks__/config.utils.ts new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/typescript/job/src/utils/__mocks__/config.utils.ts @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/typescript/job/tests/routes.spec.ts b/application-templates/typescript/job/tests/routes.spec.ts index 22f33e9..7f45e18 100644 --- a/application-templates/typescript/job/tests/routes.spec.ts +++ b/application-templates/typescript/job/tests/routes.spec.ts @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../src/app'; import * as jobController from '../src/controllers/job.controller'; +import { readConfiguration } from '../src/utils/config.utils'; +jest.mock('../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + (readConfiguration as jest.Mock).mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -20,6 +25,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(jobController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + (readConfiguration as jest.Mock).mockClear(); }); afterEach(() => { diff --git a/application-templates/typescript/service/src/utils/__mocks__/config.utils.ts b/application-templates/typescript/service/src/utils/__mocks__/config.utils.ts new file mode 100644 index 0000000..8f59d2f --- /dev/null +++ b/application-templates/typescript/service/src/utils/__mocks__/config.utils.ts @@ -0,0 +1,7 @@ +export const readConfiguration = jest.fn(() => ({ + clientId: 'mockedClientId', + clientSecret: 'mockedClientSecret', + projectKey: 'mockedProjectKey', + scope: 'mockedScope', + region: 'mockedRegion', +})); diff --git a/application-templates/typescript/service/tests/service.spec.ts b/application-templates/typescript/service/tests/service.spec.ts index 6157328..f0e128b 100644 --- a/application-templates/typescript/service/tests/service.spec.ts +++ b/application-templates/typescript/service/tests/service.spec.ts @@ -2,8 +2,13 @@ import { expect } from '@jest/globals'; import request from 'supertest'; import app from '../src/app'; import * as serviceController from '../src/controllers/service.controller'; +import { readConfiguration } from '../src/utils/config.utils'; +jest.mock('../src/utils/config.utils'); describe('Testing router', () => { + beforeEach(() => { + (readConfiguration as jest.Mock).mockClear(); + }); test('Post to non existing route', async () => { const response = await request(app).post('/none'); expect(response.status).toBe(404); @@ -36,6 +41,7 @@ describe('unexpected error', () => { postMock = jest.spyOn(serviceController, 'post').mockImplementation(() => { throw new Error('Test error'); }); + (readConfiguration as jest.Mock).mockClear(); }); afterEach(() => {