postgres direction encoder tests
This commit is contained in:
parent
c45e5c94e5
commit
14d2486c1b
|
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue