UNPKG

paymill-node

Version:
155 lines (124 loc) 4.15 kB
var api_key = '66748d6d3d0d36c819560088b9f817d7'; // secret paymill var paymill = require('../lib/main')(api_key); var nock = require('nock'); var paymillHost = 'https://api.paymill.de'; QUnit.module('create transaction'); test('It should call the callback with an Error object if the response status is not 200', function(){ // prepare env var transaction = {}; nock(paymillHost).post('/v2/transactions').reply(500,{}); expect(2); // verify var cb = function(err, response) { ok(err, 'err should not be undefined nor null'); ok(response === null, 'response should be null'); start(); }; // execute paymill.transactions.create(transaction, cb); stop(); }); test('It should call the callback with null Error and the response if all went ok (status 200)', function(){ // prepare env var transaction = {}; nock(paymillHost).post('/v2/transactions').reply(200,{}); expect(2); // verify var cb = function(err, response) { ok(err === null, 'err should be null'); ok(response !== null, 'response should not be null'); start(); }; // execute paymill.transactions.create(transaction, cb); stop(); }); QUnit.module('transaction details'); test('It should throw a TypeError if the transaction_id is not a string', function(){ // prepare env var transaction_id = {}; var cb = function(){}; // execute var fn = function (){ paymill.transactions.details(transaction_id, cb); }; // verify throws(fn, TypeError, 'raised Error is instance of TypeError'); // prepare env transaction_id = 1; // execute fn = function (){ paymill.transactions.details(transaction_id, cb); }; // verify throws(fn, TypeError, 'raised Error is instance of TypeError'); // prepare env transaction_id = function(){}; // execute fn = function (){ paymill.transactions.details(transaction_id, cb); }; // verify throws(fn, TypeError, 'raised Error is instance of TypeError'); }); test('It should call the callback with an Error object if the response status is not 200', function(){ // prepare env var transaction_id = 'testID'; nock(paymillHost).get('/v2/transactions/' + transaction_id).reply(500,{}); expect(2); // verify var cb = function(err, response) { ok(err, 'err should not be undefined nor null'); ok(response === null, 'response should be null'); start(); }; // execute paymill.transactions.details(transaction_id, cb); stop(); }); test('It should call the callback with null Error and the response if all went ok (status 200)', function(){ // prepare env var transaction_id = 'testID'; nock(paymillHost).get('/v2/transactions/' + transaction_id).reply(200,{}); expect(2); // verify var cb = function(err, response) { ok(err === null, 'err should be null'); ok(response !== null, 'response should not be null'); start(); }; // execute paymill.transactions.details(transaction_id, cb); stop(); }); QUnit.module('list transactions'); test('It should call the callback with an Error object if the response status is not 200', function(){ // prepare env var data = {}; nock(paymillHost).get('/v2/transactions').reply(500,{}); expect(2); // verify var cb = function(err, response) { ok(err, 'err should not be undefined nor null'); ok(response === null, 'response should be null'); start(); }; // execute paymill.transactions.list(data, cb); stop(); }); test('It should call the callback with null Error and the response if all went ok (status 200)', function(){ // prepare env var data = {}; nock(paymillHost).get('/v2/transactions').reply(200,{}); expect(2); // verify var cb = function(err, response) { ok(err === null, 'err should be null'); ok(response !== null, 'response should not be null'); start(); }; // execute paymill.transactions.list(data, cb); stop(); });