snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,243 @@
/* eslint-disable new-cap */
import { expect } from 'chai';
import sinon from 'sinon';
import { ChartData } from '../../../../../server/services/omnichannel-analytics/ChartData';
describe('ChartData Analytics', () => {
describe('isActionAllowed', () => {
it('should return false if no action is provided', () => {
const chart = new ChartData({} as any);
expect(chart.isActionAllowed(undefined)).to.be.false;
});
it('should return false if an invalid action is provided', () => {
const chart = new ChartData({} as any);
expect(chart.isActionAllowed('invalid_action')).to.be.false;
});
it('should return true if a valid action is provided', () => {
const chart = new ChartData({} as any);
expect(chart.isActionAllowed('Total_conversations')).to.be.true;
});
});
describe('callAction', () => {
it('should call the correct action', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [],
getAnalyticsMetricsBetweenDate: () => [],
getTotalConversationsBetweenDate: () => 0,
} as any);
expect(await chart.callAction('Total_conversations', {} as any)).to.be.equal(0);
});
it('should throw an error if the action is invalid', async () => {
const chart = new ChartData({} as any);
try {
// @ts-expect-error - Invalid action
await chart.callAction('invalid_action', {} as any);
} catch (e: any) {
expect(e.message).to.be.equal('Invalid action');
}
});
it('should call the correct action with the correct parameters', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [],
getAnalyticsMetricsBetweenDate: () => [],
getTotalConversationsBetweenDate: () => 0,
} as any);
const spy = sinon.spy(chart, 'Total_conversations');
const spy2 = sinon.spy(chart, 'Avg_chat_duration');
const spy3 = sinon.spy(chart, 'Total_messages');
const spy4 = sinon.spy(chart, 'Avg_first_response_time');
const spy5 = sinon.spy(chart, 'Avg_reaction_time');
await chart.callAction('Total_conversations', {} as any);
expect(spy.calledOnce).to.be.true;
await chart.callAction('Avg_chat_duration', {} as any);
expect(spy2.calledOnce).to.be.true;
await chart.callAction('Total_messages', {} as any);
expect(spy3.calledOnce).to.be.true;
await chart.callAction('Avg_first_response_time', {} as any);
expect(spy4.calledOnce).to.be.true;
await chart.callAction('Avg_reaction_time', {} as any);
expect(spy5.calledOnce).to.be.true;
});
});
describe('Total_conversations', () => {
it('should return the total number of conversations', async () => {
const chart = new ChartData({
getTotalConversationsBetweenDate: async () => 10,
} as any);
expect(await chart.Total_conversations({} as any)).to.be.equal(10);
});
});
describe('Avg_chat_duration', () => {
it('should return the average chat duration', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { chatDuration: 10 } }],
} as any);
expect(await chart.Avg_chat_duration({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { chatDuration: 10 } }, { metrics: { chatDuration: 20 } }],
} as any);
expect(await chart.Avg_chat_duration({} as any)).to.be.equal(15);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [],
} as any);
expect(await chart.Avg_chat_duration({} as any)).to.be.equal(0);
});
it('should ignore conversations without chatDuration', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { chatDuration: 10 } }, { metrics: {} }],
} as any);
expect(await chart.Avg_chat_duration({} as any)).to.be.equal(10);
});
});
describe('Total_messages', () => {
it('should return the total number of messages', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [{ msgs: 10 }],
} as any);
expect(await chart.Total_messages({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [{ msgs: 10 }, { msgs: 20 }],
} as any);
expect(await chart.Total_messages({} as any)).to.be.equal(30);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [],
} as any);
expect(await chart.Total_messages({} as any)).to.be.equal(0);
});
it('should ignore conversations without msgs', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDateWithMessages: () => [{ msgs: 10 }, {}],
} as any);
expect(await chart.Total_messages({} as any)).to.be.equal(10);
});
});
describe('Avg_first_response_time', () => {
it('should return the average first response time', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }],
} as any);
expect(await chart.Avg_first_response_time({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }, { metrics: { response: { ft: 20 } } }],
} as any);
expect(await chart.Avg_first_response_time({} as any)).to.be.equal(15);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [],
} as any);
expect(await chart.Avg_first_response_time({} as any)).to.be.equal(0);
});
it('should ignore conversations without response', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }, { metrics: {} }],
} as any);
expect(await chart.Avg_first_response_time({} as any)).to.be.equal(10);
});
});
describe('Best_first_response_time', () => {
it('should return the best first response time', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }],
} as any);
expect(await chart.Best_first_response_time({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }, { metrics: { response: { ft: 20 } } }],
} as any);
expect(await chart.Best_first_response_time({} as any)).to.be.equal(10);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [],
} as any);
expect(await chart.Best_first_response_time({} as any)).to.be.equal(0);
});
it('should ignore conversations without response', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { ft: 10 } } }, { metrics: {} }],
} as any);
expect(await chart.Best_first_response_time({} as any)).to.be.equal(10);
});
});
describe('Avg_response_time', () => {
it('should return the average response time', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { avg: 10 } } }],
} as any);
expect(await chart.Avg_response_time({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { avg: 10 } } }, { metrics: { response: { avg: 20 } } }],
} as any);
expect(await chart.Avg_response_time({} as any)).to.be.equal(15);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [],
} as any);
expect(await chart.Avg_response_time({} as any)).to.be.equal(0);
});
it('should ignore conversations without response', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { response: { avg: 10 } } }, { metrics: {} }],
} as any);
expect(await chart.Avg_response_time({} as any)).to.be.equal(10);
});
});
describe('Avg_reaction_time', () => {
it('should return the average reaction time', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { reaction: { ft: 10 } } }],
} as any);
expect(await chart.Avg_reaction_time({} as any)).to.be.equal(10);
});
it('should properly calculate with more conversations', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { reaction: { ft: 10 } } }, { metrics: { reaction: { ft: 20 } } }],
} as any);
expect(await chart.Avg_reaction_time({} as any)).to.be.equal(15);
});
it('should return 0 if no conversations are found', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [],
} as any);
expect(await chart.Avg_reaction_time({} as any)).to.be.equal(0);
});
it('should ignore conversations without reaction', async () => {
const chart = new ChartData({
getAnalyticsMetricsBetweenDate: () => [{ metrics: { reaction: { ft: 10 } } }, { metrics: {} }],
} as any);
expect(await chart.Avg_reaction_time({} as any)).to.be.equal(10);
});
});
});

