bridge-node-server/node_server/dev_api/specs/store-worldpay-merchant.e2e.spec.js
Martin Donnelly 57bd6c8e6a init
2018-06-24 21:15:03 +01:00

121 lines
3.9 KiB
JavaScript

/**
* @fileOverview End-to-end testing of the payment instruments save receiving worldpay swagger API
*/
'use strict';
// eslint-disable-next-line no-unused-vars
const testGlobals = require('../../tools/test/testGlobals.js');
const request = require('supertest');
const express = require('express');
const _ = require('lodash');
const initDevApi = require('../dev_server.js');
function respondsWithValue(thisApp, params, header, value) {
return request(thisApp)
.post('/dev/v0/payment-instruments/worldpay-merchants')
.set('Accept', 'application/json')
.set('Authorization', header)
.send(params)
.expect(value);
}
/**
* Test values
*/
// Correct auth method (Bearer), correct token
const TOKEN_VALID = 'YTM2ZGQ1NzUtOWFmNS01MjMyLTg5MjYtM2NkZjA5ZDU2ZGU1';
const HEADER_VALID = 'Bearer ' + TOKEN_VALID;
// Standard errored values
const TOO_LONG = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' +
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' +
'012345678901234567890123456789012345678901234567890123456789';
const BAD_MERCHANT_SERVICE_KEY = TOO_LONG;
const BAD_DESCRIPTION = TOO_LONG;
// Valid test data
const correctParameters = {
description: 'Bloggs Co Inc',
receivingAccountServiceKey: 'T_S_4db79f58-b8e8-4485-9346-1aafe16ffc57'
};
let badParameters;
describe('E2E: save worldpay merchant account for future use request', () => {
let app;
/**
* Load the dev API router to handle `/dev/*` routes
*/
before(() => {
app = express();
const devApiRouter = initDevApi.init();
app.use('/dev', devApiRouter);
});
describe('test with missing required parameters', () => {
/*
* Tests where required top level attributes are missing.
* ======================================================
*/
/*
* No receiving account service key
*/
badParameters = _.cloneDeep(correctParameters);
delete badParameters.receivingAccountServiceKey;
it('with no receivingAccountServiceKey parameter', () => {
return respondsWithValue(app, badParameters, HEADER_VALID, 400);
});
});
describe('bad data format tests', () => {
/*
* Invalid data format errors
* ==========================
*/
/*
* Bad receiving acount service key
*/
badParameters = _.cloneDeep(correctParameters);
badParameters.receivingAccountServiceKey = BAD_MERCHANT_SERVICE_KEY;
it('with a badly formatted receivingAccountServiceKey parameter', () => {
return respondsWithValue(app, badParameters, HEADER_VALID, 400);
});
/*
* Bad description
*/
badParameters = _.cloneDeep(correctParameters);
badParameters.description = BAD_DESCRIPTION;
it('with a badly formatted description parameter', () => {
return respondsWithValue(app, badParameters, HEADER_VALID, 400);
});
});
/* Skip these tests as they will change when the actual function is implemented. */
describe.skip('Good parameter data tests', () => {
/*
* Verify that the command correctly validates a minimum set of correctly formatted parameters.
*/
const minimumValidSet = _.cloneDeep(correctParameters);
delete minimumValidSet.description;
it('with the minimum set of correct parameters', () => {
return respondsWithValue(app, minimumValidSet, HEADER_VALID, 500);
});
/*
* Verify that the command works with correctly formatted parameters.
*/
it('with a full set of correct parameters', () => {
return respondsWithValue(app, correctParameters, HEADER_VALID, 500);
});
});
});