Skip to content

Commit

Permalink
Added some tests for the BankID Service methods
Browse files Browse the repository at this point in the history
  • Loading branch information
NormySan committed Nov 4, 2016
1 parent 92798f5 commit ee3ef42
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
50 changes: 25 additions & 25 deletions test/BankIDService.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
// Require dependencies.
var assert = require('chai').assert;
var sinon = require('sinon');
var soapStub = require('soap/soap-stub');
'use strict';

// Require things to test.
var BankID = require('../lib/BankID');
var helpers = require('./helpers');
var expect = require('chai').expect;
var BankIDService = require('../lib/BankIDService');
var BankIdError = require('../lib/BankIDError');

// Create the test client stub.
var clientStub = {
Authenticate: sinon.stub(),
Collect: sinon.stub(),
Sign: sinon.stub(),
};

clientStub.Authenticate.respondWithError = soapStub.createRespondingStub({});
describe('BankID Service', function () {

soapStub.registerClient('BankID Stub Client', BankID.buildBankIDApiUrl('test'), clientStub);
describe('createBankIDError', function () {

describe('BankID Service', function () {
var clientStub;
var service;
it('should create a new BankIDError when the BankID API returns an error object', function () {
var error = BankIDService.createBankIDError(helpers.simulateBankIDError());
expect(error).to.be.instanceOf(BankIdError);
});

beforeEach(function () {
clientStub = soapStub.getStub('BankID Stub Client');
soapStub.reset();
service = new BankIDService(clientStub);
it('should return the initial error object if not a BankID error', function () {
var notBankIdError = new Error('Not a BankID error');
var error = BankIDService.createBankIDError(notBankIdError);
expect(error).to.equal(notBankIdError);
});
});

it('should handle error responses', function (done) {
clientStub.Authenticate.respondWithError();
service.authenticate({}, done);
describe('isValidSSN', function () {

it('should return true on a ssn with 12 digits', function () {
expect(BankIDService.isValidSSN('199001011337')).to.equal(true);
});

it('should return false on a ssn that does not have 12 digits', function () {
expect(BankIDService.isValidSSN('19900101')).to.equal(false);
expect(BankIDService.isValidSSN('19900101133700')).to.equal(false);
});
});
});
28 changes: 28 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

/**
* Creates a mock error object that looks similar to an error recieved from
* the BankID API.
*
* @return {object}
*/
exports.simulateBankIDError = function () {
const error = new Error('Some error message');

error.root = {
Envelope: {
Body: {
Fault: {
detail: {
RpFault: {
faultStatus: 'SOME_FAULT_STATUS',
detailedDescription: 'Some detailed description',
},
},
},
},
},
};

return error;
}

0 comments on commit ee3ef42

Please sign in to comment.