db-vendo-client/test/lib/request.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
import tap from 'tap';
2022-05-07 16:17:37 +02:00
import {
checkIfResponseIsOk as checkIfResIsOk,
} from '../../lib/request.js';
2022-05-07 16:17:37 +02:00
import {
HafasError,
} from '../../lib/errors.js';
2022-05-07 16:17:37 +02:00
2024-12-08 21:42:57 +00:00
const resNoMatch = {verbindungen: [], verbindungReference: {}, fehlerNachricht: {code: 'MDA-AK-MSG-1001', ueberschrift: 'Datum liegt außerhalb der Fahrplanperiode.', text: 'Das Datum liegt außerhalb der Fahrplanperiode.'}};
const secret = Symbol('secret');
2022-05-07 16:17:37 +02:00
2024-12-07 23:48:08 +00:00
tap.test('checkIfResponseIsOk properly throws HAFAS errors', (t) => {
2022-05-07 16:17:37 +02:00
try {
checkIfResIsOk({
body: resNoMatch,
errProps: {secret},
});
2022-05-07 16:17:37 +02:00
} catch (err) {
t.ok(err);
2022-05-07 16:17:37 +02:00
t.ok(err instanceof HafasError);
t.equal(err.isHafasError, true);
t.ok(err instanceof HafasError);
t.equal(err.isCausedByServer, false);
2024-12-07 23:48:08 +00:00
t.equal(err.code, 'MDA-AK-MSG-1001');
2022-05-07 16:17:37 +02:00
2024-12-07 23:48:08 +00:00
t.equal(err.hafasMessage, 'Datum liegt außerhalb der Fahrplanperiode.');
t.equal(err.hafasDescription, 'Das Datum liegt außerhalb der Fahrplanperiode.');
2022-05-07 16:17:37 +02:00
t.end();
2022-05-07 16:17:37 +02:00
}
});