Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
closes #122 Added Schedule… (#123)
Browse files Browse the repository at this point in the history
* closes #122 Added Schedule Support

* Added Test for Schedule action

* Updated Test case

* Missing semicolon

* Corrected Tests and validated

* Increment Version

* Bumped version to 2.2.4

Changed version as per PR reviewer request
  • Loading branch information
DougMidgley authored and sfcbetiuc committed Nov 5, 2019
1 parent 9675827 commit df1e4e9
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 3 deletions.
59 changes: 58 additions & 1 deletion lib/fuel-soap.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,70 @@ FuelSoap.prototype._parseResponse = function(key, body, callback) {
callback(null, parsedRes);
}.bind(this));
};
/**
* This method handles the Schedule SOAP Action
* @memberof FuelSoap
* @param {String} type - xsi:type
* @param {Object} props - Value set in body as `ScheduleRequest.Objects`
* @param {Object} [options] - Configuration options passed in body as `ScheduleRequest.Options`
* @param {Boolean} [options.queryAllAccounts=false] - Sets `QueryAllAccounts = true` to body under `ScheduleRequest.Options`. **Note:** This value will be delete from body if used
* @param {Object} [options.reqOptions] - Request options passed to soapRequest fn. **Note:** These will be delete from body if passed
* @param {FuelSoap~StandardCallback} callback - Callback that handles response
*/
FuelSoap.prototype.schedule = function(type,schedule,interactions, action, options, callback) {
var body;
var optionsAndCallback;
var reqOptions;
var updateQueryAllAccounts;

optionsAndCallback = determineCallbackAndOptions(arguments, callback, options);
callback = optionsAndCallback.callback;
options = optionsAndCallback.options;

updateQueryAllAccounts = configureQueryAllAccounts(options);
if(isEmpty(options)) {
options = null;
}

reqOptions = helpers.parseReqOptions(options);
body = {
ScheduleRequestMsg: {
$: {
xmlns: 'http://exacttarget.com/wsdl/partnerAPI'
}
, Action: action
, Options: options
, Schedule: schedule
, Interactions: interactions
}
};

if(Array.isArray(body.ScheduleRequestMsg.Interactions)){
for(let i = 0; i < body.ScheduleRequestMsg.Interactions.length; i++){
body.ScheduleRequestMsg.Interactions[0].Interaction.$ = {'xsi:type': type};
}
} else if (typeof body.ScheduleRequestMsg.Interactions === "object") {
body.ScheduleRequestMsg.Interactions.Interaction.$ = {'xsi:type': type};
} else {
throw new TypeError('Interactions must be of Array or Object Type');
}

updateQueryAllAccounts(body.ScheduleRequestMsg, 'Options');

this.soapRequest({
action: 'Schedule'
, req: body
, key: 'ScheduleResponseMsg'
, retry: true
, reqOptions: reqOptions
}, callback);
};

// Methods that need implementations
FuelSoap.prototype.configure = function() {};
FuelSoap.prototype.extract = function() {};
FuelSoap.prototype.getSystemStatus = function() {};
FuelSoap.prototype.query = function() {};
FuelSoap.prototype.schedule = function() {};
FuelSoap.prototype.versionInfo = function() {};

function determineCallbackAndOptions(args, callback, options) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuel-soap",
"version": "2.2.3",
"version": "2.2.4",
"description": "Node library for performing SOAP API calls to Salesforce Marketing Cloud (formerly ExactTarget).",
"main": "./lib/fuel-soap.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion test/specs/general-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('General Tests', function() {
, 'extract'
, 'getSystemStatus'
, 'query'
, 'schedule'
, 'versionInfo'
];

Expand Down
103 changes: 103 additions & 0 deletions test/specs/soap-action-schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

'use strict';

var assert = require('assert');
var proxyquire = require('proxyquire');
var sinon = require('sinon');

describe('SOAP Action - schedule', function() {
var FuelSoap;
var soapRequestSpy;
var parsedOptions = { parsedOptions: true };
var simpleVerifyTestCases = [
{ property: 'action', expected: 'Schedule' }
, { property: 'key', expected: 'ScheduleResponseMsg' }
, { property: 'retry', expected: true }
, { property: 'reqOptions', expected: parsedOptions }
];

var exampleSchedule = {
Recurrence: {
$: {'xsi:type': 'MinutelyRecurrence'},
MinutelyRecurrencePatternType: 'Interval',
MinuteInterval: '10'
},
RecurrenceType: 'Minutely',
RecurrenceRangeType: 'EndAfter',
StartDateTime: '2019-04-10T10:10:00.046+01:00',
Occurrences: '999999'
};
var exampleInteractions =[
{
Interaction: {
ObjectID: '1234'
}
}
];

beforeEach(function() {
FuelSoap = proxyquire('../../lib/fuel-soap', {
'./helpers': {
parseReqOptions: function() { return parsedOptions; }
}
});
soapRequestSpy = sinon.stub(FuelSoap.prototype, 'soapRequest');
});

afterEach(function() {
FuelSoap.prototype.soapRequest.restore();
});
simpleVerifyTestCases.forEach(function(testCase) {
it('should call soapRequest with correct ' + testCase.property, function() {
// Act
FuelSoap.prototype.schedule(
'Test',
exampleSchedule,
exampleInteractions,
'start',
{ options: true },
function() {});
// Assert
assert.equal(soapRequestSpy.args[0][0][testCase.property], testCase.expected);
});
});
it('should pass correct body to soapRequest', function() {

// Act
FuelSoap.prototype.schedule('Test', exampleSchedule, exampleInteractions,'start',{ options: true } , function() {});
// Assert
var actualObj = soapRequestSpy.args[0][0].req;
assert.equal(actualObj.ScheduleRequestMsg.Schedule, exampleSchedule);
assert.equal(actualObj.ScheduleRequestMsg.Interactions, exampleInteractions);
assert.ok(!actualObj.ScheduleRequestMsg.Options.QueryAllAccounts);
});

it('should pass callback to soapRequest when options', function() {
// Arrange
var sampleCallback = sinon.spy();

// Act
FuelSoap.prototype.schedule('Test', exampleSchedule, exampleInteractions,'start', { options: true }, sampleCallback);

// Assert
assert.ok(soapRequestSpy.calledWith(sinon.match.object, sampleCallback));
});

it('should add QueryAllAccounts to body when option passed', function() {
// Arrange
var sampleOptions = { queryAllAccounts: true };

// Act
FuelSoap.prototype.schedule('Test', exampleSchedule, exampleInteractions,'start',sampleOptions , function() {});

// Assert
var actualObj = soapRequestSpy.args[0][0].req;
assert.ok(actualObj.ScheduleRequestMsg.Options.QueryAllAccounts);
});
});

0 comments on commit df1e4e9

Please sign in to comment.