Skip to content

Commit c41f817

Browse files
mohitpubnubMohit Tejaniparfeon
authored
test: add missing unit and integration test (#472)
* unit tests * fix uuid encoding issue in presence apis * handling empty channel case for presence apis * lint fix for get_state.ts * fix test url for presence endpoints and fix typescript compilation error * additional integration tests * added integration tests for presence error cases * removed minor tweaks in presence endpoints for paramters structuring, rename message actions test directory * removed invalid case of where now, fix undefined uuid case in get state * updated package.json-lock and libs --------- Co-authored-by: Mohit Tejani <mohit.tejani@Mohits-MacBook-Pro.local> Co-authored-by: Serhii Mamontov <parfeon@me.com>
1 parent 84caf59 commit c41f817

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+13130
-14
lines changed

dist/web/pubnub.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11210,7 +11210,7 @@
1121011210
}
1121111211
get path() {
1121211212
const { keySet: { subscribeKey }, uuid, channels, } = this.parameters;
11213-
return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${uuid}`;
11213+
return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${encodeString(uuid !== null && uuid !== void 0 ? uuid : '')}`;
1121411214
}
1121511215
get queryParameters() {
1121611216
const { channelGroups } = this.parameters;
@@ -11243,7 +11243,7 @@
1124311243
const { keySet: { subscribeKey }, state, channels = [], channelGroups = [], } = this.parameters;
1124411244
if (!subscribeKey)
1124511245
return 'Missing Subscribe Key';
11246-
if (!state)
11246+
if (state === undefined)
1124711247
return 'Missing State';
1124811248
if ((channels === null || channels === void 0 ? void 0 : channels.length) === 0 && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) === 0)
1124911249
return 'Please provide a list of channels and/or channel-groups';
@@ -11309,7 +11309,7 @@
1130911309
const query = { heartbeat: `${heartbeat}` };
1131011310
if (channelGroups && channelGroups.length !== 0)
1131111311
query['channel-group'] = channelGroups.join(',');
11312-
if (state)
11312+
if (state !== undefined)
1131311313
query.state = JSON.stringify(state);
1131411314
return query;
1131511315
}

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/get_state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GetPresenceStateRequest extends request_1.AbstractRequest {
5959
}
6060
get path() {
6161
const { keySet: { subscribeKey }, uuid, channels, } = this.parameters;
62-
return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${uuid}`;
62+
return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${(0, utils_1.encodeString)(uuid !== null && uuid !== void 0 ? uuid : '')}`;
6363
}
6464
get queryParameters() {
6565
const { channelGroups } = this.parameters;

lib/core/endpoints/presence/heartbeat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class HeartbeatRequest extends request_1.AbstractRequest {
5959
const query = { heartbeat: `${heartbeat}` };
6060
if (channelGroups && channelGroups.length !== 0)
6161
query['channel-group'] = channelGroups.join(',');
62-
if (state)
62+
if (state !== undefined)
6363
query.state = JSON.stringify(state);
6464
return query;
6565
}

lib/core/endpoints/presence/set_state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SetPresenceStateRequest extends request_1.AbstractRequest {
3939
const { keySet: { subscribeKey }, state, channels = [], channelGroups = [], } = this.parameters;
4040
if (!subscribeKey)
4141
return 'Missing Subscribe Key';
42-
if (!state)
42+
if (state === undefined)
4343
return 'Missing State';
4444
if ((channels === null || channels === void 0 ? void 0 : channels.length) === 0 && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) === 0)
4545
return 'Please provide a list of channels and/or channel-groups';

package-lock.json

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

src/core/endpoints/presence/get_state.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { AbstractRequest } from '../../components/request';
99
import RequestOperation from '../../constants/operations';
1010
import { KeySet, Payload, Query } from '../../types/api';
1111
import * as Presence from '../../types/api/presence';
12-
import { encodeNames } from '../../utils';
12+
import { encodeNames, encodeString } from '../../utils';
1313

1414
// --------------------------------------------------------
1515
// ------------------------ Types -------------------------
@@ -103,7 +103,10 @@ export class GetPresenceStateRequest extends AbstractRequest<Presence.GetPresenc
103103
channels,
104104
} = this.parameters;
105105

106-
return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels ?? [], ',')}/uuid/${uuid}`;
106+
return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(
107+
channels ?? [],
108+
',',
109+
)}/uuid/${encodeString(uuid ?? '')}`;
107110
}
108111

109112
protected get queryParameters(): Query {

src/core/endpoints/presence/heartbeat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class HeartbeatRequest extends AbstractRequest<Presence.PresenceHeartbeat
9191
const query: Record<string, string> = { heartbeat: `${heartbeat}` };
9292

9393
if (channelGroups && channelGroups.length !== 0) query['channel-group'] = channelGroups.join(',');
94-
if (state) query.state = JSON.stringify(state);
94+
if (state !== undefined) query.state = JSON.stringify(state);
9595

9696
return query;
9797
}

src/core/endpoints/presence/set_state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class SetPresenceStateRequest extends AbstractRequest<Presence.SetPresenc
8080
} = this.parameters;
8181

8282
if (!subscribeKey) return 'Missing Subscribe Key';
83-
if (!state) return 'Missing State';
83+
if (state === undefined) return 'Missing State';
8484
if (channels?.length === 0 && channelGroups?.length === 0)
8585
return 'Please provide a list of channels and/or channel-groups';
8686
}

src/core/pubnub-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ export class PubNubCore<
25492549

25502550
const request = new GetPresenceStateRequest({
25512551
...parameters,
2552-
uuid: parameters.uuid ?? this._configuration.userId,
2552+
uuid: parameters.uuid ?? this._configuration.userId!,
25532553
keySet: this._configuration.keySet,
25542554
});
25552555
const logResponse = (response: Presence.GetPresenceStateResponse | null) => {

0 commit comments

Comments
 (0)