Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-encoding of 'profile' parameter #392

Merged
merged 1 commit into from Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/clients/helpers.js
Expand Up @@ -37,6 +37,14 @@ var assignApiArgs = function assignApiArgs(target, source) {
} else {
target[key] = JSON.stringify(val);
}
// For the web API, this should always be a JSON-encoded object, see:
// https://api.slack.com/methods/users.profile.set or https://api.slack.com/methods/users.profile.get
} else if (key === 'profile') {
if (isString(val)) {
target[key] = val;
} else {
target[key] = JSON.stringify(val);
}
} else if (key !== 'opts') {
target[key] = val;
}
Expand Down
20 changes: 20 additions & 0 deletions test/clients/helpers.js
Expand Up @@ -51,6 +51,15 @@ describe('Client Helpers', function () {
});
});

it('JSON encodes user profile if it is not already encoded', function () {
var required = { profile: { status_text: 'testing', status_emoji: ':construction_worker:' } };

expect(helpers.getAPICallData('test', required, null)).to.be.deep.equal({
profile: '{"status_text":"testing","status_emoji":":construction_worker:"}',
token: 'test'
});
});

it('leaves attachments alone if they are already encoded', function () {
var required = { attachments: '["a","b","c"]' };

Expand All @@ -59,6 +68,17 @@ describe('Client Helpers', function () {
token: 'test'
});
});

it('leaves user profile alone if it is already encoded', function () {
var required = { profile:
'{"status_text":"testing","status_emoji":":construction_worker:"}'
};

expect(helpers.getAPICallData('test', required, null)).to.be.deep.equal({
profile: '{"status_text":"testing","status_emoji":":construction_worker:"}',
token: 'test'
});
});
});

describe('#getAPICallArgs()', function () {
Expand Down