diff --git a/.changeset/perfect-gorillas-remain.md b/.changeset/perfect-gorillas-remain.md new file mode 100644 index 00000000000..635969dc119 --- /dev/null +++ b/.changeset/perfect-gorillas-remain.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/rest-typings": patch +--- + +Fixes Omnichannel Rest API validation schemas that were flagging `Pagination` properties as invalid diff --git a/apps/meteor/tests/data/api-data.ts b/apps/meteor/tests/data/api-data.ts index 27ebcd72060..547237ff0ab 100644 --- a/apps/meteor/tests/data/api-data.ts +++ b/apps/meteor/tests/data/api-data.ts @@ -41,7 +41,7 @@ export const credentials: Credentials = { 'X-User-Id': undefined, } as unknown as Credentials; // FIXME -type PathWithoutPrefix = TPath extends `/v1/${infer U}` ? U : never; +export type PathWithoutPrefix = TPath extends `/v1/${infer U}` ? U : never; export function api>(path: TPath) { return `${prefix}${path}` as const; diff --git a/apps/meteor/tests/data/utils.ts b/apps/meteor/tests/data/utils.ts new file mode 100644 index 00000000000..ca6c85503d7 --- /dev/null +++ b/apps/meteor/tests/data/utils.ts @@ -0,0 +1,28 @@ +import type { Credentials } from '@rocket.chat/api-client'; +import type { Path } from '@rocket.chat/rest-typings'; +import { expect } from 'chai'; + +import { api, request, type PathWithoutPrefix } from './api-data'; + +export const pagination = >( + apiEndpoint: TPath, + credentials: Credentials, + extraQueryParams: Record = {}, +) => { + return request + .get(api(apiEndpoint)) + .set(credentials) + .query({ + ...extraQueryParams, + count: 10, + offset: 1, + sort: JSON.stringify({ _updatedAt: -1 }), + }) + .expect('content-type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('count').that.is.a('number'); + expect(res.body).to.have.property('offset').that.is.a('number'); + expect(res.body).to.have.property('total').that.is.a('number'); + }); +}; diff --git a/apps/meteor/tests/end-to-end/api/livechat/17-dashboards-ee.ts b/apps/meteor/tests/end-to-end/api/livechat/17-dashboards-ee.ts index ee2e102b099..19c515a742a 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/17-dashboards-ee.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/17-dashboards-ee.ts @@ -15,6 +15,7 @@ import { fetchInquiry, } from '../../../data/livechat/rooms'; import { updateEESetting, updatePermission, updateSetting } from '../../../data/permissions.helper'; +import { pagination } from '../../../data/utils'; import { IS_EE } from '../../../e2e/config/constants'; (IS_EE ? describe : describe.skip)('[EE] LIVECHAT - dashboards', () => { @@ -91,6 +92,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.agents[0]).to.have.a.property('username'); expect(body.agents[0]).to.have.a.property('averageServiceTimeInSeconds').that.is.a('number'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/agents/average-service-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/agents/total-service-time', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -151,6 +158,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.agents[0]).to.have.a.property('username'); expect(body.agents[0]).to.have.a.property('serviceTimeDuration').that.is.a('number'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/agents/total-service-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/agents/available-for-service-history', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -215,6 +228,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.agents[0]).to.have.a.property('username'); expect(body.agents[0]).to.have.a.property('availableTimeInSeconds').that.is.a('number'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/agents/available-for-service-history', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/amount-of-chats', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -274,6 +293,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('rooms').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/amount-of-chats', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/average-service-time', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -333,6 +358,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('averageServiceTimeInSeconds').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/average-service-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/average-chat-duration-time', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -392,6 +423,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('averageChatDurationTimeInSeconds').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/average-chat-duration-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/total-service-time', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -452,6 +489,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('serviceTimeDuration').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/total-service-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/average-waiting-time', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -511,6 +554,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('averageWaitingTimeInSeconds').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/average-waiting-time', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/total-transferred-chats', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -570,6 +619,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('numberOfTransferredRooms').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/total-transferred-chats', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/total-abandoned-chats', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -638,6 +693,12 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('abandonedRooms').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/total-abandoned-chats', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); describe('livechat/analytics/departments/percentage-abandoned-chats', () => { it('should return an "unauthorized error" when the user does not have the necessary permission', async () => { @@ -699,5 +760,11 @@ import { IS_EE } from '../../../e2e/config/constants'; expect(body.departments[0]).to.have.a.property('percentageOfAbandonedChats').that.is.a('number'); expect(body.departments[0]).to.have.a.property('_id'); }); + it('should accept pagination', async () => { + await pagination('livechat/analytics/departments/percentage-abandoned-chats', credentials, { + start: new Date().toISOString(), + end: new Date().toISOString(), + }); + }); }); }); diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 7ab919ca9c6..ec93ac58079 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -787,9 +787,6 @@ type LivechatDepartmentsByUnitIdProps = PaginatedRequest; const LivechatDepartmentsByUnitIdSchema = { type: 'object', properties: { - text: { - type: 'string', - }, count: { type: 'number', nullable: true, @@ -1626,6 +1623,15 @@ const LivechatAnalyticsAgentsAverageServiceTimeSchema = { end: { type: 'string', }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1696,6 +1702,15 @@ const LivechatAnalyticsAgentsTotalServiceTimeSchema = { end: { type: 'string', }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1724,6 +1739,15 @@ const LivechatAnalyticsAgentsAvailableForServiceHistorySchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1757,6 +1781,15 @@ const LivechatAnalyticsDepartmentsAmountOfChatsSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1785,6 +1818,15 @@ const LivechatAnalyticsDepartmentsAverageServiceTimeSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1813,6 +1855,15 @@ const LivechatAnalyticsDepartmentsAverageChatDurationTimeSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1840,6 +1891,15 @@ const LivechatAnalyticsDepartmentsTotalServiceTimeSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1868,6 +1928,15 @@ const LivechatAnalyticsDepartmentsAverageWaitingTimeSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1896,6 +1965,15 @@ const LivechatAnalyticsDepartmentsTotalTransferredChatsSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1924,6 +2002,15 @@ const LivechatAnalyticsDepartmentsTotalAbandonedChatsSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -1952,6 +2039,15 @@ const LivechatAnalyticsDepartmentsPercentageAbandonedChatsSchema = { type: 'string', nullable: true, }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, }, required: ['start', 'end'], additionalProperties: false, @@ -2837,7 +2933,6 @@ const GETLivechatVisitorsSearchSchema = { }, term: { type: 'string', - nullable: true, }, }, required: ['term'],