Skip to content

Commit

Permalink
fix: Avoid using anyOf when validating settings array on `livechat/…
Browse files Browse the repository at this point in the history
…appearance` endpoint (#31052)
  • Loading branch information
KevLehman authored Nov 24, 2023
1 parent 1e865b7 commit 7f05c9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { API } from '../../../../api/server';
import { Livechat } from '../../lib/LivechatTyped';
import { settings, findOpenRoom, getExtraConfigInfo, findAgent } from '../lib/livechat';

const cachedSettings = mem(settings, { maxAge: 1000, cacheKey: JSON.stringify });
const cachedSettings = mem(settings, { maxAge: process.env.TEST_MODE === 'true' ? 1 : 1000, cacheKey: JSON.stringify });

API.v1.addRoute(
'livechat/config',
Expand Down
36 changes: 36 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/02-appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,41 @@ describe('LIVECHAT - appearance', function () {
.send([{ _id: 'Livechat_title', value: 'test' }])
.expect(200);
});
// Test for: https://github.com/ajv-validator/ajv/issues/1140
it('should update a boolean setting and keep it as boolean', async () => {
await request
.post(api('livechat/appearance'))
.set(credentials)
.send([{ _id: 'Livechat_registration_form', value: true }])
.expect(200);

// Get data from livechat/config
const { body } = await request.get(api('livechat/config')).set(credentials).expect(200);
expect(body.config.settings.registrationForm).to.be.true;
});
it('should update a boolean setting and keep it as boolean', async () => {
await request
.post(api('livechat/appearance'))
.set(credentials)
.send([{ _id: 'Livechat_registration_form', value: false }])
.expect(200);

// Get data from livechat/config
const { body } = await request.get(api('livechat/config')).set(credentials).expect(200);
expect(body.config.settings.registrationForm).to.be.false;
});
it('should update a number setting and keep it as number', async () => {
await updateSetting('Livechat_enable_message_character_limit', true);
await request
.post(api('livechat/appearance'))
.set(credentials)
.send([{ _id: 'Livechat_message_character_limit', value: 100 }])
.expect(200);

// Get data from livechat/config
const { body } = await request.get(api('livechat/config')).set(credentials).expect(200);
expect(body.config.settings.limitTextLength).to.be.equal(100);
await updateSetting('Livechat_enable_message_character_limit', false);
});
});
});
3 changes: 2 additions & 1 deletion packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,8 @@ const POSTLivechatAppearanceParamsSchema = {
type: 'string',
},
value: {
anyOf: [{ type: 'string' }, { type: 'boolean' }, { type: 'number' }],
// Be careful with anyOf - https://github.com/ajv-validator/ajv/issues/1140
type: ['string', 'boolean', 'number'],
},
},
required: ['_id', 'value'],
Expand Down

0 comments on commit 7f05c9c

Please sign in to comment.