mirror of https://github.com/calzoneman/sync.git
Handle the case where no socket.io ack exists
This commit is contained in:
parent
9dc82ad444
commit
0613083eb0
|
@ -2,6 +2,7 @@ var ChannelModule = require("./module");
|
|||
var Poll = require("../poll").Poll;
|
||||
import { ValidationError } from '../errors';
|
||||
import Config from '../config';
|
||||
import { ackOrErrorMsg } from '../util/ack';
|
||||
|
||||
const TYPE_NEW_POLL = {
|
||||
title: "string",
|
||||
|
@ -160,6 +161,8 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) {
|
|||
return;
|
||||
}
|
||||
|
||||
ack = ackOrErrorMsg(ack, user);
|
||||
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
ack({
|
||||
error: {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
export function ackOrErrorMsg(ack, user) {
|
||||
if (typeof ack === 'function') {
|
||||
return ack;
|
||||
}
|
||||
|
||||
return (result) => {
|
||||
if (result.error) {
|
||||
user.socket.emit('errorMsg', { msg: result.error.message });
|
||||
}
|
||||
};
|
||||
}
|
|
@ -91,6 +91,10 @@ describe('PollModule', () => {
|
|||
let fakeUser = {
|
||||
getName() {
|
||||
return 'testUser';
|
||||
},
|
||||
socket: {
|
||||
emit() {
|
||||
}
|
||||
}
|
||||
};
|
||||
let pollModule = new PollModule(fakeChannel);
|
||||
|
@ -141,5 +145,30 @@ describe('PollModule', () => {
|
|||
assert.equal(ackResult.error.message, 'Polls are limited to a maximum of 50 options.');
|
||||
});
|
||||
});
|
||||
|
||||
it('handles a rejection with no ack provided by socket.io', () => {
|
||||
fakeChannel.broadcastToRoom = (event, data, room) => {
|
||||
assert(false, 'Expected no events to be sent');
|
||||
};
|
||||
fakeChannel.broadcastAll = (event) => {
|
||||
assert(false, 'Expected no events to be sent');
|
||||
};
|
||||
let sentErrorMsg = false;
|
||||
fakeUser.socket.emit = (event, data) => {
|
||||
if (event === 'errorMsg') {
|
||||
sentErrorMsg = true;
|
||||
}
|
||||
};
|
||||
const options = [];
|
||||
for (let i = 0; i < 200; i++) {
|
||||
options.push('option ' + i);
|
||||
}
|
||||
pollModule.handleNewPoll(fakeUser, {
|
||||
title: 'test poll',
|
||||
opts: options,
|
||||
obscured: false
|
||||
});
|
||||
assert(sentErrorMsg, 'Expected to send errorMsg since ack was missing');
|
||||
});
|
||||
})
|
||||
});
|
Loading…
Reference in New Issue