mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-08-14 03:35:36 +00:00
test: add more tests
This commit is contained in:
21
test/unit/middlewares.js
Normal file
21
test/unit/middlewares.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { assert } = require('chai');
|
||||
|
||||
const response = require('../../lib/middleware/response');
|
||||
const serializer = require('../../lib/middleware/serializer');
|
||||
const signer = require('../../lib/middleware/signer');
|
||||
|
||||
describe('Middlewares', () => {
|
||||
describe('Response Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => response('H003')));
|
||||
});
|
||||
describe('Signer Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => signer('H003')));
|
||||
});
|
||||
describe('Signer Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => serializer('H003')));
|
||||
});
|
||||
});
|
@@ -2,44 +2,111 @@
|
||||
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { readFileSync } = require('fs');
|
||||
const { join, resolve } = require('path');
|
||||
|
||||
const { assert } = require('chai');
|
||||
|
||||
const H004Response = require('../../lib/orders/H004/response');
|
||||
const ebics = require('../../');
|
||||
|
||||
|
||||
const client = new ebics.Client({
|
||||
url: 'https://iso20022test.credit-suisse.com/ebicsweb/ebicsweb',
|
||||
partnerId: 'CRS04381',
|
||||
userId: 'CRS04381',
|
||||
hostId: 'CRSISOTB',
|
||||
passphrase: 'test',
|
||||
keyStorage: ebics.fsKeysStorage(resolve(__dirname, '../support/TEST_KEYS.key')),
|
||||
});
|
||||
|
||||
const buildResponse = (xmlPath) => {
|
||||
const response = H004Response('<xml/>', {});
|
||||
const xml = readFileSync(xmlPath, { encoding: 'utf8' });
|
||||
response.orderData = () => xml;
|
||||
return response;
|
||||
};
|
||||
|
||||
const fixtures = {
|
||||
HPB: async () => H004Response(readFileSync(join(__dirname, '../fixtures/HPB_response.xml'), { encoding: 'utf8' }), await client.keys()),
|
||||
HPB_DATA: () => buildResponse(join(__dirname, '../fixtures/HPB_response_data.xml')),
|
||||
INI: () => H004Response(readFileSync(join(__dirname, '../fixtures/INI_reposne.xml'), { encoding: 'utf8' }), client.keys()),
|
||||
STA_1: () => H004Response(readFileSync(join(__dirname, '../fixtures/STA_response_part1.xml'), { encoding: 'utf8' }), client.keys()),
|
||||
STA_2: () => H004Response(readFileSync(join(__dirname, '../fixtures/STA_response_part2.xml'), { encoding: 'utf8' }), client.keys()),
|
||||
x002mod: 'AJWVHQIfP0H1fr5Y7IjSlDmFksqQ+0E+CjzbEeE6r444LCuSXwbGKF6DJqguyX1qGYxjHRvVtdkNa+GNAtlZnmuPeLHPBUOs5Zx9J5JP4JZOcKd/wnRDIasTkg3NrtZ22tjOrWx26VuR6h7dUH2oJRnFDHmbXoCDMxkqJUNr/TM89p5slJ9Oj5+NAaOzm+7AlwbJ95EI/xc2jEfhp+GdF9CYdS/m2AZaAt79y6QDtBSDdAs0OHTgsOIjbjZkptBF/Gkip2sOordjsChRNLHLDcAOWbsg1NVMuhXs1b6+bCVLXQcGhFydYhqvrXB7pFS0++hlyzqGhbZK5cwEe/v8EJk=',
|
||||
e002mod: 'AJWVHQIfP0H1fr5Y7IjSlDmFksqQ+0E+CjzbEeE6r444LCuSXwbGKF6DJqguyX1qGYxjHRvVtdkNa+GNAtlZnmuPeLHPBUOs5Zx9J5JP4JZOcKd/wnRDIasTkg3NrtZ22tjOrWx26VuR6h7dUH2oJRnFDHmbXoCDMxkqJUNr/TM89p5slJ9Oj5+NAaOzm+7AlwbJ95EI/xc2jEfhp+GdF9CYdS/m2AZaAt79y6QDtBSDdAs0OHTgsOIjbjZkptBF/Gkip2sOordjsChRNLHLDcAOWbsg1NVMuhXs1b6+bCVLXQcGhFydYhqvrXB7pFS0++hlyzqGhbZK5cwEe/v8EJk=',
|
||||
};
|
||||
|
||||
|
||||
describe('H004 response parsing', () => {
|
||||
it('parses bank keys', () => {
|
||||
const response = H004Response('<xml/>', {});
|
||||
|
||||
const x002mod = 'ntbX6WFjAJP5RyH4ogDG/26wZGzEJXsTudyvcgXmUdk1AExCNqArXDiSlGXpVNq4BKddUMFUmVOyvkdNckPRV2mk3uHNCE5T3tFKQI3FlwHSJHvPSpb9gtHnsK03jByMigWjhTKvsjIdfLVay5m5Bctxq9+5JMHwlNk7MlVXBQcqaFiHFFS1lPfA3Wk1bptPeeGyYcP0+U798oQWnCABKwS8hmYcp5xBtozGoRj9L/NDE68pdP8o/wTKNwT4Jo5nQKYfDsgO4R+z9vVv37Htp6bWhK8Jw3tpkcd3JnkYWx+Ylg0XBpg8LfjFhY2Jc7FqLlx0Bn0Y3PRLI1apxgC85w==';
|
||||
const e002mod = '4eOGrzcJHVzbEgZTmyPYUIq9kFoua8Ure1Mvyq6XlawFgCWskfu/xSKNLIMJ7H675wl/5y0Oy16P/b6pJEhWrzOw8omW46PBDTaXw9BDYBTuBblluz1yUnzpgfblP8gkRmxAo+QMIskmwdSzuZMiJcLNSzu/bkmLHK2RdrVYMAZLlB6QXTykdenPZtNmc2z4VU6TRmGljAwg2VUNF6iQoucbzDUuca+yUo3fiXZp69nfXv81X2ND+p1ir6zQpx7tbOdfauw0sEKI/Z/lC+E4fMrMlh/ZvOxSYUMA55J4liC3aUV3mTR3dPJHWu1aD1a7EfJnNw0eHLwlB+36qfgGuw==';
|
||||
|
||||
response.orderData = () => `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<HPBResponseOrderData xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||
<AuthenticationPubKeyInfo>
|
||||
<PubKeyValue>
|
||||
<ds:RSAKeyValue>
|
||||
<ds:Modulus>${x002mod}</ds:Modulus>
|
||||
<ds:Exponent>AQAB</ds:Exponent>
|
||||
</ds:RSAKeyValue>
|
||||
<TimeStamp>2015-02-25T08:01:13.061Z</TimeStamp>
|
||||
</PubKeyValue>
|
||||
<AuthenticationVersion>X002</AuthenticationVersion>
|
||||
</AuthenticationPubKeyInfo>
|
||||
<EncryptionPubKeyInfo>
|
||||
<PubKeyValue>
|
||||
<ds:RSAKeyValue>
|
||||
<ds:Modulus>${e002mod}</ds:Modulus>
|
||||
<ds:Exponent>AQAB</ds:Exponent>
|
||||
</ds:RSAKeyValue>
|
||||
<TimeStamp>2015-02-25T08:01:12.344Z</TimeStamp>
|
||||
</PubKeyValue>
|
||||
<EncryptionVersion>E002</EncryptionVersion>
|
||||
</EncryptionPubKeyInfo>
|
||||
<HostID>SBKPR01</HostID>
|
||||
</HPBResponseOrderData>`;
|
||||
|
||||
const response = fixtures.HPB_DATA();
|
||||
const bankKeys = response.bankKeys();
|
||||
|
||||
assert.equal(bankKeys.bankX002.mod.toString('base64'), x002mod);
|
||||
assert.equal(bankKeys.bankE002.mod.toString('base64'), e002mod);
|
||||
assert.equal(bankKeys.bankX002.mod.toString('base64'), fixtures.x002mod);
|
||||
assert.equal(bankKeys.bankE002.mod.toString('base64'), fixtures.e002mod);
|
||||
});
|
||||
|
||||
it('detects unsegmented response', () => {
|
||||
const response = fixtures.HPB_DATA();
|
||||
assert.equal(response.isSegmented(), false);
|
||||
assert.equal(response.isLastSegment(), false);
|
||||
});
|
||||
|
||||
it('detects segmented response', () => {
|
||||
const responsePart1 = fixtures.STA_1();
|
||||
const responsePart2 = fixtures.STA_2();
|
||||
assert.equal(responsePart1.isSegmented(), true);
|
||||
assert.equal(responsePart1.isLastSegment(), false);
|
||||
assert.equal(responsePart2.isSegmented(), true);
|
||||
assert.equal(responsePart2.isLastSegment(), true);
|
||||
});
|
||||
|
||||
it('parses OrderID', () => {
|
||||
const response = fixtures.INI();
|
||||
assert.equal(response.orderId(), 'B004');
|
||||
});
|
||||
|
||||
it('parses BuissnessCode', () => {
|
||||
const response = fixtures.INI();
|
||||
const code = response.businessCode();
|
||||
assert.equal(code, '000000');
|
||||
assert.equal(response.businessSymbol(code), 'EBICS_OK');
|
||||
assert.equal(response.businessMeaning(code), 'No technical errors occurred during processing of the EBICS request');
|
||||
assert.equal(response.businessShortText(code), 'OK');
|
||||
});
|
||||
|
||||
it('parses TechnicalCode', () => {
|
||||
const response = fixtures.INI();
|
||||
const code = response.technicalCode();
|
||||
assert.equal(code, '000000');
|
||||
assert.equal(response.technicalSymbol(code), '[EBICS_OK] OK');
|
||||
assert.equal(response.technicalMeaning(code), 'No technical errors occurred during processing of the EBICS request');
|
||||
assert.equal(response.technicalShortText(code), 'OK');
|
||||
});
|
||||
|
||||
it('parses TransactionID', () => {
|
||||
const response = fixtures.STA_1();
|
||||
const code = response.transactionId();
|
||||
assert.equal(code, 'ECD6F062AAEDFA77250526A68CBEC549');
|
||||
});
|
||||
|
||||
it('parses TransactionKey', async () => {
|
||||
const response = await fixtures.HPB();
|
||||
const code = response.transactionKey().toString('base64');
|
||||
assert.equal(code, '2OTepxiy49uayuzZlYFf8Q==');
|
||||
});
|
||||
|
||||
it('parses OrderData', async () => {
|
||||
const response = await fixtures.HPB();
|
||||
const orderBuffer = response.orderData();
|
||||
assert.deepEqual(orderBuffer, readFileSync(join(__dirname, '../fixtures/HPB_response_data.xml')));
|
||||
});
|
||||
|
||||
it('generates XML', async () => {
|
||||
const response = await fixtures.HPB();
|
||||
const xmlString = response.toXML().replace('\\n', '\n');
|
||||
assert.deepEqual(xmlString, readFileSync(join(__dirname, '../fixtures/HPB_response.xml'), { encoding: 'utf8' }));
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user