Moved tests
This commit is contained in:
parent
af9ab1a483
commit
afebfc9150
|
|
@ -7,7 +7,7 @@
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nest build",
|
"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": "nest start",
|
||||||
"start:dev": "nest start --watch",
|
"start:dev": "nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
|
|
@ -67,7 +67,9 @@
|
||||||
"json",
|
"json",
|
||||||
"ts"
|
"ts"
|
||||||
],
|
],
|
||||||
"rootDir": "src",
|
"rootDir": ".",
|
||||||
|
"roots": ["<rootDir>/tests"],
|
||||||
|
"testPathIgnorePatterns": ["./database"],
|
||||||
"testRegex": ".*\\.spec\\.ts$",
|
"testRegex": ".*\\.spec\\.ts$",
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
|
@ -78,7 +80,8 @@
|
||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"@/(.*)": "<rootDir>/$1"
|
"@/(.*)": "<rootDir>/src/$1",
|
||||||
|
"@tests/(.*)": "<rootDir>/tests/$1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"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 { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { TrackingController } from './tracking.controller';
|
|
||||||
import { TrackingService } from '@/tracking/tracking.service';
|
import { TrackingService } from '@/tracking/tracking.service';
|
||||||
import { TrackingDto } from '@/dtos/tracking.dto';
|
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||||
|
import { TrackingController } from '@/tracking/tracking.controller';
|
||||||
|
|
||||||
describe('TrackingController', () => {
|
describe('TrackingController', () => {
|
||||||
let trackingInfo: TrackingDto;
|
let trackingInfo: TrackingDto;
|
||||||
|
|
@ -1,40 +1,17 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { TrackingService } from './tracking.service';
|
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { ContainerEntity } from '@/entities/container.entity';
|
import { ContainerEntity } from '@/entities/container.entity';
|
||||||
import { ShipmentsService } from '@/shipments/shipments.service';
|
import { ShipmentsService } from '@/shipments/shipments.service';
|
||||||
import { NotificationsService } from '@/tracking/notifications.service';
|
import { NotificationsService } from '@/tracking/notifications.service';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
import * as uuid from 'uuid';
|
import { TrackingService } from '@/tracking/tracking.service';
|
||||||
import { TrackingDto } from '@/dtos/tracking.dto';
|
import {
|
||||||
import { ShipmentEntity } from '@/entities/shipment.entity';
|
mockContainerEntity,
|
||||||
|
mockShipment,
|
||||||
|
mockTrackingInfo,
|
||||||
|
} from '@tests/data/tracking.mock';
|
||||||
|
|
||||||
describe('TrackingService', () => {
|
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);
|
const containerEntityToken = getRepositoryToken(ContainerEntity);
|
||||||
let trackingService: TrackingService;
|
let trackingService: TrackingService;
|
||||||
let shipmentsService: ShipmentsService;
|
let shipmentsService: ShipmentsService;
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
"lib": [ "es2022"],
|
"lib": [ "es2022"],
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"baseUrl": "./src",
|
"baseUrl": "./",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
|
|
@ -22,10 +22,13 @@
|
||||||
"noUncheckedIndexedAccess": true,
|
"noUncheckedIndexedAccess": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": [
|
"@/*": [
|
||||||
"./*"
|
"./src/*"
|
||||||
|
],
|
||||||
|
"@tests/*": [
|
||||||
|
"./tests/*"
|
||||||
],
|
],
|
||||||
"@": [
|
"@": [
|
||||||
"./main.ts"
|
"./src/main.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue