Skip to content

Commit

Permalink
fix(templates): mock config.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
harm-meijer committed Sep 16, 2024
1 parent a532cdd commit f20a9d1
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -36,6 +41,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(eventController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
readConfiguration.mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -20,6 +25,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(jobController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
readConfiguration.mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -36,6 +41,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(serviceController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
readConfiguration.mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
6 changes: 6 additions & 0 deletions application-templates/typescript/event/tests/event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -36,6 +41,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(enventController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
(readConfiguration as jest.Mock).mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
6 changes: 6 additions & 0 deletions application-templates/typescript/job/tests/routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -20,6 +25,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(jobController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
(readConfiguration as jest.Mock).mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const readConfiguration = jest.fn(() => ({
clientId: 'mockedClientId',
clientSecret: 'mockedClientSecret',
projectKey: 'mockedProjectKey',
scope: 'mockedScope',
region: 'mockedRegion',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -36,6 +41,7 @@ describe('unexpected error', () => {
postMock = jest.spyOn(serviceController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
(readConfiguration as jest.Mock).mockClear();
});

afterEach(() => {
Expand Down

0 comments on commit f20a9d1

Please sign in to comment.