This code unit tests an AWS Lambda function responsible for syncing data between Zuora and Eloqua, ensuring it correctly calls functions to export data from Zuora and upload it to Eloqua. The tests use sinon
to mock dependencies and assert
to verify function calls and arguments.
npm run import -- "test notify entry point"
var sinon = require('sinon');
var assert = require('assert');
var importer = require('../Core');
var bundle = importer.import("notify entry point");
var zuoraExport = importer.import("zuora account service");
var eloquaUpload = importer.import("bulk upload eloqua");
var sandbox = sinon.createSandbox();
describe('content notify entry point', () => {
afterEach(() => {
sandbox.restore();
})
it('should call zuora export', () => {
const callback = sinon.spy();
const dummyBody = {
}
const requestStub = sandbox.stub(zuoraExport, "getZuoraAccounts")
.returns(Promise.resolve([]));
sandbox.stub(eloquaUpload, "bulkUploadEloqua")
.returns(Promise.resolve(true));
return bundle.handler(dummyBody, null, callback)
.then(() => {
assert(callback.calledOnce);
const stubCall = requestStub.getCall(0);
assert.equal(stubCall.args[0], dummyBody);
});
})
it('should call bulk upload', () => {
const callback = sinon.spy();
const dummyAccounts = [];
sandbox.stub(zuoraExport, "getZuoraAccounts")
.returns(Promise.resolve(dummyAccounts));
const requestStub = sandbox.stub(eloquaUpload, "bulkUploadEloqua")
.returns(Promise.resolve(true));
return bundle.handler({}, null, callback)
.then(() => {
assert(callback.calledOnce);
const stubCall = requestStub.getCall(0);
assert.equal(stubCall.args[0], dummyAccounts);
});
})
})
const sinon = require('sinon');
const assert = require('assert');
const importer = require('../Core');
describe('Content Notify Entry Point', () => {
let sandbox, bundle, zuoraExport, eloquaUpload;
beforeEach(() => {
sandbox = sinon.createSandbox();
bundle = importer.import('notify entry point');
zuoraExport = importer.import('zuora account service');
eloquaUpload = importer.import('bulk upload eloqua');
});
afterEach(() => {
sandbox.restore();
});
describe('Handler Calls', () => {
describe('Zuora Export', () => {
it('should call zuora export when no accounts are present', () => {
const callback = sinon.spy();
const dummyBody = {};
const dummyAccounts = [];
const requestStub = sandbox.stub(zuoraExport, "getZuoraAccounts")
.returns(Promise.resolve(dummyAccounts));
sandbox.stub(eloquaUpload, "bulkUploadEloqua")
.returns(Promise.resolve(true));
return bundle.handler(dummyBody, null, callback)
.then(() => {
assert(callback.calledOnce);
const stubCall = requestStub.getCall(0);
assert.equal(stubCall.args[0].zuoraExport, zuoraExport); // TODO: Check if dummyBody is actually being passed
assert.deepEqual(stubCall.args[0].accounts, []); // TODO: Check if dummyAccounts is actually being passed
});
});
it('should call bulk upload with accounts', () => {
const callback = sinon.spy();
const dummyAccounts = [];
sandbox.stub(zuoraExport, "getZuoraAccounts")
.returns(Promise.resolve(dummyAccounts));
const requestStub = sandbox.stub(eloquaUpload, "bulkUploadEloqua")
.returns(Promise.resolve(true));
return bundle.handler({}, null, callback)
.then(() => {
assert(callback.calledOnce);
const stubCall = requestStub.getCall(0);
assert.equal(stubCall.args[0].zuoraExport, zuoraExport); // TODO: Check if dummyAccounts is actually being passed
assert.deepEqual(stubCall.args[0].accounts, dummyAccounts);
});
});
});
});
});
This code defines unit tests for an AWS Lambda function that handles notifications and data synchronization between Zuora and Eloqua.
Here's a breakdown:
Setup:
sandbox
using sinon
to isolate and control the behavior of mocked functions.Test Cases:
describe
and it
blocks:
should call zuora export
: Verifies that the Lambda function calls the getZuoraAccounts
function from the zuoraExport
module with the correct input data.should call bulk upload
: Checks if the function calls the bulkUploadEloqua
function from the eloquaUpload
module with the retrieved data from Zuora.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.