Skip to content

Commit

Permalink
Merge pull request #93 from RamprasadAkella/master
Browse files Browse the repository at this point in the history
IO-9978-adding unit-tests
  • Loading branch information
alluriprasad authored Dec 27, 2019
2 parents ce0ba02 + 7185de5 commit b0360df
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ Extension.prototype.callFunction = function (functionOptions, extensionOptions,
return callback({statusCode: 422, errors: [errors.get('EXTENSION_INCORRECT_FUNCTION')]})
}

if (extensionOptions.lastExportDateTime) {
if (functionOptions.lastExportDateTime) {
try {
extensionOptions.lastExportDateTime = new Date(extensionOptions.lastExportDateTime)
functionOptions.lastExportDateTime = new Date(functionOptions.lastExportDateTime)
} catch (err) {
return callback({statusCode: 422, errors: [{ message: err.message, code: err.code }]})
}
}
if (extensionOptions.currentExportDateTime) {
if (functionOptions.currentExportDateTime) {
try {
extensionOptions.currentExportDateTime = new Date(extensionOptions.lastExportDateTime)
functionOptions.currentExportDateTime = new Date(functionOptions.currentExportDateTime)
} catch (err) {
return callback({statusCode: 422, errors: [{ message: err.message, code: err.code }]})
}
Expand Down
26 changes: 26 additions & 0 deletions test/test.callFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ describe('Extension callFunction tests', function () {
})
})

it('should parse "lastExportDateTime" and "currentExportDateTime" as dates ' +
'while sending request to hooks.', function (done) {
var extensionProperties = {
diy: true,
type: 'hook',
function: 'stringifyDateObject',
maxResponseSize: 2000
}

let lastExportDateTime = '2019-01-01T00:00:00.000Z'
let currentExportDateTime = '2020-01-01T00:00:00.000Z'
var options = {
key1: ['a'],
bearerToken: bearerToken,
lastExportDateTime: lastExportDateTime,
currentExportDateTime: currentExportDateTime
}

testUtil.callFunction(options, extensionProperties, function (four0xErrors, data) {
should.not.exist(four0xErrors)
data[0].lastExportDateTime.should.equal(lastExportDateTime)
data[0].currentExportDateTime.should.equal(currentExportDateTime)
done()
})
})

it('should invoke a hook which is part of an instance', function (done) {
var extensionProperties = {
type: 'hook',
Expand Down
10 changes: 10 additions & 0 deletions test/testModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ var testModule = {
return callback(null, [options])
},

stringifyDateObject: function (options, callback) {
if (options.lastExportDateTime && typeof options.lastExportDateTime === 'object') {
options.lastExportDateTime = options.lastExportDateTime.toISOString()
}
if (options.currentExportDateTime && typeof options.currentExportDateTime === 'object') {
options.currentExportDateTime = options.currentExportDateTime.toISOString()
}
return callback(null, [options])
},

echoResponse: function (options, callback) {
return callback(null, options.resp)
},
Expand Down

0 comments on commit b0360df

Please sign in to comment.