Skip to content

Commit 3f00028

Browse files
crgbaumgartajb413
authored andcommitted
Added partial channelGroups for chatEngine server tests. (#19)
* Added partial channelGroups for chatEngine server tests. * Rm unused CG functions for breaking coverage.
1 parent 9c7aa55 commit 3f00028

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/modules/pubnub.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ const pubnubInterface = {
114114
});
115115
});
116116
},
117+
channelGroups: {
118+
addChannels: (obj) => {
119+
return new Promise((resolve) => {
120+
if (typeof(obj) !== 'object' || (!obj.channels && !obj.channelGroup)) {
121+
let err = '[channelGroups.addChannels] expects Object with [channels] and \'channelGroup\'';
122+
throw Error(err);
123+
}
124+
125+
resolve({
126+
error: false,
127+
operation: "PNAddChannelsToGroupOperation",
128+
status: 200
129+
});
130+
});
131+
},
132+
removeChannels: (obj) => {
133+
return new Promise((resolve) => {
134+
if (typeof(obj) !== 'object' || (!obj.channelGroup)) {
135+
let err = '[channelGroups.addChannels] expects Object with [channels] and \'channelGroup\'';
136+
throw Error(err);
137+
}
138+
139+
resolve({
140+
error: false,
141+
operation: "PNRemoveChannelsFromGroupOperation",
142+
status: 200
143+
});
144+
});
145+
},
146+
},
117147
};
118148
pubnubInterface.fire = pubnubInterface.publish;
119149

test/endpointEventHandler.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,33 @@ export default (request, response) => {
226226
}).catch(testFail);
227227
}
228228

229+
if (request.channelGroups) {
230+
let pubnub = require('pubnub');
231+
let channelGroups = request.channelGroups;
232+
233+
if (channelGroups.addChannels) {
234+
return pubnub.channelGroups.addChannels(channelGroups.addChannels).then((value) => {
235+
if (value) {
236+
response.status = 200;
237+
return response.send(value)
238+
} else {
239+
return testFail(value);
240+
}
241+
})
242+
}
243+
244+
if (channelGroups.removeChannels) {
245+
return pubnub.channelGroups.removeChannels(channelGroups.removeChannels).then((value) => {
246+
if (value) {
247+
response.status = 200;
248+
return response.send(value)
249+
} else {
250+
return testFail(value);
251+
}
252+
})
253+
}
254+
}
255+
229256
response.status = 200;
230257
return response.send('Hello World!');
231258
};

test/unit.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,4 +903,65 @@ describe('#endpoint', () => {
903903
done();
904904
});
905905
});
906+
907+
it('adds a channel to channelGroups API', function(done) {
908+
let request = Object.assign({}, endpointRequestObject);
909+
let response = Object.assign({}, endpointResponseObject);
910+
911+
request.channelGroups = {
912+
addChannels: {
913+
channels: ['abcAsEasyAs123'],
914+
channelGroup: 'yahBoiMichealJackson',
915+
uuid: 'USER-MJ-0',
916+
}
917+
};
918+
919+
let correctResult = {
920+
body: {
921+
error: false,
922+
operation: "PNAddChannelsToGroupOperation",
923+
status: 200
924+
},
925+
status: 200
926+
}
927+
928+
endpoint(request, response).then((testResult) => {
929+
assert.equal(testResult.status, correctResult.status, 'status');
930+
assert.equal(testResult.body.error, correctResult.body.error, 'body.error');
931+
assert.equal(testResult.body.operation, correctResult.body.operation, 'body.operation');
932+
assert.equal(testResult.body.status, correctResult.body.status, 'body.status');
933+
done();
934+
});
935+
});
936+
937+
it('removes a channel from channelGroups API', function(done) {
938+
let request = Object.assign({}, endpointRequestObject);
939+
let response = Object.assign({}, endpointResponseObject);
940+
941+
request.channelGroups = {
942+
removeChannels: {
943+
channels: ['abcAsEasyAs123'],
944+
channelGroup: 'yahBoiMichealJackson',
945+
uuid: 'USER-MJ-1',
946+
}
947+
};
948+
949+
let correctResult = {
950+
body: {
951+
error: false,
952+
operation: "PNRemoveChannelsFromGroupOperation",
953+
status: 200
954+
},
955+
status: 200
956+
};
957+
958+
endpoint(request, response).then((testResult) => {
959+
assert.equal(testResult.status, correctResult.status, 'status');
960+
assert.equal(testResult.body.error, correctResult.body.error, 'body.error');
961+
assert.equal(testResult.body.operation, correctResult.body.operation, 'body.operation');
962+
assert.equal(testResult.body.status, correctResult.body.status, 'body.status');
963+
done();
964+
});
965+
966+
});
906967
});

0 commit comments

Comments
 (0)