zuora to eloqua | aws entry point | notify entry point | Search

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.

Run example

npm run import -- "test aws entry point"

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([]));
            });
    });
})

What the code could have been:

// 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:

  1. Setup:

  2. Test Cases:

  3. Assertions:

  4. Cleanup: