regression: Room update via apps engine failing with `Duplicated index key` error (#35878)

pull/35888/head
Kevin Aleman 8 months ago committed by GitHub
parent 2caf06ad9d
commit d4eef32b9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      apps/meteor/app/apps/server/converters/rooms.js
  2. 13
      apps/meteor/tests/unit/app/apps/server/mocks/models/Rooms.mock.js
  3. 57
      apps/meteor/tests/unit/app/apps/server/rooms.tests.ts

@ -137,12 +137,12 @@ export class AppRoomsConverter {
const newRoom = {
...(room.id && { _id: room.id }),
t: room.type,
ts: room.createdAt,
msgs: room.messageCount || 0,
_updatedAt: room.updatedAt,
...(typeof room.type !== 'undefined' && { t: room.type }),
...(typeof room.createdAt !== 'undefined' && { ts: room.createdAt }),
...(typeof room.messageCount !== 'undefined' && { msgs: room.messageCount || 0 }),
...(typeof room.updatedAt !== 'undefined' && { _updatedAt: room.updatedAt }),
...(room.displayName && { fname: room.displayName }),
...(room.type !== 'd' && { name: room.slugifiedName }),
...(room.type !== 'd' && room.slugifiedName && { name: room.slugifiedName }),
...(room.members && { members: room.members }),
...(typeof room.isDefault !== 'undefined' && { default: room.isDefault }),
...(typeof room.isReadOnly !== 'undefined' && { ro: room.isReadOnly }),

@ -115,6 +115,19 @@ export class RoomsMock extends BaseModelMock {
updatedAt: new Date('2019-04-10T17:44:34.931Z'),
},
GENERALPartialWithOptionalProps: {
id: 'GENERAL',
slugifiedName: 'general',
displaySystemMessages: true,
updatedAt: new Date('2019-04-10T17:44:34.931Z'),
messageCount: 40,
type: 'c',
},
UpdatedRoom: {
customFields: { custom: 'field' },
},
LivechatRoom: {
id: 'LivechatRoom',
slugifiedName: undefined,

@ -112,11 +112,66 @@ describe('The AppMessagesConverter instance', () => {
expect(rocketchatRoom).to.have.property('_id', appRoom.id);
expect(rocketchatRoom).to.have.property('name', appRoom.slugifiedName);
expect(rocketchatRoom).to.have.property('sysMes', appRoom.displaySystemMessages);
expect(rocketchatRoom).to.have.property('msgs', 0);
expect(rocketchatRoom).to.have.property('_updatedAt', appRoom.updatedAt);
expect(rocketchatRoom).to.not.have.property('msgs');
expect(rocketchatRoom).to.not.have.property('ro');
expect(rocketchatRoom).to.not.have.property('default');
expect(rocketchatRoom).to.not.have.property('t');
});
it('should return a proper schema when receiving a partial object', async () => {
const appRoom = RoomsMock.convertedData.GENERALPartialWithOptionalProps as unknown as IAppsRoom;
const rocketchatRoom = await roomConverter.convertAppRoom(appRoom, true);
expect(rocketchatRoom).to.have.property('_id', appRoom.id);
expect(rocketchatRoom).to.have.property('name', appRoom.slugifiedName);
expect(rocketchatRoom).to.have.property('sysMes', appRoom.displaySystemMessages);
expect(rocketchatRoom).to.have.property('_updatedAt', appRoom.updatedAt);
expect(rocketchatRoom).to.have.property('msgs', appRoom.messageCount);
expect(rocketchatRoom).to.have.property('t', 'c');
expect(rocketchatRoom).to.not.have.property('ro');
expect(rocketchatRoom).to.not.have.property('default');
});
it('should not include properties that are not present in the app room', async () => {
const appRoom = RoomsMock.convertedData.UpdatedRoom as unknown as IAppsRoom;
const rocketchatRoom = await roomConverter.convertAppRoom(appRoom, true);
expect(rocketchatRoom).to.have.property('customFields');
expect(rocketchatRoom).to.not.have.property('_id');
expect(rocketchatRoom).to.not.have.property('t');
});
it('should not include name as undefined if the room doesnt have a name property', async () => {
const appRoom = RoomsMock.convertedData.UpdatedRoom as unknown as IAppsRoom;
const rocketchatRoom = await roomConverter.convertAppRoom(appRoom, true);
expect(rocketchatRoom.name).to.be.undefined;
});
it('should include a name if the source room has slugifiedName property', async () => {
const appRoom = RoomsMock.convertedData.GENERALPartialWithOptionalProps as unknown as IAppsRoom;
const rocketchatRoom = await roomConverter.convertAppRoom(appRoom, true);
expect(rocketchatRoom.name).to.equal(appRoom.slugifiedName);
});
it('should not use _unmappedProperties when the room is a partial object', async () => {
const appRoom = RoomsMock.convertedData.GENERALPartialWithOptionalProps as unknown as IAppsRoom;
// @ts-expect-error - _unmappedProperties
const rocketchatRoom = await roomConverter.convertAppRoom({ ...appRoom, _unmappedProperties_: { unmapped: 'property' } }, true);
expect(rocketchatRoom).to.not.have.property('unmapped');
});
it('should use _unmappedProperties when the room is a partial object', async () => {
const appRoom = RoomsMock.convertedData.GENERALPartialWithOptionalProps as unknown as IAppsRoom;
// @ts-expect-error - _unmappedProperties
const rocketchatRoom = await roomConverter.convertAppRoom({ ...appRoom, _unmappedProperties_: { unmapped: 'property' } }, false);
expect(rocketchatRoom).to.have.property('unmapped', 'property');
});
});
});

Loading…
Cancel
Save