Improved some tests

This commit is contained in:
Thom Werring 2024-03-26 20:00:34 +01:00
parent c33cc366d6
commit d7728f1ca4
4 changed files with 14 additions and 35 deletions

View File

@ -1,24 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});

View File

@ -1,9 +0,0 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}

View File

@ -17,7 +17,6 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config e2e-tests/jest-e2e.json",
"prepare": "husky install"
},
"dependencies": {
@ -77,7 +76,7 @@
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"coverageDirectory": "<rootDir>/coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"@/(.*)": "<rootDir>/src/$1",

View File

@ -17,11 +17,24 @@ describe('uuidTransformer util', () => {
expect(transformer.from(null)).toBe(NIL);
});
it('From method should throw an error if paring an invalid length buffer', () => {
expect(() => transformer.from(Buffer.alloc(15))).toThrow();
});
it('From method should return a nil uuid if empty 16 length buffer is passed', () => {
expect(transformer.from(Buffer.alloc(16))).toBe(NIL);
});
it('From and To methods should be each others inverse', () => {
const uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
expect(transformer.from(transformer.to(uuid))).toBe(uuid);
});
it('To method should return a buffer matching the uuid', () => {
expect(transformer.to(NIL)).toEqual(Buffer.alloc(16));
});
it('To method throw an error if passing a string that does not match a uuid', () => {
expect(() => transformer.to('test')).toThrow();
});
});