Moved tests
This commit is contained in:
parent
af9ab1a483
commit
afebfc9150
|
|
@ -7,7 +7,7 @@
|
|||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"e2e-tests/**/*.ts\"",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"e2e-tests/**/*.ts\" \"tests/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
|
|
@ -67,7 +67,9 @@
|
|||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"rootDir": ".",
|
||||
"roots": ["<rootDir>/tests"],
|
||||
"testPathIgnorePatterns": ["./database"],
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
|
|
@ -78,7 +80,8 @@
|
|||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node",
|
||||
"moduleNameMapper": {
|
||||
"@/(.*)": "<rootDir>/$1"
|
||||
"@/(.*)": "<rootDir>/src/$1",
|
||||
"@tests/(.*)": "<rootDir>/tests/$1"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
describe('AppController', () => {});
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
let service: NotificationsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NotificationsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<NotificationsService>(NotificationsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||
import { ShipmentEntity } from '@/entities/shipment.entity';
|
||||
import * as uuid from 'uuid';
|
||||
import { ContainerEntity } from '@/entities/container.entity';
|
||||
|
||||
export const mockTrackingInfo: TrackingDto = {
|
||||
carrierName: 'Evergreen',
|
||||
destinationUnLoCode: 'NLAMS',
|
||||
departureDate: new Date('2023-05-14T11:00:00.000Z'),
|
||||
arrivalDateEstimate: new Date('2023-02-14T15:00:00.000Z'),
|
||||
containerNumber: 'AAAA000000000',
|
||||
};
|
||||
|
||||
export const mockShipment: ShipmentEntity = {
|
||||
id: uuid.NIL,
|
||||
createdAt: new Date('2023-05-01T11:00:00.000Z'),
|
||||
carrierName: 'Evergreen',
|
||||
originPort: 'NLAMS',
|
||||
destinationPort: 'NLAMS',
|
||||
departureDate: new Date('2023-05-14T11:00:00.000Z'),
|
||||
arrivalDateOriginal: new Date('2023-02-14T15:00:00.000Z'),
|
||||
arrivalDateEstimate: new Date('2023-02-14T15:00:00.000Z'),
|
||||
};
|
||||
|
||||
export const mockContainerEntity: ContainerEntity = {
|
||||
id: uuid.NIL,
|
||||
shipmentId: uuid.NIL,
|
||||
containerNumber: 'AAAA000000000',
|
||||
shipment: mockShipment,
|
||||
};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NotificationsService } from '@/tracking/notifications.service';
|
||||
import { mockShipment, mockTrackingInfo } from '@tests/data/tracking.mock';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
let service: NotificationsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NotificationsService],
|
||||
})
|
||||
.useMocker((token) => {
|
||||
switch (token) {
|
||||
case 'NOTIFIER_FACTORY':
|
||||
return () => ({
|
||||
send: jest.fn().mockResolvedValue(true),
|
||||
});
|
||||
}
|
||||
})
|
||||
.compile();
|
||||
|
||||
service = module.get<NotificationsService>(NotificationsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
it('should have a method send that resolves', async () => {
|
||||
await expect(
|
||||
service.send(mockShipment, mockTrackingInfo),
|
||||
).resolves.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TrackingController } from './tracking.controller';
|
||||
import { TrackingService } from '@/tracking/tracking.service';
|
||||
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||
import { TrackingController } from '@/tracking/tracking.controller';
|
||||
|
||||
describe('TrackingController', () => {
|
||||
let trackingInfo: TrackingDto;
|
||||
|
|
@ -1,40 +1,17 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TrackingService } from './tracking.service';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ContainerEntity } from '@/entities/container.entity';
|
||||
import { ShipmentsService } from '@/shipments/shipments.service';
|
||||
import { NotificationsService } from '@/tracking/notifications.service';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import * as uuid from 'uuid';
|
||||
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||
import { ShipmentEntity } from '@/entities/shipment.entity';
|
||||
import { TrackingService } from '@/tracking/tracking.service';
|
||||
import {
|
||||
mockContainerEntity,
|
||||
mockShipment,
|
||||
mockTrackingInfo,
|
||||
} from '@tests/data/tracking.mock';
|
||||
|
||||
describe('TrackingService', () => {
|
||||
const mockTrackingInfo: TrackingDto = {
|
||||
carrierName: 'Evergreen',
|
||||
destinationUnLoCode: 'NLAMS',
|
||||
departureDate: new Date('2023-05-14T11:00:00.000Z'),
|
||||
arrivalDateEstimate: new Date('2023-02-14T15:00:00.000Z'),
|
||||
containerNumber: 'AAAA000000000',
|
||||
};
|
||||
|
||||
const mockShipment: ShipmentEntity = {
|
||||
id: uuid.NIL,
|
||||
createdAt: new Date('2023-05-01T11:00:00.000Z'),
|
||||
carrierName: 'Evergreen',
|
||||
originPort: 'NLAMS',
|
||||
destinationPort: 'NLAMS',
|
||||
departureDate: new Date('2023-05-14T11:00:00.000Z'),
|
||||
arrivalDateOriginal: new Date('2023-02-14T15:00:00.000Z'),
|
||||
arrivalDateEstimate: new Date('2023-02-14T15:00:00.000Z'),
|
||||
};
|
||||
|
||||
const mockContainerEntity: ContainerEntity = {
|
||||
id: uuid.NIL,
|
||||
shipmentId: uuid.NIL,
|
||||
containerNumber: 'AAAA000000000',
|
||||
shipment: mockShipment,
|
||||
};
|
||||
|
||||
const containerEntityToken = getRepositoryToken(ContainerEntity);
|
||||
let trackingService: TrackingService;
|
||||
let shipmentsService: ShipmentsService;
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"lib": [ "es2022"],
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./src",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
|
|
@ -22,10 +22,13 @@
|
|||
"noUncheckedIndexedAccess": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./*"
|
||||
"./src/*"
|
||||
],
|
||||
"@tests/*": [
|
||||
"./tests/*"
|
||||
],
|
||||
"@": [
|
||||
"./main.ts"
|
||||
"./src/main.ts"
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue