@flusys/nestjs-event-manager 6.3.0 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -190,7 +190,16 @@ let EventService = class EventService extends _classes.ApiService {
190
190
  });
191
191
  }
192
192
  participant.status = dto.status;
193
- return participantRepo.save(participant);
193
+ const saved = await participantRepo.save(participant);
194
+ await Promise.all([
195
+ this.clearCacheForAll(),
196
+ this.clearCacheForId([
197
+ {
198
+ id: participant.eventId
199
+ }
200
+ ])
201
+ ]);
202
+ return saved;
194
203
  }
195
204
  // Private business logic helpers
196
205
  async addCreatorAndParticipants(eventId, participantIds, user) {
@@ -50,6 +50,15 @@ function buildParticipant(overrides = {}) {
50
50
  };
51
51
  }
52
52
  describe('EventService', ()=>{
53
+ const mockUtilsService = {
54
+ clearCache: jest.fn(),
55
+ getCacheKey: jest.fn().mockReturnValue('cache-key'),
56
+ trackCacheKey: jest.fn()
57
+ };
58
+ // Call history is shared across tests in this file; reset it so each cache assertion is exact.
59
+ beforeEach(()=>{
60
+ mockUtilsService.clearCache.mockClear();
61
+ });
53
62
  let service;
54
63
  let mockEventRepo;
55
64
  let mockParticipantRepo;
@@ -72,7 +81,7 @@ describe('EventService', ()=>{
72
81
  getRepository: jest.fn((entity)=>Promise.resolve(entity === _entities.EventParticipant ? mockParticipantRepo : mockEventRepo)),
73
82
  getDataSource: jest.fn()
74
83
  };
75
- service = new _eventservice.EventService({}, {}, mockConfigService, mockDataSourceProvider);
84
+ service = new _eventservice.EventService({}, mockUtilsService, mockConfigService, mockDataSourceProvider);
76
85
  });
77
86
  describe('resolveEntity', ()=>{
78
87
  it('resolves to the company-scoped entity when the company feature is enabled', ()=>{
@@ -361,6 +370,19 @@ describe('EventService', ()=>{
361
370
  status: _enums.ParticipantStatus.TENTATIVE
362
371
  }));
363
372
  });
373
+ it('invalidates the event list cache and the parent event entry', async ()=>{
374
+ const participant = buildParticipant({
375
+ status: _enums.ParticipantStatus.PENDING
376
+ });
377
+ mockParticipantRepo.findOne.mockResolvedValue(participant);
378
+ mockParticipantRepo.save.mockImplementation(async (p)=>p);
379
+ await service.updateParticipantStatus({
380
+ id: participant.id,
381
+ status: _enums.ParticipantStatus.ACCEPTED
382
+ }, user);
383
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('event', expect.anything());
384
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('event', expect.anything(), participant.eventId);
385
+ });
364
386
  it('throws NotFoundException with the correct messageKey when the participant is missing', async ()=>{
365
387
  mockParticipantRepo.findOne.mockResolvedValue(null);
366
388
  const dto = {
@@ -180,7 +180,16 @@ export class EventService extends ApiService {
180
180
  });
181
181
  }
182
182
  participant.status = dto.status;
183
- return participantRepo.save(participant);
183
+ const saved = await participantRepo.save(participant);
184
+ await Promise.all([
185
+ this.clearCacheForAll(),
186
+ this.clearCacheForId([
187
+ {
188
+ id: participant.eventId
189
+ }
190
+ ])
191
+ ]);
192
+ return saved;
184
193
  }
185
194
  // Private business logic helpers
186
195
  async addCreatorAndParticipants(eventId, participantIds, user) {
@@ -46,6 +46,15 @@ function buildParticipant(overrides = {}) {
46
46
  };
47
47
  }
48
48
  describe('EventService', ()=>{
49
+ const mockUtilsService = {
50
+ clearCache: jest.fn(),
51
+ getCacheKey: jest.fn().mockReturnValue('cache-key'),
52
+ trackCacheKey: jest.fn()
53
+ };
54
+ // Call history is shared across tests in this file; reset it so each cache assertion is exact.
55
+ beforeEach(()=>{
56
+ mockUtilsService.clearCache.mockClear();
57
+ });
49
58
  let service;
50
59
  let mockEventRepo;
51
60
  let mockParticipantRepo;
@@ -68,7 +77,7 @@ describe('EventService', ()=>{
68
77
  getRepository: jest.fn((entity)=>Promise.resolve(entity === EventParticipant ? mockParticipantRepo : mockEventRepo)),
69
78
  getDataSource: jest.fn()
70
79
  };
71
- service = new EventService({}, {}, mockConfigService, mockDataSourceProvider);
80
+ service = new EventService({}, mockUtilsService, mockConfigService, mockDataSourceProvider);
72
81
  });
73
82
  describe('resolveEntity', ()=>{
74
83
  it('resolves to the company-scoped entity when the company feature is enabled', ()=>{
@@ -357,6 +366,19 @@ describe('EventService', ()=>{
357
366
  status: ParticipantStatus.TENTATIVE
358
367
  }));
359
368
  });
369
+ it('invalidates the event list cache and the parent event entry', async ()=>{
370
+ const participant = buildParticipant({
371
+ status: ParticipantStatus.PENDING
372
+ });
373
+ mockParticipantRepo.findOne.mockResolvedValue(participant);
374
+ mockParticipantRepo.save.mockImplementation(async (p)=>p);
375
+ await service.updateParticipantStatus({
376
+ id: participant.id,
377
+ status: ParticipantStatus.ACCEPTED
378
+ }, user);
379
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('event', expect.anything());
380
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('event', expect.anything(), participant.eventId);
381
+ });
360
382
  it('throws NotFoundException with the correct messageKey when the participant is missing', async ()=>{
361
383
  mockParticipantRepo.findOne.mockResolvedValue(null);
362
384
  const dto = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-event-manager",
3
- "version": "6.3.0",
3
+ "version": "6.4.1",
4
4
  "description": "Event manager module with calendar support and recurrence",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -84,7 +84,7 @@
84
84
  "express": "^5.0.0"
85
85
  },
86
86
  "dependencies": {
87
- "@flusys/nestjs-core": "6.3.0",
88
- "@flusys/nestjs-shared": "6.3.0"
87
+ "@flusys/nestjs-core": "6.4.1",
88
+ "@flusys/nestjs-shared": "6.4.1"
89
89
  }
90
90
  }