diff --git a/package.json b/package.json index 5a468592..2eb5eb56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.5.2", + "version": "1.5.3", "main": "index.ts", "license": "BUSL-1.1", "scripts": { diff --git a/src/models/eventsFactory.js b/src/models/eventsFactory.js index c552bc41..d56f761a 100644 --- a/src/models/eventsFactory.js +++ b/src/models/eventsFactory.js @@ -33,6 +33,7 @@ const ChartType = { * @property {Number} originalTimestamp - UNIX timestmap of the original event * @property {String} originalEventId - id of the original event * @property {String} projectId - id of the project, which repetition it is + * @property {Number} [count] - number of real repetition occurrences; absent means single occurrence */ /** @@ -1100,6 +1101,7 @@ class EventsFactory extends Factory { originalEventId: event._id, timestamp: repetition.timestamp, payload: composeEventPayloadByRepetition(event.payload, repetition), + count: repetition.count, projectId: this.projectId, }; } diff --git a/src/typeDefs/event.ts b/src/typeDefs/event.ts index cf65e848..d0c84cf0 100644 --- a/src/typeDefs/event.ts +++ b/src/typeDefs/event.ts @@ -271,6 +271,14 @@ type Event { """ totalCount: Int! + """ + Number of real occurrences this single repetition represents. Null for the + original event and for ordinary repetitions (both mean "single occurrence") + — distinct from totalCount, which is the group's grand total across all + repetitions. + """ + count: Int + """ User assigneed to the event """ diff --git a/test/models/eventsFactory-compose-repetition.test.ts b/test/models/eventsFactory-compose-repetition.test.ts new file mode 100644 index 00000000..9406f81a --- /dev/null +++ b/test/models/eventsFactory-compose-repetition.test.ts @@ -0,0 +1,78 @@ +import '../../src/env-test'; + +jest.mock('../../src/redisHelper', () => ({ + __esModule: true, + default: { + getInstance: () => ({}), + }, +})); + +jest.mock('../../src/services/chartDataService', () => ({ + __esModule: true, + default: jest.fn().mockImplementation(function () { + return {}; + }), +})); + +jest.mock('../../src/dataLoaders', () => ({ + createProjectEventsByIdLoader: () => ({}), +})); + +jest.mock('../../src/mongo', () => ({ + databases: { + events: { + collection: jest.fn(), + }, + }, +})); + +// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-explicit-any +const EventsFactory = require('../../src/models/eventsFactory') as any; + +describe('EventsFactory._composeEventWithRepetition', () => { + const projectId = '507f1f77bcf86cd799439011'; + let factory: any; + + const baseEvent = { + _id: 'original-event-id', + groupHash: 'hash', + totalCount: 5, + timestamp: 1000, + payload: { title: 'Test error' }, + }; + + beforeEach(() => { + factory = new EventsFactory(projectId); + }); + + it('should not set count when there is no repetitions', () => { + const result = factory._composeEventWithRepetition(baseEvent, null); + + expect(result.count).toBeUndefined(); + }); + + it('should expose repetition count on the composed result when present', () => { + const repetition = { + _id: 'repetition-id', + timestamp: 2000, + delta: null, + count: 7, + }; + + const result = factory._composeEventWithRepetition(baseEvent, repetition); + + expect(result.count).toBe(7); + }); + + it('should leave repetition count undefined when count is not present', () => { + const repetition = { + _id: 'repetition-id', + timestamp: 2000, + delta: null, + }; + + const result = factory._composeEventWithRepetition(baseEvent, repetition); + + expect(result.count).toBeUndefined(); + }); +});