diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index 4ed00ac820..d268bc511e 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -191,7 +191,7 @@ module.exports = function (Messaging) { Messaging.renameRoom = async function (uid, roomId, newName) { if (!newName) { - throw new Error('[[error:invalid-name]]'); + throw new Error('[[error:invalid-data]]'); } newName = newName.trim(); if (newName.length > 75) { diff --git a/test/messaging.js b/test/messaging.js index 5064a156b0..b61aab20a7 100644 --- a/test/messaging.js +++ b/test/messaging.js @@ -521,24 +521,17 @@ describe('Messaging Library', () => { }); }); - it('should fail to rename room with invalid data', (done) => { - socketModules.chats.renameRoom({ uid: mocks.users.foo.uid }, null, (err) => { - assert.equal(err.message, '[[error:invalid-data]]'); - socketModules.chats.renameRoom({ uid: mocks.users.foo.uid }, { roomId: null }, (err) => { - assert.equal(err.message, '[[error:invalid-data]]'); - socketModules.chats.renameRoom({ uid: mocks.users.foo.uid }, { roomId: roomId, newName: null }, (err) => { - assert.equal(err.message, '[[error:invalid-data]]'); - done(); - }); - }); - }); + it('should fail to rename room with invalid data', async () => { + let { body } = await callv3API('put', `/chats/${roomId}`, { name: null }, 'foo'); + assert.strictEqual(body.status.message, await translator.translate('[[error:invalid-data]]')); + + ({ body } = await callv3API('put', `/chats/${roomId}`, {}, 'foo')); + assert.strictEqual(body.status.message, await translator.translate('[[error:required-parameters-missing, name]]')); }); - it('should rename room', (done) => { - socketModules.chats.renameRoom({ uid: mocks.users.foo.uid }, { roomId: roomId, newName: 'new room name' }, (err) => { - assert.ifError(err); - done(); - }); + it('should rename room', async () => { + const { statusCode } = await callv3API('put', `/chats/${roomId}`, { name: 'new room name' }, 'foo'); + assert.strictEqual(statusCode, 200); }); it('should send a room-rename system message when a room is renamed', (done) => {