Skip to content

Commit

Permalink
fix: Single Business hours not working when start/end are on differen…
Browse files Browse the repository at this point in the history
…t days (#30765)
  • Loading branch information
KevLehman authored Nov 24, 2023
1 parent ad8ef5a commit 38c5302
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/LivechatBusinessHours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class LivechatBusinessHoursRaw extends BaseRaw<ILivechatBusinessHour> imp
active: true,
workHours: {
$elemMatch: {
$or: [{ 'start.cron.dayOfWeek': day, 'finish.cron.dayOfWeek': day }],
$or: [{ 'start.cron.dayOfWeek': day }, { 'finish.cron.dayOfWeek': day }],
open: true,
},
},
Expand Down
44 changes: 44 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ describe('LIVECHAT - business hours', function () {

let defaultBhId: any;
describe('[CE] livechat/business-hour', () => {
after(async () => {
await saveBusinessHour({
...defaultBhId,
timezone: {
name: 'America/Sao_Paulo',
utc: '-03:00',
},
workHours: getWorkHours(true),
});
});

it('should fail when user doesnt have view-livechat-business-hours permission', async () => {
await removePermissionFromAllRoles('view-livechat-business-hours');
const response = await request.get(api('livechat/business-hour')).set(credentials).expect(403);
Expand Down Expand Up @@ -100,6 +111,39 @@ describe('LIVECHAT - business hours', function () {

expect(body).to.have.property('success', true);
});
it('should save a default business hour with proper timezone settings', async () => {
await saveBusinessHour({
...defaultBhId,
timezone: {
name: 'Asia/Kolkata',
utc: '+05:30',
},
workHours: getWorkHours(true),
timezoneName: 'Asia/Kolkata',
});

const { body } = await request
.get(api('livechat/business-hour'))
.set(credentials)
.query({ type: LivechatBusinessHourTypes.DEFAULT })
.expect(200);

expect(body.success).to.be.true;
expect(body.businessHour).to.be.an('object');
expect(body.businessHour.timezone).to.be.an('object').that.has.property('name').that.is.equal('Asia/Kolkata');
expect(body.businessHour.workHours).to.be.an('array').with.lengthOf(7);

const { workHours } = body.businessHour;

expect(workHours[0].day).to.be.equal('Sunday');
expect(workHours[0].start.utc.dayOfWeek).to.be.equal('Saturday');
expect(workHours[0].finish.utc.dayOfWeek).to.be.equal('Sunday');
});

it('should allow agents to be available', async () => {
const { body } = await makeAgentAvailable(credentials);
expect(body).to.have.property('success', true);
});
});

(IS_EE ? describe : describe.skip)('[EE] livechat/business-hour', () => {
Expand Down

0 comments on commit 38c5302

Please sign in to comment.