Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.5.2",
"version": "1.5.3",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/models/eventsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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,
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/typeDefs/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
78 changes: 78 additions & 0 deletions test/models/eventsFactory-compose-repetition.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});