mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-08-14 03:35:36 +00:00
test: add additional tests
This commit is contained in:
49
test/unit/BankLetterTest.js
Normal file
49
test/unit/BankLetterTest.js
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { assert } = require('chai');
|
||||
const { join, resolve } = require('path');
|
||||
const { readFileSync, mkdirSync, existsSync } = require('fs');
|
||||
|
||||
|
||||
const BankLetter = require('../../lib/BankLetter');
|
||||
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 createDir = (where) => {
|
||||
try {
|
||||
mkdirSync(where);
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST')
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
describe('BankLetter', () => {
|
||||
let bankLetterGenerator = null;
|
||||
|
||||
it('creates an instance', () => assert.doesNotThrow(() => {
|
||||
bankLetterGenerator = new BankLetter({
|
||||
client,
|
||||
bankName: 'Credit Suisse AG',
|
||||
template: readFileSync(join(__dirname, '../../templates/ini_de.hbs'), { encoding: 'utf8' }),
|
||||
});
|
||||
}));
|
||||
|
||||
it('genrates a letter', async () => assert.doesNotThrow(async () => bankLetterGenerator.generate()));
|
||||
it('throws with invalid serliazitaion path', async () => bankLetterGenerator.serialize('').catch(e => assert.instanceOf(e, Error)));
|
||||
it('serliaziers a letter to disk', async () => {
|
||||
createDir('.test_tmp');
|
||||
await bankLetterGenerator.serialize('.test_tmp/test_letter.html').then(t => assert.equal(t, true));
|
||||
assert.equal(existsSync('.test_tmp/test_letter.html'), true);
|
||||
});
|
||||
});
|
@@ -3,19 +3,39 @@
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
const { assert } = require('chai');
|
||||
const { resolve } = require('path');
|
||||
|
||||
|
||||
const response = require('../../lib/middleware/response');
|
||||
const serializer = require('../../lib/middleware/serializer');
|
||||
const signer = require('../../lib/middleware/signer');
|
||||
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')),
|
||||
});
|
||||
|
||||
|
||||
describe('Middlewares', () => {
|
||||
describe('Response Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => response('H003')));
|
||||
it('should not throw with supported protocol version', () => assert.doesNotThrow(() => response.version('H004')));
|
||||
it('should throw with no unsupported protocol version', () => assert.throws(() => response.version('H003')));
|
||||
});
|
||||
describe('Signer Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => signer('H003')));
|
||||
it('should not throw with supported protocol version', () => assert.doesNotThrow(() => signer.version('H004')));
|
||||
it('should throw with no unsupported protocol version', () => assert.throws(() => signer.version('H003')));
|
||||
});
|
||||
describe('Signer Middleware', () => {
|
||||
it('should throw with no unspported protocol version', () => assert.throws(() => serializer('H003')));
|
||||
describe('Serializer Middleware', () => {
|
||||
it('should not throw with supported protocol version and ini operation', () => assert.doesNotThrow(() => serializer.use(ebics.Orders.INI, client)));
|
||||
it('should not throw with supported protocol version and download operation', () => assert.doesNotThrow(() => serializer.use(ebics.Orders.STA('2018-01-01', '2018-02-01'), client)));
|
||||
it('should not throw with supported protocol version and upload operation', () => assert.doesNotThrow(() => serializer.use(ebics.Orders.AZV('<xml />'), client)));
|
||||
it('should throw with no supported protocol version and ', () => assert.throws(() => serializer.use({ version: 'H004', operation: 'unspported' }, client)));
|
||||
it('should throw with no unuspported protocol version', () => assert.throws(() => serializer.use({ version: 'H003' }, client)));
|
||||
});
|
||||
});
|
||||
|
@@ -108,5 +108,4 @@ describe('H004 response parsing', () => {
|
||||
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