From c91144daa23e806764e5cd80382d1726d4380339 Mon Sep 17 00:00:00 2001 From: Audrius Vaitonis Date: Thu, 11 Apr 2024 15:21:50 +0100 Subject: [PATCH] feat(DTFS2-7052): refactor api tests to match TFS and solve type issues --- test/api.ts | 44 --------------- test/app.api-test.ts | 19 +++---- test/createApp.ts | 30 ---------- test/currencies/currencies.api-test.ts | 43 +++++++------- .../exposure-period.api-test.ts | 49 ++++++++-------- .../interest-rates/interest-rates.api-test.ts | 19 +++---- test/markets/markets.api-test.ts | 56 +++++++++---------- test/numbers/numbers.api-test.ts | 55 +++++++++--------- .../premium-schedules.api-test.ts | 47 +++++++--------- .../sector-industries.api-test.ts | 33 +++++------ test/support/api.ts | 4 ++ test/yield-rates/yield-rates.api-test.ts | 47 +++++++--------- 12 files changed, 166 insertions(+), 280 deletions(-) delete mode 100644 test/api.ts delete mode 100644 test/createApp.ts diff --git a/test/api.ts b/test/api.ts deleted file mode 100644 index 68d549d9..00000000 --- a/test/api.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { INestApplication } from '@nestjs/common'; -import request from 'supertest'; - -export class Api { - app: INestApplication; - - public constructor(app: INestApplication) { - this.app = app; - } - - get(url: string) { - return request(this.app).get(url); - } - - post(data: string | object) { - return { to: (url: string) => request(this.app).post(url).send(data) }; - } - - postEach(list: any) { - return { - to: async (url: string) => { - const results = []; - - for (const data of list) { - const result = await request(this.app).post(url).send(data); - - results.push(result); - } - - return results; - }, - }; - } - - put(data: string | object) { - return { to: (url: string) => request(this.app).put(url).send(data) }; - } - - remove(data: string | object) { - return { - to: (url: string) => request(this.app).delete(url).send(data), - }; - } -} diff --git a/test/app.api-test.ts b/test/app.api-test.ts index 6acfd80b..0853661c 100644 --- a/test/app.api-test.ts +++ b/test/app.api-test.ts @@ -1,24 +1,19 @@ -import { INestApplication } from '@nestjs/common'; - -import { Api } from './api'; -import { CreateApp } from './createApp'; +import { Api } from '@ukef-test/support/api'; describe('AppController (e2e)', () => { - let app: INestApplication; let api; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /ready`, async () => { - const { status } = await api.get('/ready'); + const { status } = await api.get('/api/v1/ready'); expect(status).toBe(200); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/createApp.ts b/test/createApp.ts deleted file mode 100644 index aee3bcee..00000000 --- a/test/createApp.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ValidationPipe } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; - -import { MainModule } from '../src/main.module'; - -export class CreateApp { - // NestJs app initialisation happens in /src/main.ts, here is some duplication of same process. - // TODO: maybe it is possible to reuse initialisation in /src/main.ts as similar approach is done in DTFS projects. - async init() { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [MainModule], - }).compile(); - - const app = moduleFixture.createNestApplication(); - - // Validation pipeline is require to check validations. - app.useGlobalPipes( - new ValidationPipe({ - whitelist: true, - transform: true, - forbidNonWhitelisted: true, - transformOptions: { - enableImplicitConversion: true, - }, - }), - ); - await app.init(); - return app; - } -} diff --git a/test/currencies/currencies.api-test.ts b/test/currencies/currencies.api-test.ts index 595d9d51..3e6fdf9e 100644 --- a/test/currencies/currencies.api-test.ts +++ b/test/currencies/currencies.api-test.ts @@ -1,10 +1,6 @@ -import { INestApplication } from '@nestjs/common'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Currencies', () => { - let app: INestApplication; let api: Api; const expectedResult = expect.arrayContaining([ @@ -25,31 +21,34 @@ describe('Currencies', () => { ]); beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); describe('/currencies/exchange', () => { it('should return 200 on GET `/currencies/exchange?source=GBP&target=AED&exchangeRateDate=2021-01-26`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=GBP&target=AED&exchangeRateDate=2021-01-26'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=GBP&target=AED&exchangeRateDate=2021-01-26'); expect(status).toBe(200); expect(body).toEqual(expectedResult); }); it('should return 200 on GET `/currencies/exchange?source=GBP&target=AED`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=GBP&target=AED'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=GBP&target=AED'); expect(status).toBe(200); expect(body).toEqual(expectedResult); }); it('should return 200 on GET `currencies/exchange?source=USD&target=GBP`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=USD&target=GBP'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=USD&target=GBP'); expect(status).toBe(200); expect(body).toEqual(expectedResult); }); it('should return 404 on GET `/currencies/exchange?source=AED&target=GBP`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=AED&target=GBP'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=AED&target=GBP'); expect(status).toBe(404); expect(body).toEqual({ statusCode: 404, @@ -59,7 +58,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange?source=GBP&target=abc`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=GBP&target=abc'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=GBP&target=abc'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -69,7 +68,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange?source=abc&target=AED`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=abc&target=AED'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=abc&target=AED'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -79,7 +78,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange?source=abc&target=def`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=abc&target=def'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=abc&target=def'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -89,7 +88,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange`', async () => { - const { status, body } = await api.get('/currencies/exchange'); + const { status, body } = await api.get('/api/v1/currencies/exchange'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -99,7 +98,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange?source=GBP`', async () => { - const { status, body } = await api.get('/currencies/exchange?source=GBP'); + const { status, body } = await api.get('/api/v1/currencies/exchange?source=GBP'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -109,7 +108,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/exchange?target=GBP`', async () => { - const { status, body } = await api.get('/currencies/exchange?target=GBP'); + const { status, body } = await api.get('/api/v1/currencies/exchange?target=GBP'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -121,7 +120,7 @@ describe('Currencies', () => { describe('/currencies', () => { it('should return 200 on GET `/currencies`', async () => { - const { status, body } = await api.get('/currencies'); + const { status, body } = await api.get('/api/v1/currencies'); expect(status).toBe(200); expect(body).toEqual( expect.arrayContaining([ @@ -142,7 +141,7 @@ describe('Currencies', () => { describe('/currencies/{isoCode}', () => { it('should return 200 on GET `/currencies/GBP`', async () => { - const { status, body } = await api.get('/currencies/GBP'); + const { status, body } = await api.get('/api/v1/currencies/GBP'); expect(status).toBe(200); expect(body).toEqual( expect.arrayContaining([ @@ -161,7 +160,7 @@ describe('Currencies', () => { }); it('should return 400 on GET `/currencies/abc`', async () => { - const { status, body } = await api.get('/currencies/abc'); + const { status, body } = await api.get('/api/v1/currencies/abc'); expect(status).toBe(400); expect(body).toEqual({ statusCode: 400, @@ -170,8 +169,4 @@ describe('Currencies', () => { }); }); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/exposure-period/exposure-period.api-test.ts b/test/exposure-period/exposure-period.api-test.ts index 80095e8e..0781ea76 100644 --- a/test/exposure-period/exposure-period.api-test.ts +++ b/test/exposure-period/exposure-period.api-test.ts @@ -1,38 +1,37 @@ -import { INestApplication } from '@nestjs/common'; import { PRODUCTS } from '@ukef/constants'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Exposure period', () => { - let app: INestApplication; let api: Api; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.EW}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.EW}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.EW}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(12); }); it(`GET /exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.EW}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.EW}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.EW}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(13); }); it(`GET /exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.BS}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.BS}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-07-04&enddate=2018-07-04&productgroup=${PRODUCTS.BS}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(13); }); it(`GET /exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.BS}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.BS}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-07-04&enddate=2018-07-05&productgroup=${PRODUCTS.BS}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(13); }); @@ -50,42 +49,42 @@ describe('Exposure period', () => { // EW Start is EOM it(`GET /exposure-period?startdate=2017-03-31&enddate=2017-04-01&productgroup=${PRODUCTS.EW}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-31&enddate=2017-04-01&productgroup=${PRODUCTS.EW}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-31&enddate=2017-04-01&productgroup=${PRODUCTS.EW}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(1); }); // BS Start is EOM it(`GET /exposure-period?startdate=2017-03-31&enddate=2017-04-29&productgroup=${PRODUCTS.BS}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-31&enddate=2017-04-29&productgroup=${PRODUCTS.BS}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-31&enddate=2017-04-29&productgroup=${PRODUCTS.BS}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(1); }); // EW Start is EOM, end is EOM it(`GET /exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.EW}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.EW}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.EW}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(1); }); // BS Start is EOM, end is EOM, +1 for exposure it(`GET /exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.BS}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.BS}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-31&enddate=2017-04-30&productgroup=${PRODUCTS.BS}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(2); }); // EW Start DOM = End DOM it(`GET /exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.EW}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.EW}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.EW}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(1); }); // BS Start DOM = End DOM, +1 for exposure it(`GET /exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.BS}`, async () => { - const { status, body } = await api.get(`/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.BS}`); + const { status, body } = await api.get(`/api/v1/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=${PRODUCTS.BS}`); expect(status).toBe(200); expect(body.exposurePeriod).toBe(2); }); @@ -93,7 +92,7 @@ describe('Exposure period', () => { // Input error handling checks it('GET /exposure-period', async () => { - const { status, body } = await api.get(`/exposure-period`); + const { status, body } = await api.get(`/api/v1/exposure-period`); expect(status).toBe(400); expect(body.message).toContain('startdate must be a valid ISO 8601 date string'); expect(body.message).toContain('enddate must be a valid ISO 8601 date string'); @@ -102,7 +101,7 @@ describe('Exposure period', () => { }); it('Should fail Feb 29 and Feb 30 - GET /exposure-period?startdate=2017-02-29&enddate=2017-02-30&productgroup=test', async () => { - const { status, body } = await api.get('/exposure-period?startdate=2017-02-29&enddate=2017-02-30&productgroup=test'); + const { status, body } = await api.get('/api/v1/exposure-period?startdate=2017-02-29&enddate=2017-02-30&productgroup=test'); expect(status).toBe(400); expect(body.message).toContain('startdate must be a valid ISO 8601 date string'); expect(body.message).toContain('enddate must be a valid ISO 8601 date string'); @@ -110,7 +109,7 @@ describe('Exposure period', () => { }); it('GET /exposure-period?startdate=2017-01-32&enddate=2017-02-32&productgroup=test', async () => { - const { status, body } = await api.get('/exposure-period?startdate=2017-01-32&enddate=2017-02-32&productgroup=test'); + const { status, body } = await api.get('/api/v1/exposure-period?startdate=2017-01-32&enddate=2017-02-32&productgroup=test'); expect(status).toBe(400); expect(body.message).toContain('startdate must be a valid ISO 8601 date string'); expect(body.message).toContain('enddate must be a valid ISO 8601 date string'); @@ -118,7 +117,7 @@ describe('Exposure period', () => { }); it('GET /exposure-period?startdate=null&enddate=null&productgroup=null', async () => { - const { status, body } = await api.get('/exposure-period?startdate=null&enddate=null&productgroup=null'); + const { status, body } = await api.get('/api/v1/exposure-period?startdate=null&enddate=null&productgroup=null'); expect(status).toBe(400); expect(body.message).toContain('startdate must be a valid ISO 8601 date string'); expect(body.message).toContain('enddate must be a valid ISO 8601 date string'); @@ -126,7 +125,7 @@ describe('Exposure period', () => { }); it('GET /exposure-period?startdate=undefined&enddate=undefined&productgroup=undefined', async () => { - const { status, body } = await api.get('/exposure-period?startdate=undefined&enddate=undefined&productgroup=undefined'); + const { status, body } = await api.get('/api/v1/exposure-period?startdate=undefined&enddate=undefined&productgroup=undefined'); expect(status).toBe(400); expect(body.message).toContain('startdate must be a valid ISO 8601 date string'); expect(body.message).toContain('enddate must be a valid ISO 8601 date string'); @@ -134,12 +133,8 @@ describe('Exposure period', () => { }); it('GET /exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=new', async () => { - const { status, body } = await api.get('/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=new'); + const { status, body } = await api.get('/api/v1/exposure-period?startdate=2017-03-05&enddate=2017-04-05&productgroup=new'); expect(status).toBe(400); expect(body.message).toContain('productgroup must be one of the following values: EW, BS'); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/interest-rates/interest-rates.api-test.ts b/test/interest-rates/interest-rates.api-test.ts index 4831efde..2d63091d 100644 --- a/test/interest-rates/interest-rates.api-test.ts +++ b/test/interest-rates/interest-rates.api-test.ts @@ -1,19 +1,18 @@ -import { INestApplication } from '@nestjs/common'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Interest rates', () => { - let app: INestApplication; let api: Api; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /interest-rates`, async () => { - const { status, body } = await api.get('/interest-rates'); + const { status, body } = await api.get('/api/v1/interest-rates'); expect(status).toBe(200); expect(body).toEqual( @@ -35,8 +34,4 @@ describe('Interest rates', () => { ]), ); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/markets/markets.api-test.ts b/test/markets/markets.api-test.ts index 3a61a2dd..1443fb20 100644 --- a/test/markets/markets.api-test.ts +++ b/test/markets/markets.api-test.ts @@ -1,11 +1,8 @@ -import { INestApplication } from '@nestjs/common'; +import { Api } from '@ukef-test/support/api'; -import { Api } from '../api'; -import { CreateApp } from '../createApp'; import { TEST_CONSTANTS } from '../test-constants'; describe('Markets', () => { - let app: INestApplication; let api: Api; const marketSchema = { @@ -30,19 +27,22 @@ describe('Markets', () => { }; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /markets`, async () => { - const { status, body } = await api.get('/markets'); + const { status, body } = await api.get('/api/v1/markets'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(marketSchema)])); }); it(`GET /markets?active=Y`, async () => { - const { status, body } = await api.get('/markets?active=Y'); + const { status, body } = await api.get('/api/v1/markets?active=Y'); expect(status).toBe(200); expect(body).toEqual( @@ -56,7 +56,7 @@ describe('Markets', () => { }); it(`GET /markets?active=N`, async () => { - const { status, body } = await api.get('/markets?active=N'); + const { status, body } = await api.get('/api/v1/markets?active=N'); expect(status).toBe(200); expect(body).toEqual( @@ -70,15 +70,15 @@ describe('Markets', () => { }); it(`returns more results from GET /markets?active=Y than GET /markets?active=N`, async () => { - const responseActive = await api.get('/markets?active=Y'); - const responseDisabled = await api.get('/markets?active=N'); + const responseActive = await api.get('/api/v1/markets?active=Y'); + const responseDisabled = await api.get('/api/v1/markets?active=N'); // We expect more active markets than disabled expect(responseActive.body.length).toBeGreaterThan(responseDisabled.body.length); }); it(`GET /markets?active=something-else`, async () => { - const { status, body } = await api.get('/markets?active=something-else'); + const { status, body } = await api.get('/api/v1/markets?active=something-else'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -86,7 +86,7 @@ describe('Markets', () => { }); it(`GET /markets?active=`, async () => { - const { status, body } = await api.get('/markets?active='); + const { status, body } = await api.get('/api/v1/markets?active='); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -94,7 +94,7 @@ describe('Markets', () => { }); it(`GET /markets?active=null`, async () => { - const { status, body } = await api.get('/markets?active=null'); + const { status, body } = await api.get('/api/v1/markets?active=null'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -102,7 +102,7 @@ describe('Markets', () => { }); it(`GET /markets?active=undefined`, async () => { - const { status, body } = await api.get('/markets?active=undefined'); + const { status, body } = await api.get('/api/v1/markets?active=undefined'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -112,7 +112,7 @@ describe('Markets', () => { // Testing "search" query parameter it(`GET /markets?search=Aus`, async () => { - const { status, body } = await api.get('/markets?search=Aus'); + const { status, body } = await api.get('/api/v1/markets?search=Aus'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(marketSchema)])); @@ -120,7 +120,7 @@ describe('Markets', () => { }); it(`GET /markets?search=AUT`, async () => { - const { status, body } = await api.get('/markets?search=AUT'); + const { status, body } = await api.get('/api/v1/markets?search=AUT'); expect(status).toBe(200); @@ -130,8 +130,8 @@ describe('Markets', () => { }); it(`test that query param search is not case sensitive`, async () => { - const { status, body } = await api.get('/markets?search=Aus'); - const lowerCaseResponse = await api.get('/markets?search=aus'); + const { status, body } = await api.get('/api/v1/markets?search=Aus'); + const lowerCaseResponse = await api.get('/api/v1/markets?search=aus'); expect(status).toBe(200); expect(lowerCaseResponse.status).toBe(200); @@ -140,55 +140,51 @@ describe('Markets', () => { }); it(`GET /markets?active=Y&search=Aus`, async () => { - const { status, body } = await api.get('/markets?active=Y&search=Aus'); + const { status, body } = await api.get('/api/v1/markets?active=Y&search=Aus'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(marketSchema)])); }); it(`GET /markets?active=N&search=Aus`, async () => { - const { status, body } = await api.get('/markets?active=N&search=Aus'); + const { status, body } = await api.get('/api/v1/markets?active=N&search=Aus'); expect(status).toBe(200); expect(body).toEqual([]); }); it(`GET /markets?search=undefined`, async () => { - const { status, body } = await api.get('/markets?search=undefined'); + const { status, body } = await api.get('/api/v1/markets?search=undefined'); expect(status).toBe(200); expect(body).toEqual([]); }); it(`GET /markets?search=null`, async () => { - const { status, body } = await api.get('/markets?search=null'); + const { status, body } = await api.get('/api/v1/markets?search=null'); expect(status).toBe(200); expect(body).toEqual([]); }); it(`GET /markets?search=`, async () => { - const { status, body } = await api.get('/markets?search='); + const { status, body } = await api.get('/api/v1/markets?search='); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(marketSchema)])); }); it(`GET /markets?search=${TEST_CONSTANTS.SPECIAL_CHARACTERS}`, async () => { - const { status, body } = await api.get(`/markets?search=${TEST_CONSTANTS.SPECIAL_CHARACTERS}`); + const { status, body } = await api.get(`/api/v1/markets?search=${TEST_CONSTANTS.SPECIAL_CHARACTERS}`); expect(status).toBe(200); expect(body).toEqual([]); }); it(`GET /markets?search=%20%20%20`, async () => { - const { status, body } = await api.get('/markets?search=%20%20%20'); + const { status, body } = await api.get('/api/v1/markets?search=%20%20%20'); expect(status).toBe(200); expect(body).toEqual([]); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/numbers/numbers.api-test.ts b/test/numbers/numbers.api-test.ts index 25cb95e4..a0128a1b 100644 --- a/test/numbers/numbers.api-test.ts +++ b/test/numbers/numbers.api-test.ts @@ -1,19 +1,18 @@ -import { INestApplication } from '@nestjs/common'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Numbers', () => { - let app: INestApplication; let api: Api; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /numbers?type=1&ukefId=0010581069`, async () => { - const { status, body } = await api.get('/numbers?type=1&ukefId=0010581069'); + const { status, body } = await api.get('/api/v1/numbers?type=1&ukefId=0010581069'); expect(status).toBe(404); expect(body.error).toMatch('Not Found'); @@ -31,25 +30,25 @@ describe('Numbers', () => { }, ]; // Generate - const postResponse = await api.post(postNumbersPayload).to('/numbers'); + const postResponse = await api.post('/api/v1/numbers', postNumbersPayload); expect(postResponse.status).toBe(201); // Test - const getResponse = await api.get('/numbers?type=' + postResponse.body[0].type + '&ukefId=' + postResponse.body[0].maskedId); + const getResponse = await api.get('/api/v1/numbers?type=' + postResponse.body[0].type + '&ukefId=' + postResponse.body[0].maskedId); expect(getResponse.status).toBe(200); expect(postResponse.body[0]).toEqual(getResponse.body); }); it(`GET /numbers?type=2&ukefId=0030581069`, async () => { - const { status } = await api.get('/numbers?type=2&ukefId=0030581069'); + const { status } = await api.get('/api/v1/numbers?type=2&ukefId=0030581069'); expect(status).toBe(404); }); it(`GET /numbers?type=a&ukefId=a`, async () => { - const { status, body } = await api.get('/numbers?type=a&ukefId=a'); + const { status, body } = await api.get('/api/v1/numbers?type=a&ukefId=a'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -58,7 +57,7 @@ describe('Numbers', () => { }); it(`GET /numbers?type=null&ukefId=null`, async () => { - const { status, body } = await api.get('/numbers?type=null&ukefId=null'); + const { status, body } = await api.get('/api/v1/numbers?type=null&ukefId=null'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -67,7 +66,7 @@ describe('Numbers', () => { }); it(`GET /numbers?type=undefined&ukefId=undefined`, async () => { - const { status, body } = await api.get('/numbers?type=undefined&ukefId=undefined'); + const { status, body } = await api.get('/api/v1/numbers?type=undefined&ukefId=undefined'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -76,7 +75,7 @@ describe('Numbers', () => { }); it(`GET /numbers?type=a&ukefId=0030581069`, async () => { - const { status, body } = await api.get('/numbers?type=a&ukefId=0030581069'); + const { status, body } = await api.get('/api/v1/numbers?type=a&ukefId=0030581069'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -84,7 +83,7 @@ describe('Numbers', () => { }); it(`GET /numbers?type=3&ukefId=0030581069`, async () => { - const { status, body } = await api.get('/numbers?type=3&ukefId=0030581069'); + const { status, body } = await api.get('/api/v1/numbers?type=3&ukefId=0030581069'); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -99,7 +98,7 @@ describe('Numbers', () => { requestingSystem: 'Jest 1 - Deal', }, ]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(201); expect(body).toHaveLength(1); @@ -119,7 +118,7 @@ describe('Numbers', () => { requestingSystem: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mau', }, ]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(201); expect(body).toHaveLength(1); @@ -139,7 +138,7 @@ describe('Numbers', () => { requestingSystem: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ac magna ipsum', }, ]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -149,7 +148,7 @@ describe('Numbers', () => { it(`POST /numbers single, missing fields`, async () => { const payload = [{}]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -160,7 +159,7 @@ describe('Numbers', () => { it(`POST /numbers single, empty payload`, async () => { const payload = ''; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -169,7 +168,7 @@ describe('Numbers', () => { it(`POST /numbers single, empty array`, async () => { const payload = []; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -178,7 +177,7 @@ describe('Numbers', () => { it(`POST /numbers single, not parsable array`, async () => { const payload = '[]'; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -187,7 +186,7 @@ describe('Numbers', () => { it(`POST /numbers single, bad json`, async () => { const payload = 'asd'; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -217,7 +216,7 @@ describe('Numbers', () => { requestingSystem: 'Jest 4 - Covenant', }, ]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(201); expect(body).toHaveLength(4); @@ -295,7 +294,7 @@ describe('Numbers', () => { requestingSystem: 'Jest 4 - Party', }, ]; - const { status, body } = await api.post(payload).to('/numbers'); + const { status, body } = await api.post('/api/v1/numbers', payload); expect(status).toBe(201); expect(body).toHaveLength(payload.length); @@ -314,8 +313,4 @@ describe('Numbers', () => { return previousValues; }, Object.create(null)); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/premium-schedules/premium-schedules.api-test.ts b/test/premium-schedules/premium-schedules.api-test.ts index a9b75486..d259c96b 100644 --- a/test/premium-schedules/premium-schedules.api-test.ts +++ b/test/premium-schedules/premium-schedules.api-test.ts @@ -1,14 +1,10 @@ -import { INestApplication } from '@nestjs/common'; import { PRODUCTS } from '@ukef/constants'; +import { Api } from '@ukef-test/support/api'; import Chance from 'chance'; -import { Api } from '../api'; -import { CreateApp } from '../createApp'; - const chance = new Chance(); describe('Premium schedules', () => { - let app: INestApplication; let api: Api; const premiumScheduleSchema = { @@ -28,12 +24,15 @@ describe('Premium schedules', () => { }; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it('GET /premium/segments/12345678', async () => { - const { status, body } = await api.get('/premium/segments/12345678'); + const { status, body } = await api.get('/api/v1/premium/segments/12345678'); // Not generated yet. expect(status).toBe(404); @@ -60,7 +59,7 @@ describe('Premium schedules', () => { maximumLiability: 40000, }, ]; - const postResponse = await api.post(createSchedules).to('/premium/schedule'); + const postResponse = await api.post('/api/v1/premium/schedule', createSchedules); expect(postResponse.status).toBe(201); expect(postResponse.body).toHaveLength(1); @@ -85,12 +84,12 @@ describe('Premium schedules', () => { }, ]; // Generate - const postResponse = await api.post(createSchedules).to('/premium/schedule'); + const postResponse = await api.post('/api/v1/premium/schedule', createSchedules); expect(postResponse.status).toBe(201); // Test - const getResponse = await api.get('/premium/segments/' + postResponse.body[0].facilityURN); + const getResponse = await api.get('/api/v1/premium/segments/' + postResponse.body[0].facilityURN); expect(getResponse.status).toBe(200); expect(getResponse.body).toHaveLength(16); @@ -116,7 +115,7 @@ describe('Premium schedules', () => { maximumLiability: 40000, }, ]; - const postResponse = await api.post(createSchedules).to('/premium/schedule'); + const postResponse = await api.post('/api/v1/premium/schedule', createSchedules); expect(postResponse.status).toBe(201); expect(postResponse.body).toHaveLength(1); @@ -140,7 +139,7 @@ describe('Premium schedules', () => { maximumLiability: 40000, }, ]; - const postResponse = await api.post(createSchedules).to('/premium/schedule'); + const postResponse = await api.post('/api/v1/premium/schedule', createSchedules); expect(postResponse.status).toBe(201); expect(postResponse.body).toHaveLength(1); @@ -164,7 +163,7 @@ describe('Premium schedules', () => { maximumLiability: 40000, }, ]; - const postResponse = await api.post(createSchedules).to('/premium/schedule'); + const postResponse = await api.post('/api/v1/premium/schedule', createSchedules); expect(postResponse.status).toBe(201); expect(postResponse.body).toHaveLength(1); @@ -188,7 +187,7 @@ describe('Premium schedules', () => { maximumLiability: 40000, }, ]; - const { status, body } = await api.post(createSchedules).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', createSchedules); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -213,7 +212,7 @@ describe('Premium schedules', () => { }, ]; - const { status, body } = await api.post(createSchedules).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', createSchedules); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -223,20 +222,20 @@ describe('Premium schedules', () => { }); it('GET /premium/segments/null', async () => { - const { status, body } = await api.get('/premium/segments/null'); + const { status, body } = await api.get('/api/v1/premium/segments/null'); expect(status).toBe(400); expect(body.message).toContain('facilityId must match /^\\d{8,10}$/ regular expression'); }); it('GET /premium/segments/undefined', async () => { - const { status, body } = await api.get('/premium/segments/undefined'); + const { status, body } = await api.get('/api/v1/premium/segments/undefined'); expect(status).toBe(400); expect(body.message).toContain('facilityId must match /^\\d{8,10}$/ regular expression'); }); it('POST /premium/schedule, empty array', async () => { const payload = []; - const { status, body } = await api.post(payload).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -245,7 +244,7 @@ describe('Premium schedules', () => { it('POST /premium/schedule, not parsable array', async () => { const payload = '[]'; - const { status, body } = await api.post(payload).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -254,7 +253,7 @@ describe('Premium schedules', () => { it('POST /premium/schedule, bad json', async () => { const payload = 'asd'; - const { status, body } = await api.post(payload).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -263,7 +262,7 @@ describe('Premium schedules', () => { it('POST /premium/schedule, field validation', async () => { const payload = [{}]; - const { status, body } = await api.post(payload).to('/premium/schedule'); + const { status, body } = await api.post('/api/v1/premium/schedule', payload); expect(status).toBe(400); expect(body.error).toMatch('Bad Request'); @@ -291,8 +290,4 @@ describe('Premium schedules', () => { expect(body.message).toContain('maximumLiability should not be empty'); expect(body.message).toContain('maximumLiability must be a number conforming to the specified constraints'); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/sector-industries/sector-industries.api-test.ts b/test/sector-industries/sector-industries.api-test.ts index d9b62091..bedf4145 100644 --- a/test/sector-industries/sector-industries.api-test.ts +++ b/test/sector-industries/sector-industries.api-test.ts @@ -1,10 +1,6 @@ -import { INestApplication } from '@nestjs/common'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Sector industries', () => { - let app: INestApplication; let api: Api; const sectorIndustriesSchema = { @@ -25,63 +21,62 @@ describe('Sector industries', () => { }; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); it(`GET /sector-industries`, async () => { - const { status, body } = await api.get('/sector-industries'); + const { status, body } = await api.get('/api/v1/sector-industries'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(sectorIndustriesSchema)])); }); it(`GET /sector-industries?ukefSectorId=1001`, async () => { - const { status, body } = await api.get('/sector-industries?ukefSectorId=1001'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefSectorId=1001'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(sectorIndustriesSchema)])); expect(body.length).toBeGreaterThan(1); }); it(`GET /sector-industries?ukefIndustryId=01120`, async () => { - const { status, body } = await api.get('/sector-industries?ukefIndustryId=01120'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefIndustryId=01120'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(sectorIndustriesSchema)])); expect(body).toHaveLength(1); }); it(`GET /sector-industries?ukefSectorId=1001&ukefIndustryId=01120`, async () => { - const { status, body } = await api.get('/sector-industries?ukefSectorId=1001&ukefIndustryId=01120'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefSectorId=1001&ukefIndustryId=01120'); expect(status).toBe(200); expect(body).toHaveLength(1); }); it(`GET /sector-industries?ukefSectorId=1234`, async () => { - const { status } = await api.get('/sector-industries?ukefSectorId=1234'); + const { status } = await api.get('/api/v1/sector-industries?ukefSectorId=1234'); expect(status).toBe(404); }); it(`GET /sector-industries?ukefSectorId=a&ukefIndustryId=a`, async () => { - const { status, body } = await api.get('/sector-industries?ukefSectorId=a&ukefIndustryId=a'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefSectorId=a&ukefIndustryId=a'); expect(status).toBe(400); expect(body.message).toContain('ukefSectorId must match /^\\d{4}$/ regular expression'); expect(body.message).toContain('ukefIndustryId must match /^\\d{5}$/ regular expression'); }); it(`GET /sector-industries?ukefSectorId=null&ukefIndustryId=null`, async () => { - const { status, body } = await api.get('/sector-industries?ukefSectorId=null&ukefIndustryId=null'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefSectorId=null&ukefIndustryId=null'); expect(status).toBe(400); expect(body.message).toContain('ukefSectorId must match /^\\d{4}$/ regular expression'); expect(body.message).toContain('ukefIndustryId must match /^\\d{5}$/ regular expression'); }); it(`GET /sector-industries?ukefSectorId=undefined&ukefIndustryId=undefined`, async () => { - const { status, body } = await api.get('/sector-industries?ukefSectorId=undefined&ukefIndustryId=undefined'); + const { status, body } = await api.get('/api/v1/sector-industries?ukefSectorId=undefined&ukefIndustryId=undefined'); expect(status).toBe(400); expect(body.message).toContain('ukefSectorId must match /^\\d{4}$/ regular expression'); expect(body.message).toContain('ukefIndustryId must match /^\\d{5}$/ regular expression'); }); - - afterAll(async () => { - await app.close(); - }); }); diff --git a/test/support/api.ts b/test/support/api.ts index dc03f634..f86625d2 100644 --- a/test/support/api.ts +++ b/test/support/api.ts @@ -16,6 +16,10 @@ export class Api { return this.request().get(url).set(this.getValidAuthHeader()); } + post(url: string, body: string | object): request.Test { + return this.request().post(url).send(body).set(this.getValidAuthHeader()); + } + getWithoutAuth(url: string, strategy?: string, key?: string): request.Test { const query = this.request().get(url); return this.setQueryWithAuthStrategyIfPresent(query, strategy, key); diff --git a/test/yield-rates/yield-rates.api-test.ts b/test/yield-rates/yield-rates.api-test.ts index 0386c8db..756dbfe8 100644 --- a/test/yield-rates/yield-rates.api-test.ts +++ b/test/yield-rates/yield-rates.api-test.ts @@ -1,16 +1,15 @@ -import { INestApplication } from '@nestjs/common'; import { DATE } from '@ukef/constants'; - -import { Api } from '../api'; -import { CreateApp } from '../createApp'; +import { Api } from '@ukef-test/support/api'; describe('Interest rates', () => { - let app: INestApplication; - let api: Api; + let api; beforeAll(async () => { - app = await new CreateApp().init(); - api = new Api(app.getHttpServer()); + api = await Api.create(); + }); + + afterAll(async () => { + await api.destroy(); }); const yieldRateSchema = { @@ -31,13 +30,13 @@ describe('Interest rates', () => { }; it(`GET /yield-rates`, async () => { - const { status, body } = await api.get('/yield-rates'); + const { status, body } = await api.get('/api/v1/yield-rates'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining({ ...yieldRateSchema, effectiveTo: DATE.MAXIMUM_TIMEZONE_LIMIT })])); }); it(`GET /yield-rates?searchDate=2023-03-02`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=2023-03-02'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=2023-03-02'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining(yieldRateSchema)])); @@ -47,78 +46,74 @@ describe('Interest rates', () => { // UKEF at the moment has yield rates since 2010-03-15, maybe some old data will be retired in future. it(`returns 404 for any date past 2010-03-15 where the yield data does not exist`, async () => { - const { status } = await api.get('/yield-rates?searchDate=2010-03-14'); + const { status } = await api.get('/api/v1/yield-rates?searchDate=2010-03-14'); expect(status).toBe(404); }); // Current yield rates have effective date till 9999-12-31, so 9999-12-30 is max date with results. it(`GET /yield-rates?searchDate=9999-12-30`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=9999-12-30'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=9999-12-30'); expect(status).toBe(200); expect(body).toEqual(expect.arrayContaining([expect.objectContaining({ ...yieldRateSchema, effectiveTo: DATE.MAXIMUM_TIMEZONE_LIMIT })])); }); // Current yield rates have effective date till 9999-12-31, so no rates for this max date. it(`returns 404 for GET /yield-rates?searchDate=9999-12-31`, async () => { - const { status } = await api.get('/yield-rates?searchDate=9999-12-31'); + const { status } = await api.get('/api/v1/yield-rates?searchDate=9999-12-31'); expect(status).toBe(404); }); it(`returns 400 for GET /yield-rates?searchDate=2023-03-02T16:29:04.027Z`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=2023-03-02T16:29:04.027Z'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=2023-03-02T16:29:04.027Z'); expect(status).toBe(400); expect(body.message).toContain('searchDate should use format YYYY-MM-DD'); }); it(`returns 400 for GET /yield-rates?searchDate=null`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=null'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=null'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=undefined`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=undefined'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=undefined'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=ABC`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=ABC'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=ABC'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=123`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=123'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=123'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=!"£!"£`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=!"£!"£'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=!"£!"£'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=A%20£`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=A%20£'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=A%20£'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=++`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=++'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=++'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); it(`returns 400 for GET /yield-rates?searchDate=0000-00-00`, async () => { - const { status, body } = await api.get('/yield-rates?searchDate=0000-00-00'); + const { status, body } = await api.get('/api/v1/yield-rates?searchDate=0000-00-00'); expect(status).toBe(400); expect(body.message).toContain('searchDate must be a valid ISO 8601 date string'); }); - - afterAll(async () => { - await app.close(); - }); });