Added final tests
This commit is contained in:
parent
73db243099
commit
f1ac705204
|
|
@ -10,7 +10,6 @@ export class ShipmentsService {
|
||||||
private readonly shipmentRepository: Repository<ShipmentEntity>,
|
private readonly shipmentRepository: Repository<ShipmentEntity>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// @todo add pagination
|
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.shipmentRepository.find({
|
return this.shipmentRepository.find({
|
||||||
relations: ['liveTracking', 'containers'],
|
relations: ['liveTracking', 'containers'],
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,59 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { ShipmentsService } from '@/shipments/shipments.service';
|
import { ShipmentsService } from '@/shipments/shipments.service';
|
||||||
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
|
import { ShipmentEntity } from '@/entities/shipment.entity';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { mockShipment } from '@tests/data/tracking.mock';
|
||||||
|
|
||||||
describe('ShipmentsService', () => {
|
describe('ShipmentsService', () => {
|
||||||
|
const shipmentEntityToken = getRepositoryToken(ShipmentEntity);
|
||||||
let service: ShipmentsService;
|
let service: ShipmentsService;
|
||||||
|
let repository: Repository<ShipmentEntity>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [ShipmentsService],
|
providers: [ShipmentsService],
|
||||||
}).compile();
|
})
|
||||||
|
.useMocker((token) => {
|
||||||
|
switch (token) {
|
||||||
|
case shipmentEntityToken:
|
||||||
|
return {
|
||||||
|
find: jest.fn().mockResolvedValue([]),
|
||||||
|
save: jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation((shipmentEntity: ShipmentEntity) =>
|
||||||
|
Promise.resolve(shipmentEntity),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.compile();
|
||||||
|
|
||||||
service = module.get<ShipmentsService>(ShipmentsService);
|
service = module.get<ShipmentsService>(ShipmentsService);
|
||||||
|
repository = module.get<Repository<ShipmentEntity>>(shipmentEntityToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a getAll method', () => {
|
||||||
|
expect(service.getAll).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch data with relations liveTracking and containers', async () => {
|
||||||
|
await expect(service.getAll()).resolves.toEqual([]);
|
||||||
|
expect(repository.find).toHaveBeenCalledWith({
|
||||||
|
relations: ['liveTracking', 'containers'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have an update method', () => {
|
||||||
|
expect(service.update).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch data with relations liveTracking and containers', async () => {
|
||||||
|
await expect(service.update(mockShipment)).resolves.toEqual(mockShipment);
|
||||||
|
expect(repository.save).toHaveBeenCalledWith(mockShipment);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue