Skip to content

Commit

Permalink
Fix updateCustomTextByLanguage (#638)
Browse files Browse the repository at this point in the history
Fixes updateCustomTextByLanguage, previously the payload was being added to the url and not the body fo the request.  Test included
  • Loading branch information
davidpatrick authored Jul 27, 2021
1 parent 6c3caac commit b27149a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/management/PromptsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ PromptsManager.prototype.getCustomTextByLanguage = function(params, cb) {
*/
PromptsManager.prototype.updateCustomTextByLanguage = function(params, cb) {
params = params || {};
options = {};

if (!params.prompt || typeof params.prompt !== 'string') {
throw new ArgumentError('The prompt parameter must be a string');
Expand All @@ -200,11 +201,14 @@ PromptsManager.prototype.updateCustomTextByLanguage = function(params, cb) {
throw new ArgumentError('The body parameter must be an object');
}

options.prompt = params.prompt;
options.language = params.language;

if (cb && cb instanceof Function) {
return this.customTextByLanguage.update(params, params.body, cb);
return this.customTextByLanguage.update(options, params.body, cb);
}

return this.customTextByLanguage.update(params, params.body);
return this.customTextByLanguage.update(options, params.body);
};

module.exports = PromptsManager;
21 changes: 19 additions & 2 deletions test/management/prompts.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe('PromptsManager', function() {
var params = {
prompt: 'test',
language: 'english',
body: {}
body: { login: { title: 'Hello!' } }
};

beforeEach(function() {
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('PromptsManager', function() {
});
});

it('shoushould perform a GET request to /api/v2/prompts/test/custom-text/english', function(done) {
it('should perform a PUT request to /api/v2/prompts/test/custom-text/english', function(done) {
var request = this.request;

this.prompts.updateCustomTextByLanguage(params).then(function() {
Expand All @@ -388,5 +388,22 @@ describe('PromptsManager', function() {
done();
});
});

it('should send the payload to the body', function(done) {
nock.cleanAll();

var request = nock(API_URL)
.put(
'/prompts/test/custom-text/english',
body => body && body.login && body.login.title === 'Hello!'
)
.reply(200);

this.prompts.updateCustomTextByLanguage(params).then(function() {
expect(request.isDone()).to.be.true;

done();
});
});
});
});

0 comments on commit b27149a

Please sign in to comment.