Skip to content

Commit

Permalink
feat(DTFS2-7052): refactor api tests to match TFS and solve type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
avaitonis committed Apr 11, 2024
1 parent c8cb1bc commit c91144d
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 280 deletions.
44 changes: 0 additions & 44 deletions test/api.ts

This file was deleted.

19 changes: 7 additions & 12 deletions test/app.api-test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
30 changes: 0 additions & 30 deletions test/createApp.ts

This file was deleted.

43 changes: 19 additions & 24 deletions test/currencies/currencies.api-test.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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([
Expand All @@ -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([
Expand All @@ -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,
Expand All @@ -170,8 +169,4 @@ describe('Currencies', () => {
});
});
});

afterAll(async () => {
await app.close();
});
});
Loading

0 comments on commit c91144d

Please sign in to comment.