Skip to content

Commit

Permalink
Add send_completion_email and upsert params for importUsers
Browse files Browse the repository at this point in the history
add send_completion_email and upsert params for importUsers
  • Loading branch information
luisrudge authored Oct 23, 2018
2 parents 9bb7af4 + 5bdc2ad commit bcc359c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/management/JobsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ JobsManager.prototype.get = function(params, cb) {
* @example
* var params = {
* connection_id: '{CONNECTION_ID}',
* users: '{PATH_TO_USERS_FILE}'
* users: '{PATH_TO_USERS_FILE}',
* upsert: true, //optional
* send_completion_email: false //optional
* };
*
* management.jobs.get(params, function (err) {
Expand All @@ -118,11 +120,13 @@ JobsManager.prototype.get = function(params, cb) {
* }
* });
*
* @param {Object} data Users import data.
* @param {String} data.connectionId Connection for the users insertion.
* @param {String} data.users Path to the users data file.
* @param {String} data.users_json JSON data for the users.
* @param {Function} [cb] Callback function.
* @param {Object} data Users import data.
* @param {String} data.connectionId Connection for the users insertion.
* @param {String} data.users Path to the users data file.
* @param {String} data.users_json JSON data for the users.
* @param {String} data.upsert OPTIONAL: set to true to upsert users, defaults to false
* @param {String} data.send_completion_email OPTIONAL: defaults to true
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
Expand All @@ -134,6 +138,8 @@ JobsManager.prototype.importUsers = function(data, cb) {

var url = options.baseUrl + '/jobs/users-imports';
var method = 'POST';
var upsert = data.upsert === true ? 'true' : 'false';
var send_completion_email = data.send_completion_email === false ? 'false' : 'true';

var promise = options.tokenProvider.getAccessToken().then(function(access_token) {
return new Promise(function(resolve, reject) {
Expand All @@ -151,7 +157,9 @@ JobsManager.prototype.importUsers = function(data, cb) {
filename: data.users_json ? 'users.json' : data.users
}
},
connection_id: data.connection_id
connection_id: data.connection_id,
upsert: upsert,
send_completion_email: send_completion_email
}
},
function(err, res) {
Expand Down
70 changes: 69 additions & 1 deletion test/management/jobs.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('JobsManager', function() {
});
});

it('should have two parts: connection_id and users file', function(done) {
it('should have four parts: connection_id, users file, upsert and send_completion_email', function(done) {
nock.cleanAll();
var boundary = null;

Expand All @@ -248,6 +248,16 @@ describe('JobsManager', function() {
.to.exist.to.be.a('string')
.to.equal(data.connection_id);

// Validate the upsert param - default is false
expect(parts.upsert)
.to.exist.to.be.a('string')
.to.equal('false');

// Validate the send_completion_email param - default is true
expect(parts.send_completion_email)
.to.exist.to.be.a('string')
.to.equal('true');

// Validate the content type of the users JSON.
expect(parts.users)
.to.exist.to.be.a('string')
Expand All @@ -269,6 +279,64 @@ describe('JobsManager', function() {
});
});

it('should set upsert parameter correctly', function(done) {
nock.cleanAll();
var boundary = null;

var request = nock(API_URL)
.matchHeader('Content-Type', function(header) {
boundary = '--' + header.match(/boundary=([^\n]*)/)[1];

return true;
})
.post('/jobs/users-imports', function(body) {
var parts = extractParts(body, boundary);

// Validate the upsert param
expect(parts.upsert)
.to.exist.to.be.a('string')
.to.equal('true');

return true;
})
.reply(200);

this.jobs.importUsers(Object.assign({ upsert: true }, data)).then(function() {
expect(request.isDone()).to.be.true;

done();
});
});

it('should set send_completion_email parameter correctly', function(done) {
nock.cleanAll();
var boundary = null;

var request = nock(API_URL)
.matchHeader('Content-Type', function(header) {
boundary = '--' + header.match(/boundary=([^\n]*)/)[1];

return true;
})
.post('/jobs/users-imports', function(body) {
var parts = extractParts(body, boundary);

// Validate the upsert param
expect(parts.send_completion_email)
.to.exist.to.be.a('string')
.to.equal('false');

return true;
})
.reply(200);

this.jobs.importUsers(Object.assign({ send_completion_email: false }, data)).then(function() {
expect(request.isDone()).to.be.true;

done();
});
});

it('should include the token in the Authorization header', function(done) {
nock.cleanAll();

Expand Down

0 comments on commit bcc359c

Please sign in to comment.