fix: `default` field is not returned from the `setDefault` endpoint when setting to false (#30194)

pull/30235/head
Matheus Barbosa Silva 2 years ago committed by GitHub
parent 203304782f
commit ba24f3c21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .changeset/real-pets-visit.md
  2. 18
      apps/meteor/server/models/raw/Rooms.ts
  3. 60
      apps/meteor/tests/end-to-end/api/02-channels.js
  4. 2
      packages/core-typings/src/IRoom.ts

@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/core-typings": patch
---
Fixed `default` field not being returned from the `setDefault` endpoints when setting to false

@ -1349,7 +1349,7 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
t: {
$in: types,
},
...(defaultValue ? { default: true } : { default: { $exists: false } }),
...(defaultValue ? { default: true } : { default: { $ne: true } }),
};
return this.find(query, options);
@ -1763,17 +1763,11 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
saveDefaultById(_id: IRoom['_id'], defaultValue: boolean): Promise<UpdateResult> {
const query: Filter<IRoom> = { _id };
const update: UpdateFilter<IRoom> = defaultValue
? {
$set: {
default: true,
},
}
: {
$unset: {
default: 1,
},
};
const update: UpdateFilter<IRoom> = {
$set: {
default: defaultValue,
},
};
return this.updateOne(query, update);
}

@ -1573,25 +1573,49 @@ describe('[Channels]', function () {
});
});
it('/channels.setDefault', async () => {
const roomInfo = await getRoomInfo(channel._id);
describe('/channels.setDefault', () => {
it('should set channel as default', async () => {
const roomInfo = await getRoomInfo(channel._id);
return request
.post(api('channels.setDefault'))
.set(credentials)
.send({
roomId: channel._id,
default: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('channel._id');
expect(res.body).to.have.nested.property('channel.name', `EDITED${apiPublicChannelName}`);
expect(res.body).to.have.nested.property('channel.t', 'c');
expect(res.body).to.have.nested.property('channel.msgs', roomInfo.channel.msgs);
});
return request
.post(api('channels.setDefault'))
.set(credentials)
.send({
roomId: channel._id,
default: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('channel._id');
expect(res.body).to.have.nested.property('channel.name', `EDITED${apiPublicChannelName}`);
expect(res.body).to.have.nested.property('channel.t', 'c');
expect(res.body).to.have.nested.property('channel.msgs', roomInfo.channel.msgs);
expect(res.body).to.have.nested.property('channel.default', true);
});
});
it('should unset channel as default', async () => {
const roomInfo = await getRoomInfo(channel._id);
return request
.post(api('channels.setDefault'))
.set(credentials)
.send({
roomId: channel._id,
default: false,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('channel._id');
expect(res.body).to.have.nested.property('channel.name', `EDITED${apiPublicChannelName}`);
expect(res.body).to.have.nested.property('channel.t', 'c');
expect(res.body).to.have.nested.property('channel.msgs', roomInfo.channel.msgs);
expect(res.body).to.have.nested.property('channel.default', false);
});
});
});
it('/channels.leave', async () => {

@ -23,7 +23,7 @@ export interface IRoom extends IRocketChatRecord {
name?: string;
fname?: string;
msgs: number;
default?: true;
default?: boolean;
broadcast?: true;
featured?: true;
announcement?: string;

Loading…
Cancel
Save