zuora to eloqua | eloqua existing import | aws entry point | Search

This code unit tests the eloqua existing import module, which checks for the existence of custom data objects and import definitions within the Eloqua API. The tests use Sinon.js to mock API responses and assert the module's expected behavior.

Run example

npm run import -- "test eloqua existing import"

test eloqua existing import

var assert = require('assert');
var sinon = require('sinon');
var importer = require('../Core');
var request = importer.import("http request polyfill");
var existing = importer.import("eloqua existing import");
var { bulkImportTemplate } = importer.import("eloqua create template");
var {
    getEloquaConfig,
    getOauthToken,
} = importer.import("eloqua import blueprints");

var eloquaConfig = getEloquaConfig();
var eloquaToken = getOauthToken();
var sandbox = sinon.createSandbox();

describe('eloqua existing import', () => {
        
    afterEach(() => {
        sandbox.restore();
    })

    it('should check if the custom object is configured', () => {
        
        const requestStub = sandbox.stub(request, "request")
            .returns(Promise.resolve({ body: {items: [{name: 'AUT - NA Renewals'}] } }));
        
        return existing.getCustomDataObject({}, eloquaConfig)
            .then(r => {
                assert(r);
                assert(requestStub.calledOnce, 'request should only be called once');
            })
    })
    
    it('should check if there is already an import definition', () => {
        
        const requestStub = sandbox.stub(request, "request")
            .returns(Promise.resolve({ body: {items: [{name: bulkImportTemplate(0).name, uri: '/imports/1234'}] } }));
        
        return existing.getImportDefinitions('/imports/1234', eloquaToken, eloquaConfig)
            .then(r => {
                assert(r.uri);
                assert(requestStub.calledOnce, 'request should only be called once');
            })
    })
    
});

What the code could have been:

const assert = require('assert');
const sinon = require('sinon');
const { createSandbox } = require('sinon');

const importer = require('../Core');
const requestMock = importer.import('http request polyfill');
const existingImport = importer.import('eloqua existing import');
const { getEloquaConfig, getOauthToken, bulkImportTemplate } = importer.import('eloqua import blueprints');

describe('Eloqua Existing Import', () => {
  let sandbox;

  beforeEach(() => {
    sandbox = createSandbox();
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('should check if the custom object is configured', async () => {
    // Mock the request response to return a custom object
    const requestStub = sandbox.stub(requestMock,'request')
     .returns(Promise.resolve({ body: { items: [{ name: 'AUT - NA Renewals' }] } }));

    const result = await existingImport.getCustomDataObject({}, await getEloquaConfig());
    assert(result);
    assert(requestStub.calledOnce,'request should only be called once');
  });

  it('should check if there is already an import definition', async () => {
    // Mock the request response to return an import definition
    const requestStub = sandbox.stub(requestMock,'request')
     .returns(Promise.resolve({ body: { items: [{ name: bulkImportTemplate(0).name, uri: '/imports/1234' }] } }));

    const result = await existingImport.getImportDefinitions('/imports/1234', await getOauthToken(), await getEloquaConfig());
    assert(result.uri);
    assert(requestStub.calledOnce,'request should only be called once');
  });
});

This code defines unit tests for the eloqua existing import module, which likely handles interacting with the Eloqua API to check for existing custom data objects and import definitions.

Here's a breakdown:

  1. Setup:

  2. Test Suite:

  3. Test Cases:

  4. Conclusion:

    These tests verify the functionality of the eloqua existing import module by mocking API interactions and asserting the expected behavior.