This code uses unit tests to ensure that an AWS Lambda function correctly handles the process of uploading data from Zuora to Eloqua, including calling the necessary functions for data retrieval, mapping, and upload. The tests use sinon
to mock dependencies and assert
to verify the function's behavior.
npm run import -- "test aws entry point"
var assert = require('assert');
var sinon = require('sinon');
var importer = require('../Core');
var bundle = importer.import("aws entry point");
var eloquaUpload = importer.import("bulk upload eloqua");
var zuoraExport = importer.import("zuora export month");
var mapper = importer.import("zuora eloqua mapper");
process.env.ZUORA_API_USER = 'devteam@fakepage.com';
process.env.ZUORA_API_USER = 'pass';
process.env.ZUORA_API_USER = 'http://localhost:18888';
var sandbox = sinon.createSandbox();
describe('bulk upload entry point', () => {
afterEach(() => {
sandbox.restore();
})
it('should call zuora month export', () => {
var callback = sinon.spy();
sandbox.stub(zuoraExport, 'getZuoraMonth').returns(Promise.resolve([]));
return bundle.handler({}, null, callback)
.then(() => {
assert(zuoraExport.getZuoraMonth.calledWithMatch(0));
});
});
it('should call data mapper', () => {
var callback = sinon.spy();
sandbox.stub(zuoraExport, 'getZuoraMonth').returns(Promise.resolve([]));
sandbox.stub(mapper, 'mapDataToFields').returns([]);
return bundle.handler({}, null, callback)
.then(() => {
assert(mapper.mapDataToFields.calledWithMatch([]));
});
});
it('should call bulk upload', () => {
var callback = sinon.spy();
sandbox.stub(zuoraExport, 'getZuoraMonth').returns(Promise.resolve([]));
sandbox.stub(mapper, 'mapDataToFields').returns([]);
sandbox.stub(eloquaUpload, 'bulkUploadEloqua').returns([]);
return bundle.handler({}, null, callback)
.then(() => {
assert(eloquaUpload.bulkUploadEloqua.calledWithMatch([]));
});
});
})
// Core.js
function importImporters(importers) {
return {
handler: (...args) => {
const entryPoint = importers['aws entry point'];
const zuoraExport = importers['zuora export month'];
const mapper = importers['zuora eloqua mapper'];
const eloquaUpload = importers['bulk upload eloqua'];
// TODO: Validate input arguments
// TODO: Implement business logic here
const response = entryPoint.handler(zuoraExport.getZuoraMonth(), mapper.mapDataToFields(), eloquaUpload.bulkUploadEloqua());
// TODO: Handle any errors that may occur
return response;
},
};
}
module.exports = { importImporters };
This code defines unit tests for an AWS Lambda function that handles bulk data uploads from Zuora to Eloqua.
Here's a breakdown:
Setup:
assert
for testing, sinon
for mocking functions, and various components related to Zuora, Eloqua, and the Lambda function itself.sandbox
using sinon
to isolate and control the behavior of mocked functions.Test Cases:
describe
and it
blocks:
should call zuora month export
: Verifies that the Lambda function calls the getZuoraMonth
function from the zuoraExport
module.should call data mapper
: Checks if the function calls the mapDataToFields
function from the mapper
module after successfully retrieving data from Zuora.should call bulk upload
: Confirms that the function calls the bulkUploadEloqua
function from the eloquaUpload
module after mapping the data.Assertions:
assert
to verify that the expected functions are called with the correct arguments.Cleanup:
afterEach
block ensures that the sandbox
is restored after each test case, preventing side effects from one test affecting another.