Skip to content

Commit a22ecd5

Browse files
author
Max Presman
committed
add validation for channels and or channel groups
1 parent adb5e84 commit a22ecd5

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

dist/web/pubnub.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,17 +5145,22 @@ return /******/ (function(modules) { // webpackBootstrap
51455145

51465146
function validateParams(modules, incomingParams) {
51475147
var config = modules.config;
5148-
var state = incomingParams.state;
5148+
var state = incomingParams.state,
5149+
_incomingParams$chann = incomingParams.channels,
5150+
channels = _incomingParams$chann === undefined ? [] : _incomingParams$chann,
5151+
_incomingParams$chann2 = incomingParams.channelGroups,
5152+
channelGroups = _incomingParams$chann2 === undefined ? [] : _incomingParams$chann2;
51495153

51505154

51515155
if (!state) return 'Missing State';
51525156
if (!config.subscribeKey) return 'Missing Subscribe Key';
5157+
if (channels.length === 0 && channelGroups.length === 0) return 'Please provide a list of channels and/or channel-groups';
51535158
}
51545159

51555160
function getURL(modules, incomingParams) {
51565161
var config = modules.config;
5157-
var _incomingParams$chann = incomingParams.channels,
5158-
channels = _incomingParams$chann === undefined ? [] : _incomingParams$chann;
5162+
var _incomingParams$chann3 = incomingParams.channels,
5163+
channels = _incomingParams$chann3 === undefined ? [] : _incomingParams$chann3;
51595164

51605165
var stringifiedChannels = channels.length > 0 ? channels.join(',') : ',';
51615166
return '/v2/presence/sub-key/' + config.subscribeKey + '/channel/' + _utils2.default.encodeString(stringifiedChannels) + '/uuid/' + config.UUID + '/data';
@@ -5173,8 +5178,8 @@ return /******/ (function(modules) { // webpackBootstrap
51735178

51745179
function prepareParams(modules, incomingParams) {
51755180
var state = incomingParams.state,
5176-
_incomingParams$chann2 = incomingParams.channelGroups,
5177-
channelGroups = _incomingParams$chann2 === undefined ? [] : _incomingParams$chann2;
5181+
_incomingParams$chann4 = incomingParams.channelGroups,
5182+
channelGroups = _incomingParams$chann4 === undefined ? [] : _incomingParams$chann4;
51785183

51795184
var params = {};
51805185

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/endpoints/presence/set_state.js

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/endpoints/presence/set_state.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/endpoints/presence/set_state.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export function getOperation(): string {
1010

1111
export function validateParams(modules: ModulesInject, incomingParams: SetStateArguments) {
1212
let { config } = modules;
13-
let { state } = incomingParams;
13+
let { state, channels = [], channelGroups = [] } = incomingParams;
1414

1515
if (!state) return 'Missing State';
1616
if (!config.subscribeKey) return 'Missing Subscribe Key';
17+
if (channels.length === 0 && channelGroups.length === 0) return 'Please provide a list of channels and/or channel-groups';
1718
}
1819

1920
export function getURL(modules: ModulesInject, incomingParams: SetStateArguments): string {

test/integration/operations/stateSetting.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ describe('setting state operation', () => {
2323
});
2424

2525
describe('#setState', () => {
26+
it('fails if no channels are provided', (done) => {
27+
pubnub.setState({ state: { hello: 'there' } }, (status) => {
28+
assert.equal(status.error, true);
29+
assert.equal(status.message, 'Please provide a list of channels and/or channel-groups');
30+
done();
31+
});
32+
});
33+
2634
it('supports updating for one channel', (done) => {
2735
const scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/uuid/myUUID/data')
2836
.query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', state: '{"hello":"there"}' })

0 commit comments

Comments
 (0)