db-vendo-client/test/lib/request.js
McToel 1aeb246622
Browser compatibility (#17)
* Removed Proxy and local address code

* replaced node crypto with web crypto

* Replaced require with static imports

* removed commented out imports

* import db-hafas-stations on demand

* trying to handle undefined envs

* Less optimistic variable handling

* cleanup

* Small browser docs addition

* Linting

* No async in new Promise

* Bumped eslint to v9 and ecmaScript to 2025

* removed duplicated eslint config

* Bumped minimal node version to node 18

* Added node 24

* using math.random instead of webcrypto and reintroduced randomizeUserAgent

* Oh no node 24 is actually not released yet

* removed temp debug file
2025-02-25 13:21:26 +01:00

35 lines
1.1 KiB
JavaScript

// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import tap from 'tap';
import {
checkIfResponseIsOk as checkIfResIsOk,
} from '../../lib/request.js';
import {
HafasError,
} from '../../lib/errors.js';
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');
tap.test('checkIfResponseIsOk properly throws HAFAS errors', (t) => {
try {
checkIfResIsOk({
body: resNoMatch,
errProps: {secret},
});
} catch (err) {
t.ok(err);
t.ok(err instanceof HafasError);
t.equal(err.isHafasError, true);
t.ok(err instanceof HafasError);
t.equal(err.isCausedByServer, false);
t.equal(err.code, 'MDA-AK-MSG-1001');
t.equal(err.hafasMessage, 'Datum liegt außerhalb der Fahrplanperiode.');
t.equal(err.hafasDescription, 'Das Datum liegt außerhalb der Fahrplanperiode.');
t.end();
}
});