Skip to content

Commit

Permalink
Remove complex bankenlist parameter from api
Browse files Browse the repository at this point in the history
  • Loading branch information
ckosmowski committed Nov 14, 2018
1 parent e180026 commit c511db6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/Bank.ts

This file was deleted.

15 changes: 3 additions & 12 deletions src/FinTSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ClientRequest } from 'http';
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';
import { Bank } from './Bank';
import { BPD } from './BPD';
import { DatenElementGruppe } from './DatenElementGruppe';
import { Exceptions } from './Exceptions';
Expand Down Expand Up @@ -34,7 +33,6 @@ export class FinTSClient {

public upd: UPD = new UPD();
public konten: Konto[] = [];
private bankenliste: { [index: string]: Bank };
private ctry = 280;

private debugMode = false;
Expand All @@ -44,8 +42,8 @@ export class FinTSClient {
private inConnection = false;
private lastSignaturId = 1;

constructor(public blz: string, public kundenId: string,
public pin: string, public bankenList: any) {
constructor(public blz: string, public bankUrl: string, public kundenId: string,
public pin: string) {
this.kundenId = Helper.escapeUserString(kundenId);
this.pin = Helper.escapeUserString(pin);
this.clear();
Expand All @@ -57,15 +55,8 @@ export class FinTSClient {
this.sysId = 0;
this.lastSignaturId = 1;
this.bpd = new BPD();

try {
this.bpd.url = this.bankenList === undefined ? this.bankenliste['' + this.blz].url : this.bankenList['' + this.blz].url;
} catch (e) {
throw new Exceptions.MissingBankConnectionDataException(this.blz);
}

this.bpd.url = this.bankUrl;
this.upd = new UPD();

this.konten = [];
}

Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './Bank';
export * from './Betrag';
export * from './BPD';
export * from './ByteVal';
Expand Down
37 changes: 22 additions & 15 deletions test/FinTSClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const bankenliste = {
url: 'http://TOBESET/cgi-bin/hbciservlet',
},
};
const testBlz = '12345678';
let testBankUrl = '';
const testKundenId = 'test1';
const testPin = '1234';

const expectClientState = (client: FinTSClient) => {
expect(client.bpd).toHaveProperty('versBpd', '78');
Expand All @@ -24,7 +28,10 @@ const expectClientState = (client: FinTSClient) => {

beforeAll(async (done) => {
testServer = new TestServer(bankenliste);
testServer.start(done);
testServer.start(() => {
testBankUrl = bankenliste[testBlz].url;
done();
});
});

afterAll(() => {
Expand All @@ -34,7 +41,7 @@ afterAll(() => {
describe('The FinTSClient', () => {

it('initializes a dialog', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.msgInitDialog(makeCallback(done, (error, recvMsg, hasNewUrl) => {
expectClientState(client);
expect(client.konten[0].sepaData).toBe(null);
Expand All @@ -43,23 +50,23 @@ describe('The FinTSClient', () => {
});

it('throws an error for a wrong user', (done) => {
const client = new FinTSClient('12345678', 'test2', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, 'test2', testPin);
client.msgInitDialog((error) => {
expect(error).toBeDefined();
done();
});
});

it('throws an error for a wrong pin', (done) => {
const client = new FinTSClient('12345678', 'test1', '12341', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, '12341');
client.msgInitDialog((error) => {
expect(error).toBeDefined();
done();
});
});

it('ends the dialog, closes secure', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.msgInitDialog(makeCallback(done, () => {
client.msgEndDialog(makeCallback(done, () => {
client.closeSecure();
Expand All @@ -75,7 +82,7 @@ describe('The FinTSClient', () => {
});

it('requests account information', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.msgInitDialog(makeCallback(done, (err) => {
expectClientState(client);
expect(client.konten[0].sepaData).toBe(null);
Expand All @@ -89,7 +96,7 @@ describe('The FinTSClient', () => {
});

it('reports error on failed connection', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.msgInitDialog(makeCallback(done, (error) => {
expectClientState(client);
expect(client.konten[0].sepaData).toBe(null);
Expand All @@ -103,7 +110,7 @@ describe('The FinTSClient', () => {
}, 60000);

it('establishes a connection', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, () => {
expectClientState(client);
expect(client.konten[0].sepaData).not.toBeNull();
Expand All @@ -114,23 +121,23 @@ describe('The FinTSClient', () => {
});

it('fails connecting with wrong user', (done) => {
const client = new FinTSClient('12345678', 'test1_wrong_user', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, 'test2', testPin);
client.establishConnection((error) => {
expect(error).toBeDefined();
done();
});
});

it('fails connecting with wrong password', (done) => {
const client = new FinTSClient('12345678', 'test1', '123d', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, '123d');
client.establishConnection((error) => {
expect(error).toBeDefined();
done();
});
});

it('retrieves transactions', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, () => {
expect(client.konten[0].sepaData).not.toBeNull();
client.msgGetKontoUmsaetze(client.konten[0].sepaData, null, null, makeCallback(done, (error2, rMsg, data: Umsatz[]) => {
Expand Down Expand Up @@ -160,7 +167,7 @@ describe('The FinTSClient', () => {
});

it('retrieves totals', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, (error) => {
expect(client.konten[0].sepaData).not.toBeNull();
client.msgGetSaldo(client.konten[0].sepaData, makeCallback(done, (error2, rMsg, data) => {
Expand All @@ -180,7 +187,7 @@ describe('The FinTSClient', () => {
});

it('checks the correct sequence of messages', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, (error) => {
let errorChecked = false;
expect(client.konten[0].sepaData).not.toBeNull();
Expand Down Expand Up @@ -216,7 +223,7 @@ describe('The FinTSClient with offset', () => {
});

it('retrieves transactions', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, (error) => {
expect(client.konten[0].sepaData).not.toBeNull();
client.msgGetKontoUmsaetze(client.konten[0].sepaData, null, null, makeCallback(done, (error2, rMsg, data: Umsatz[]) => {
Expand Down Expand Up @@ -245,7 +252,7 @@ describe('The FinTSClient with HBCI 2.2 protocol', () => {
});

it('establishes connection', (done) => {
const client = new FinTSClient('12345678', 'test1', '1234', bankenliste);
const client = new FinTSClient(testBlz, testBankUrl, testKundenId, testPin);
client.establishConnection(makeCallback(done, (error) => {
expectClientState(client);
expect(client.konten[0].sepaData).not.toBeNull();
Expand Down

0 comments on commit c511db6

Please sign in to comment.