View File

@@ -0,0 +1,351 @@
/* eslint-disable new-cap */
import { expect } from 'chai';
import moment from 'moment-timezone';
import sinon from 'sinon';
import { conversations } from './mockData';
import { OverviewData } from '../../../../../server/services/omnichannel-analytics/OverviewData';
const analytics = (date: { gte: Date; lte: Date }) => {
// filter the mockData array with the date param with moment
return conversations.filter((c) => moment(c.ts).isBetween(date.gte, date.lte, undefined, '[]'));
};
describe('OverviewData Analytics', () => {
describe('isActionAllowed', () => {
it('should return false if no action is provided', () => {
const overview = new OverviewData({} as any);
expect(overview.isActionAllowed(undefined)).to.be.false;
});
it('should return false if an invalid action is provided', () => {
const overview = new OverviewData({} as any);
expect(overview.isActionAllowed('invalid_action')).to.be.false;
});
it('should return true if a valid action is provided', () => {
const overview = new OverviewData({} as any);
expect(overview.isActionAllowed('Conversations')).to.be.true;
});
});
describe('callAction', () => {
it('should fail if the action is invalid', async () => {
const overview = new OverviewData({} as any);
try {
// @ts-expect-error - Invalid action
await overview.callAction('invalid_action', {} as any);
} catch (e: any) {
expect(e.message).to.be.equal('Invalid action');
}
});
it('should call the correct action with the correct parameters', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: () => [],
getOnHoldConversationsBetweenDate: () => 0,
getAnalyticsMetricsBetweenDate: () => [],
} as any);
const spy = sinon.spy(overview, 'Conversations');
const spy2 = sinon.spy(overview, 'Productivity');
await overview.callAction('Conversations', moment(), moment(), '', 'UTC');
expect(spy.calledOnce).to.be.true;
await overview.callAction('Productivity', moment(), moment(), '', 'UTC', (v: string): string => v);
expect(spy2.calledOnce).to.be.true;
});
});
describe('getKeyHavingMaxValue', () => {
it('should return the key with the max value', () => {
const overview = new OverviewData({} as any);
const map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
expect(overview.getKeyHavingMaxValue(map, 'd')).to.be.equal('c');
});
it('should return the default key if the map is empty', () => {
const overview = new OverviewData({} as any);
const map = new Map();
expect(overview.getKeyHavingMaxValue(map, 'd')).to.be.equal('d');
});
});
describe('getAllMapKeysSize', () => {
it('should return the sum of all map keys', () => {
const overview = new OverviewData({} as any);
const map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
expect(overview.sumAllMapKeys(map)).to.be.equal(6);
});
it('should return 0 if the map is empty', () => {
const overview = new OverviewData({} as any);
const map = new Map();
expect(overview.sumAllMapKeys(map)).to.be.equal(0);
});
});
describe('getBusiestDay', () => {
it('should return the day with the most messages', () => {
const overview = new OverviewData({} as any);
const map = new Map();
map.set(
'Monday',
new Map([
['1', 1],
['2', 2],
]),
);
map.set(
'Tuesday',
new Map([
['13', 1],
['15', 2],
]),
);
map.set(
'Sunday',
new Map([
['12', 2],
['23', 2],
]),
);
expect(overview.getBusiestDay(map)).to.be.equal('Sunday');
});
it('should return the first day with the most messages if theres a tie', () => {
const overview = new OverviewData({} as any);
const map = new Map();
map.set(
'Monday',
new Map([
['1', 1],
['2', 2],
]),
);
map.set(
'Tuesday',
new Map([
['13', 1],
['15', 2],
]),
);
map.set(
'Sunday',
new Map([
['12', 1],
['23', 2],
]),
);
expect(overview.getBusiestDay(map)).to.be.equal('Monday');
});
it('should return the default key if the map is empty', () => {
const overview = new OverviewData({} as any);
const map = new Map();
expect(overview.getBusiestDay(map)).to.be.equal('-');
});
});
describe('sumAllMapKeys', () => {
it('should return the sum of all map keys', () => {
const overview = new OverviewData({} as any);
const map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
expect(overview.sumAllMapKeys(map)).to.be.equal(6);
});
it('should return 0 if the map is empty', () => {
const overview = new OverviewData({} as any);
const map = new Map();
expect(overview.sumAllMapKeys(map)).to.be.equal(0);
});
});
describe('Conversations', () => {
it('should return all values as 0 when theres no data', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: () => [],
getOnHoldConversationsBetweenDate: () => 0,
} as any);
const result = await overview.Conversations(moment(), moment(), '', 'UTC', (v: string): string => v, {});
expect(result).to.be.deep.equal([
{ title: 'Total_conversations', value: 0 },
{ title: 'Open_conversations', value: 0 },
{ title: 'On_Hold_conversations', value: 0 },
{ title: 'Total_messages', value: 0 },
{ title: 'Busiest_day', value: '-' },
{ title: 'Conversations_per_day', value: '0.00' },
{ title: 'Busiest_time', value: '-' },
]);
});
it('should return all values as 0 when theres data but not on the period we pass', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: () => analytics({ gte: moment().set('month', 9).toDate(), lte: moment().set('month', 9).toDate() }),
getOnHoldConversationsBetweenDate: () => 0,
} as any);
const result = await overview.Conversations(moment(), moment(), '', 'UTC', (v: string): string => v, {});
expect(result).to.be.deep.equal([
{ title: 'Total_conversations', value: 0 },
{ title: 'Open_conversations', value: 0 },
{ title: 'On_Hold_conversations', value: 0 },
{ title: 'Total_messages', value: 0 },
{ title: 'Busiest_day', value: '-' },
{ title: 'Conversations_per_day', value: '0.00' },
{ title: 'Busiest_time', value: '-' },
]);
});
it('should return the correct values when theres data on the period we pass', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: (date: { gte: Date; lte: Date }) => analytics(date),
getOnHoldConversationsBetweenDate: () => 1,
} as any);
// Fixed date to assure we get the same data
const result = await overview.Conversations(
moment.utc().set('month', 10).set('year', 2023).set('date', 12).startOf('day'),
moment.utc().set('month', 10).set('year', 2023).set('date', 12).endOf('day'),
'',
'UTC',
(v: string): string => v,
{},
);
expect(result).to.be.deep.equal([
{ title: 'Total_conversations', value: 1 },
{ title: 'Open_conversations', value: 0 },
{ title: 'On_Hold_conversations', value: 1 },
{ title: 'Total_messages', value: 93 },
{ title: 'Busiest_day', value: 'Sunday' },
{ title: 'Conversations_per_day', value: '1.00' },
{ title: 'Busiest_time', value: '11AM - 12PM' },
]);
});
it('should only return conversation metrics related to the provided period, and not consider previous or following days', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: (date: { gte: Date; lte: Date }) => analytics(date),
getOnHoldConversationsBetweenDate: () => 1,
} as any);
// choosing this specific date since the day before and after are not empty
const targetDate = moment.utc().set('month', 10).set('year', 2023).set('date', 23);
// Fixed date to assure we get the same data
const result = await overview.Conversations(targetDate.startOf('day'), targetDate.endOf('day'), '', 'UTC');
expect(result).to.be.deep.equal([
{ title: 'Total_conversations', value: 1 },
{ title: 'Open_conversations', value: 0 },
{ title: 'On_Hold_conversations', value: 1 },
{ title: 'Total_messages', value: 14 },
{ title: 'Busiest_day', value: 'Thursday' },
{ title: 'Conversations_per_day', value: '1.00' },
{ title: 'Busiest_time', value: '7AM - 8AM' },
]);
});
it('should return all values as 0 when there is no data in the provided period, but there is data in the previous and following days', async () => {
const overview = new OverviewData({
getAnalyticsBetweenDate: (date: { gte: Date; lte: Date }) => analytics(date),
getOnHoldConversationsBetweenDate: () => 0,
} as any);
// choosing this specific date since the day before and after are not empty
const targetDate = moment.utc().set('month', 10).set('year', 2023).set('date', 13);
const result = await overview.Conversations(targetDate.startOf('day'), targetDate.endOf('day'), '', 'UTC');
expect(result).to.be.deep.equal([
{ title: 'Total_conversations', value: 0 },
{ title: 'Open_conversations', value: 0 },
{ title: 'On_Hold_conversations', value: 0 },
{ title: 'Total_messages', value: 0 },
{ title: 'Busiest_day', value: '-' },
{ title: 'Conversations_per_day', value: '0.00' },
{ title: 'Busiest_time', value: '-' },
]);
});
});
describe('Productivity', () => {
it('should return all values as 0 when theres no data', async () => {
const overview = new OverviewData({
getAnalyticsMetricsBetweenDate: () => ({
forEach: () => [],
}),
} as any);
const result = await overview.Productivity(moment(), moment(), '', 'UTC', (v: string): string => v, {});
expect(result).to.be.deep.equal([
{ title: 'Avg_response_time', value: '00:00:00' },
{ title: 'Avg_first_response_time', value: '00:00:00' },
{ title: 'Avg_reaction_time', value: '00:00:00' },
]);
});
it('should return all values as 0 when theres data but not on the period we pass', async () => {
const overview = new OverviewData({
getAnalyticsMetricsBetweenDate: (_: any, date: { gte: Date; lte: Date }) => analytics(date),
} as any);
const result = await overview.Productivity(
moment().set('month', 9),
moment().set('month', 9),
'',
'UTC',
(v: string): string => v,
{},
);
expect(result).to.be.deep.equal([
{ title: 'Avg_response_time', value: '00:00:00' },
{ title: 'Avg_first_response_time', value: '00:00:00' },
{ title: 'Avg_reaction_time', value: '00:00:00' },
]);
});
it('should return the correct values when theres data on the period we pass', async () => {
const overview = new OverviewData({
getAnalyticsMetricsBetweenDate: (_: any, date: { gte: Date; lte: Date }) => analytics(date),
} as any);
const result = await overview.Productivity(
moment().set('month', 10).set('year', 2023).startOf('month'),
moment().set('month', 10).set('year', 2023).endOf('month'),
'',
'UTC',
);
expect(result).to.be.deep.equal([
{ title: 'Avg_response_time', value: '00:00:07' },
{ title: 'Avg_first_response_time', value: '00:00:10' },
{ title: 'Avg_reaction_time', value: '00:00:49' },
]);
});
it('should only return productivity metrics related to the provided period, and not consider previous or following days', async () => {
const overview = new OverviewData({
getAnalyticsMetricsBetweenDate: (_: any, date: { gte: Date; lte: Date }) => analytics(date),
} as any);
// choosing this specific date since the day before and after are not empty
const targetDate = moment().set('month', 10).set('year', 2023).set('date', 25);
const result = await overview.Productivity(targetDate.startOf('day'), targetDate.clone().endOf('day'), '', 'UTC');
expect(result).to.be.deep.equal([
{ title: 'Avg_response_time', value: '00:00:01' },
{ title: 'Avg_first_response_time', value: '00:00:04' },
{ title: 'Avg_reaction_time', value: '00:02:03' },
]);
});
it('should return all values as 0 when there is no data in the provided period, but there is data in the previous and following days', async () => {
const overview = new OverviewData({
getAnalyticsMetricsBetweenDate: (_: any, date: { gte: Date; lte: Date }) => analytics(date),
} as any);
// choosing this specific date since the day before and after are not empty
const targetDate = moment.utc().set('month', 10).set('year', 2023).set('date', 13);
const result = await overview.Productivity(targetDate.startOf('day'), targetDate.endOf('day'), '', 'UTC');
expect(result).to.be.deep.equal([
{ title: 'Avg_response_time', value: '00:00:00' },
{ title: 'Avg_first_response_time', value: '00:00:00' },
{ title: 'Avg_reaction_time', value: '00:00:00' },
]);
});
});
});

