-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: customFields ignored in livechat room creation (#33047)
- Loading branch information
1 parent
a40541b
commit 7e2facc
Showing
4 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': patch | ||
--- | ||
|
||
Fixed: Custom fields in extraData now correctly added to extraRoomInfo by livechat.beforeRoom callback during livechat room creation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isPlainObject(value: unknown) { | ||
return value !== null && typeof value === 'object' && !Array.isArray(value); | ||
} |
52 changes: 52 additions & 0 deletions
52
apps/meteor/tests/unit/server/livechat/hooks/beforeNewRoom.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import proxyquire from 'proxyquire'; | ||
import sinon from 'sinon'; | ||
|
||
import { callbacks } from '../../../../../lib/callbacks'; | ||
|
||
const findStub = sinon.stub(); | ||
|
||
proxyquire.noCallThru().load('../../../../../ee/app/livechat-enterprise/server/hooks/beforeNewRoom.ts', { | ||
'meteor/meteor': { | ||
Meteor: { | ||
Error, | ||
}, | ||
}, | ||
'@rocket.chat/models': { | ||
OmnichannelServiceLevelAgreements: { | ||
findOneByIdOrName: findStub, | ||
}, | ||
}, | ||
}); | ||
|
||
describe('livechat.beforeRoom', () => { | ||
beforeEach(() => findStub.withArgs('high').resolves({ _id: 'high' }).withArgs('invalid').resolves(null)); | ||
|
||
it('should return roomInfo with customFields when provided', async () => { | ||
const roomInfo = { name: 'test' }; | ||
const extraData = { customFields: { test: 'test' } }; | ||
const result = await callbacks.run('livechat.beforeRoom', roomInfo, extraData); | ||
expect(result).to.deep.equal({ ...roomInfo, customFields: extraData.customFields }); | ||
}); | ||
|
||
it('should throw an error when provided with an invalid sla', async () => { | ||
const roomInfo = { name: 'test' }; | ||
const extraData = { customFields: { test: 'test' }, sla: 'invalid' }; | ||
await expect(callbacks.run('livechat.beforeRoom', roomInfo, extraData)).to.be.rejectedWith(Error, 'error-invalid-sla'); | ||
}); | ||
|
||
it('should not include field in roomInfo when extraData has field other than customFields, sla', async () => { | ||
const roomInfo = { name: 'test' }; | ||
const extraData = { customFields: { test: 'test' }, sla: 'high' }; | ||
const result = await callbacks.run('livechat.beforeRoom', roomInfo, extraData); | ||
expect(result).to.deep.equal({ ...roomInfo, customFields: extraData.customFields, slaId: 'high' }); | ||
}); | ||
|
||
it('should return roomInfo with no customFields when customFields is not an object', async () => { | ||
const roomInfo = { name: 'test' }; | ||
const extraData = { customFields: 'not an object' }; | ||
const result = await callbacks.run('livechat.beforeRoom', roomInfo, extraData); | ||
expect(result).to.deep.equal({ ...roomInfo }); | ||
}); | ||
}); |