48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
|
import { Test, TestingModule } from '@nestjs/testing';
|
||
|
import { HttpService } from '@nestjs/axios';
|
||
|
import { GeorouterCreator } from '../../adapters/secondaries/georouter-creator';
|
||
|
import { Geodesic } from '../../adapters/secondaries/geodesic';
|
||
|
import { GraphhopperGeorouter } from '../../adapters/secondaries/graphhopper-georouter';
|
||
|
|
||
|
const mockHttpService = jest.fn();
|
||
|
const mockGeodesic = jest.fn();
|
||
|
|
||
|
describe('Georouter creator', () => {
|
||
|
let georouterCreator: GeorouterCreator;
|
||
|
|
||
|
beforeAll(async () => {
|
||
|
const module: TestingModule = await Test.createTestingModule({
|
||
|
imports: [],
|
||
|
providers: [
|
||
|
GeorouterCreator,
|
||
|
{
|
||
|
provide: HttpService,
|
||
|
useValue: mockHttpService,
|
||
|
},
|
||
|
{
|
||
|
provide: Geodesic,
|
||
|
useValue: mockGeodesic,
|
||
|
},
|
||
|
],
|
||
|
}).compile();
|
||
|
|
||
|
georouterCreator = module.get<GeorouterCreator>(GeorouterCreator);
|
||
|
});
|
||
|
|
||
|
it('should be defined', () => {
|
||
|
expect(georouterCreator).toBeDefined();
|
||
|
});
|
||
|
it('should create a graphhopper georouter', () => {
|
||
|
const georouter = georouterCreator.create(
|
||
|
'graphhopper',
|
||
|
'http://localhost',
|
||
|
);
|
||
|
expect(georouter).toBeInstanceOf(GraphhopperGeorouter);
|
||
|
});
|
||
|
it('should throw an exception if georouter type is unknown', () => {
|
||
|
expect(() =>
|
||
|
georouterCreator.create('unknown', 'http://localhost'),
|
||
|
).toThrow();
|
||
|
});
|
||
|
});
|