node-ebics-client/test/spec/H004.js

110 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-10-11 18:58:26 +00:00
"use strict";
2019-11-01 06:13:53 +00:00
2019-11-05 03:54:32 +00:00
/* eslint-env node, mocha */
2019-11-01 06:13:53 +00:00
2023-10-11 18:58:26 +00:00
const { assert } = require("chai");
2019-11-01 06:13:53 +00:00
2023-10-11 18:58:26 +00:00
const path = require("path");
const fs = require("fs");
2019-11-01 06:13:53 +00:00
2023-10-11 18:58:26 +00:00
const ebics = require("../../");
2019-11-01 06:13:53 +00:00
2023-10-11 18:58:26 +00:00
const libxml = require("libxmljs");
2019-11-01 06:13:53 +00:00
2023-10-11 18:58:26 +00:00
const schemaPath = path.resolve(__dirname, "../xsd/ebics_H004.xsd");
const schemaDoc = libxml.parseXml(
fs.readFileSync(schemaPath, { encoding: "utf8" })
);
2019-11-01 06:13:53 +00:00
const schemaDir = path.dirname(schemaPath);
const cwd = process.cwd();
const validateXML = (str) => {
try {
process.chdir(schemaDir);
2023-10-11 18:58:26 +00:00
const isValid = libxml.parseXml(str).validate(schemaDoc);
2019-11-01 06:13:53 +00:00
process.chdir(cwd);
return isValid;
} catch (e) {
process.chdir(cwd);
return false;
}
};
const client = new ebics.Client({
2023-10-11 18:58:26 +00:00
url: "https://iso20022test.credit-suisse.com/ebicsweb/ebicsweb",
partnerId: "CRS04381",
userId: "CRS04381",
hostId: "CRSISOTB",
passphrase: "test",
keyStorage: ebics.fsKeysStorage(
path.resolve(__dirname, "../support/TEST_KEYS.key")
),
2019-11-01 06:13:53 +00:00
});
const { Orders } = ebics;
2019-11-01 09:27:36 +00:00
/*
upload :
const AZV = require('./AZV');
const CD1 = require('./CD1');
const CDB = require('./CDB');
const CDD = require('./CDD');
const CDS = require('./CDS');
const CCT = require('./CCT');
const CCS = require('./CCS');
const XE3 = require('./XE3');
const XCT = require('./XCT');
*/
2023-10-11 18:58:26 +00:00
const uploadBuilder = (fn) => fn("");
const dateBuilder = (fn) => fn("2018-01-01", "2019-01-01");
2019-11-01 09:27:36 +00:00
const fnOrders = {
// upload | document
AZV: uploadBuilder,
CD1: uploadBuilder,
CDB: uploadBuilder,
CDD: uploadBuilder,
CDS: uploadBuilder,
CCT: uploadBuilder,
CCS: uploadBuilder,
XE3: uploadBuilder,
XCT: uploadBuilder,
// download
STA: dateBuilder,
VMK: dateBuilder,
HAA: dateBuilder,
HTD: dateBuilder,
HPD: dateBuilder,
HKD: dateBuilder,
PTK: dateBuilder,
HAC: dateBuilder,
Z53: dateBuilder,
2019-11-26 16:22:09 +00:00
DKI: dateBuilder,
C53: dateBuilder,
C52: dateBuilder,
2019-11-01 09:27:36 +00:00
};
const getOrderObject = (name, order) => {
2023-10-11 18:58:26 +00:00
if (typeof order === "object") return order;
if (fnOrders[name]) return fnOrders[name](order);
2019-11-01 09:27:36 +00:00
return null;
};
2023-10-11 18:58:26 +00:00
describe("H004 order generation", () => {
2019-11-01 06:13:53 +00:00
// eslint-disable-next-line no-restricted-syntax
2019-11-01 09:27:36 +00:00
for (const [name, orderDefinition] of Object.entries(Orders)) {
const order = getOrderObject(name, orderDefinition);
2023-10-11 18:58:26 +00:00
if (!order) continue;
2019-11-01 06:13:53 +00:00
const type = order.orderDetails.OrderType;
const { operation } = order;
it(`[${operation}] ${type} order generation`, async () => {
const signedOrder = await client.signOrder(order);
assert.isTrue(validateXML(signedOrder));
});
}
});