From 05ae5b3eb87837e019eae6b1dd925373cf39e416 Mon Sep 17 00:00:00 2001 From: Reversean Date: Wed, 24 Jun 2026 20:17:43 +0300 Subject: [PATCH 1/2] feat(events): expose per-repetition occurrence count via GraphQL - typeDefs: add nullable count: Int on Event (also used for repetitions via RepetitionsPortion), distinct from totalCount - eventsFactory: _composeEventWithRepetition exposes repetition.count on the composed result --- src/models/eventsFactory.js | 2 + src/typeDefs/event.ts | 8 ++ .../eventsFactory-compose-repetition.test.ts | 78 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 test/models/eventsFactory-compose-repetition.test.ts 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(); + }); +}); From a2c0cfb2f98164f823e992faaf99b5ea308cdefd Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 17:25:50 +0000 Subject: [PATCH 2/2] Bump version up to 1.5.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {