postgres direction encoder tests

This commit is contained in:
sbriat 2023-08-22 11:38:14 +02:00
parent c45e5c94e5
commit 14d2486c1b
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import { Coordinates } from '@modules/geography/core/application/types/coordinates.type';
import { PostgresDirectionEncoder } from '@modules/geography/infrastructure/postgres-direction-encoder';
describe('Postgres direction encoder', () => {
it('should be defined', () => {
const postgresDirectionEncoder: PostgresDirectionEncoder =
new PostgresDirectionEncoder();
expect(postgresDirectionEncoder).toBeDefined();
});
it('should encode coordinates to a postgres direction', () => {
const postgresDirectionEncoder: PostgresDirectionEncoder =
new PostgresDirectionEncoder();
const coordinates: Coordinates[] = [
{
lon: 6,
lat: 47,
},
{
lon: 6.1,
lat: 47.1,
},
{
lon: 6.2,
lat: 47.2,
},
];
const direction = postgresDirectionEncoder.encode(coordinates);
expect(direction).toBe("'LINESTRING(6 47,6.1 47.1,6.2 47.2)'");
});
it('should decode a postgres direction to coordinates', () => {
const postgresDirectionEncoder: PostgresDirectionEncoder =
new PostgresDirectionEncoder();
const direction = "'LINESTRING(6 47,6.1 47.1,6.2 47.2)'";
const coordinates: Coordinates[] =
postgresDirectionEncoder.decode(direction);
expect(coordinates.length).toBe(3);
expect(coordinates[0].lat).toBe(47);
expect(coordinates[1].lon).toBe(6.1);
expect(coordinates[2].lat).toBe(47.2);
});
});