View File

@@ -0,0 +1,38 @@
export const conversations = [
{ ts: new Date('2023-11-07T14:37:40.081Z'), msgs: 21 },
{
ts: new Date('2023-11-14T02:10:38.971Z'),
msgs: 48,
metrics: {
response: { avg: 10, ft: 4 },
reaction: { ft: 10 },
},
},
{ ts: new Date('2023-11-04T20:33:27.172Z'), msgs: 82 },
{ ts: new Date('2023-11-12T11:37:17.716Z'), msgs: 93 },
{ ts: new Date('2023-11-30T17:27:00.057Z'), msgs: 65 },
{
ts: new Date('2023-11-28T01:13:44.980Z'),
msgs: 45,
metrics: {
response: { avg: 10.233, ft: 23.1 },
reaction: { ft: 13.2343333 },
},
},
{ ts: new Date('2023-11-19T04:05:23.717Z'), msgs: 11 },
{ ts: new Date('2023-11-15T09:16:21.890Z'), msgs: 17 },
{ ts: new Date('2023-11-26T03:53:19.443Z'), msgs: 37 },
{ ts: new Date('2023-11-24T13:45:01.650Z'), msgs: 96 },
{
ts: new Date('2023-11-25T07:46:38.990Z'),
msgs: 38,
metrics: {
response: { avg: 1.34344417, ft: 4.19383484 },
reaction: { ft: 123.040949 },
},
},
{ ts: new Date('2023-11-21T07:27:38.990Z'), msgs: 38 },
{ ts: new Date('2023-11-29T07:37:38.990Z'), msgs: 38 },
{ ts: new Date('2023-11-22T07:47:38.990Z'), msgs: 34 },
{ ts: new Date('2023-11-23T07:57:38.990Z'), msgs: 14 },
];