diff --git a/src/modules/geography/geography.mapper.ts b/src/modules/geography/route.mapper.ts similarity index 100% rename from src/modules/geography/geography.mapper.ts rename to src/modules/geography/route.mapper.ts diff --git a/src/modules/geography/tests/unit/route.mapper.spec.ts b/src/modules/geography/tests/unit/route.mapper.spec.ts new file mode 100644 index 0000000..8c27c2d --- /dev/null +++ b/src/modules/geography/tests/unit/route.mapper.spec.ts @@ -0,0 +1,58 @@ +import { RouteEntity } from '@modules/geography/core/domain/route.entity'; +import { RouteMapper } from '@modules/geography/route.mapper'; +import { Test } from '@nestjs/testing'; + +describe('Route Mapper', () => { + let routeMapper: RouteMapper; + + beforeAll(async () => { + const module = await Test.createTestingModule({ + providers: [RouteMapper], + }).compile(); + routeMapper = module.get(RouteMapper); + }); + + it('should be defined', () => { + expect(routeMapper).toBeDefined(); + }); + + it('should map domain entity to persistence data', async () => { + expect(routeMapper.toPersistence()).toBeUndefined(); + }); + + it('should map persisted data to domain entity', async () => { + expect(routeMapper.toDomain()).toBeUndefined(); + }); + + it('should map domain entity to response', async () => { + const now = new Date(); + const routeEntity: RouteEntity = new RouteEntity({ + id: '047a6ecf-23d4-4d3e-877c-3225d560a8da', + createdAt: now, + updatedAt: now, + props: { + driverDistance: 23000, + driverDuration: 900, + passengerDistance: 23000, + passengerDuration: 900, + fwdAzimuth: 283, + backAzimuth: 93, + distanceAzimuth: 19840, + spacetimePoints: [], + waypoints: [ + { + position: 0, + lon: 6.1765103, + lat: 48.689446, + }, + { + position: 1, + lon: 2.3523, + lat: 48.8567, + }, + ], + }, + }); + expect(routeMapper.toResponse(routeEntity).driverDistance).toBe(23000); + }); +});