fix: Omni AJV schemas ignoring `Pagination` properties (#36111)

pull/36035/head^2
Kevin Aleman 7 months ago committed by GitHub
parent 5cd7b20d5f
commit da288f69a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .changeset/perfect-gorillas-remain.md
  2. 2
      apps/meteor/tests/data/api-data.ts
  3. 28
      apps/meteor/tests/data/utils.ts
  4. 67
      apps/meteor/tests/end-to-end/api/livechat/17-dashboards-ee.ts
  5. 103
      packages/rest-typings/src/v1/omnichannel.ts

@ -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

@ -41,7 +41,7 @@ export const credentials: Credentials = {
'X-User-Id': undefined,
} as unknown as Credentials; // FIXME
type PathWithoutPrefix<TPath> = TPath extends `/v1/${infer U}` ? U : never;
export type PathWithoutPrefix<TPath> = TPath extends `/v1/${infer U}` ? U : never;
export function api<TPath extends PathWithoutPrefix<Path>>(path: TPath) {
return `${prefix}${path}` as const;

@ -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 = <TPath extends PathWithoutPrefix<Path>>(
apiEndpoint: TPath,
credentials: Credentials,
extraQueryParams: Record<string, any> = {},
) => {
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');
});
};

@ -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(),
});
});
});
});

@ -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'],

Loading…
Cancel
Save