34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('osrmConfig optimize()', function() {
|
|
it('should send coords, receive OSRM response, and return a correctly ordered result', async function() {
|
|
const result = await models.OsrmConfig.optimize([4, 3], 1, 2);
|
|
|
|
// Verifications
|
|
expect(Array.isArray(result)).toBe(true);
|
|
expect(result.length).toBe(4);
|
|
|
|
// Check the order
|
|
expect(result[0].addressId).toBe(1);
|
|
expect(result[1].addressId).toBe(4);
|
|
expect(result[2].addressId).toBe(3);
|
|
expect(result[3].addressId).toBe(2);
|
|
|
|
// Check the coordinates format
|
|
expect(result[0].latitude).toBe('10.111111');
|
|
expect(result[0].longitude).toBe('-74.111111');
|
|
});
|
|
|
|
it('should throw an error if no addresses are provided', async function() {
|
|
let error;
|
|
try {
|
|
await models.OsrmConfig.optimize([], null);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toBe('No address has coordinates');
|
|
});
|
|
});
|