mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: isFinite check for room assertion, more test migrating
This commit is contained in:
@@ -107,6 +107,10 @@ Assert.folderName = helpers.try(async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Assert.room = helpers.try(async (req, res, next) => {
|
Assert.room = helpers.try(async (req, res, next) => {
|
||||||
|
if (!isFinite(req.params.roomId)) {
|
||||||
|
return controllerHelpers.formatApiResponse(400, res, new Error('[[error:invalid-data]]'));
|
||||||
|
}
|
||||||
|
|
||||||
const [exists, inRoom] = await Promise.all([
|
const [exists, inRoom] = await Promise.all([
|
||||||
await messaging.roomExists(req.params.roomId),
|
await messaging.roomExists(req.params.roomId),
|
||||||
await messaging.isUserInRoom(req.uid, req.params.roomId),
|
await messaging.isUserInRoom(req.uid, req.params.roomId),
|
||||||
|
|||||||
@@ -115,11 +115,9 @@ describe('Messaging Library', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('rooms', () => {
|
describe('rooms', () => {
|
||||||
it('should fail to create a new chat room with invalid data', (done) => {
|
it('should fail to create a new chat room with invalid data', async () => {
|
||||||
socketModules.chats.newRoom({ uid: mocks.users.foo.uid }, null, (err) => {
|
const { body } = await callv3API('post', '/chats', {}, 'foo');
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.equal(body.status.message, await translator.translate('[[error:required-parameters-missing, uids]]'));
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return rate limit error on second try', async () => {
|
it('should return rate limit error on second try', async () => {
|
||||||
@@ -360,17 +358,12 @@ describe('Messaging Library', () => {
|
|||||||
assert(!isInRoom);
|
assert(!isInRoom);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to send a message to room with invalid data', (done) => {
|
it('should fail to send a message to room with invalid data', async () => {
|
||||||
socketModules.chats.send({ uid: mocks.users.foo.uid }, null, (err) => {
|
let { body } = await callv3API('post', `/chats/abc`, { message: 'test' }, 'foo');
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.strictEqual(body.status.message, await translator.translate('[[error:invalid-data]]'));
|
||||||
socketModules.chats.send({ uid: mocks.users.foo.uid }, { roomId: null }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
({ body } = await callv3API('post', `/chats/1`, {}, 'foo'));
|
||||||
socketModules.chats.send({ uid: null }, { roomId: 1 }, (err) => {
|
assert.strictEqual(body.status.message, await translator.translate('[[error:required-parameters-missing, message]]'));
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to send chat if content is empty', async () => {
|
it('should fail to send chat if content is empty', async () => {
|
||||||
@@ -548,30 +541,19 @@ describe('Messaging Library', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to load room with invalid-data', (done) => {
|
it('should fail to load room with invalid-data', async () => {
|
||||||
socketModules.chats.loadRoom({ uid: mocks.users.foo.uid }, null, (err) => {
|
const { body } = await callv3API('get', `/chats/abc`, {}, 'foo');
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.strictEqual(body.status.message, await translator.translate('[[error:invalid-data]]'));
|
||||||
socketModules.chats.loadRoom({ uid: mocks.users.foo.uid }, { roomId: null }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to load room if user is not in', (done) => {
|
it('should fail to load room if user is not in', async () => {
|
||||||
socketModules.chats.loadRoom({ uid: 0 }, { roomId: roomId }, (err) => {
|
const { body } = await callv3API('get', `/chats/${roomId}`, {}, 'baz');
|
||||||
assert.equal(err.message, '[[error:no-privileges]]');
|
assert.strictEqual(body.status.message, await translator.translate('[[error:no-privileges]]'));
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load chat room', (done) => {
|
it('should load chat room', async () => {
|
||||||
socketModules.chats.loadRoom({ uid: mocks.users.foo.uid }, { roomId: roomId }, (err, data) => {
|
const { body } = await callv3API('get', `/chats/${roomId}`, {}, 'foo');
|
||||||
assert.ifError(err);
|
assert.strictEqual(body.response.roomName, 'new room name');
|
||||||
assert(data);
|
|
||||||
assert.equal(data.roomName, 'new room name');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if user is dnd', (done) => {
|
it('should return true if user is dnd', (done) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user