@@ -2,10 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
22import { NotFoundException } from '@nestjs/common' ;
33import { WebhookService } from './webhook.service' ;
44import { PrismaService } from '../prisma/prisma.service' ;
5- import { CacheService } from '../common/cache/cache.service' ;
6- import { RequestContextService } from '../common/request-context/request-context.service' ;
75import { EndpointStatus } from './domain/webhook-events' ;
8- import { WEBHOOK_ENDPOINT_CACHE_PREFIX } from './webhook.service' ;
96
107const PROJECT_ID = 'project-1' ;
118const ENDPOINT_ID = 'endpoint-1' ;
@@ -52,14 +49,11 @@ describe('WebhookService', () => {
5249 const module : TestingModule = await Test . createTestingModule ( {
5350 providers : [
5451 WebhookService ,
55- CacheService ,
56- RequestContextService ,
5752 { provide : PrismaService , useValue : mockPrisma } ,
5853 ] ,
5954 } ) . compile ( ) ;
6055
6156 service = module . get < WebhookService > ( WebhookService ) ;
62- cache = module . get < CacheService > ( CacheService ) ;
6357 } ) ;
6458
6559 it ( 'should be defined' , ( ) => {
@@ -188,25 +182,13 @@ describe('WebhookService', () => {
188182 expect ( result . id ) . toBe ( ENDPOINT_ID ) ;
189183 } ) ;
190184
191- it ( 'returns cached endpoint on second call without hitting the database' , async ( ) => {
185+ it ( 'hits the database each time ' , async ( ) => {
192186 mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
193187
194188 await service . getEndpoint ( ENDPOINT_ID ) ;
195189 await service . getEndpoint ( ENDPOINT_ID ) ;
196190
197- expect ( mockPrisma . webhookEndpoint . findUnique ) . toHaveBeenCalledTimes ( 1 ) ;
198- expect (
199- cache . get ( `${ WEBHOOK_ENDPOINT_CACHE_PREFIX } ${ ENDPOINT_ID } ` ) ,
200- ) . toBeTruthy ( ) ;
201- } ) ;
202-
203- it ( 'falls through to database on cache miss' , async ( ) => {
204- mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
205-
206- expect ( cache . get ( `${ WEBHOOK_ENDPOINT_CACHE_PREFIX } ${ ENDPOINT_ID } ` ) ) . toBeNull ( ) ;
207- await service . getEndpoint ( ENDPOINT_ID ) ;
208-
209- expect ( mockPrisma . webhookEndpoint . findUnique ) . toHaveBeenCalledTimes ( 1 ) ;
191+ expect ( mockPrisma . webhookEndpoint . findUnique ) . toHaveBeenCalledTimes ( 2 ) ;
210192 } ) ;
211193
212194 it ( 'throws NotFoundException when endpoint not found' , async ( ) => {
@@ -231,22 +213,6 @@ describe('WebhookService', () => {
231213
232214 expect ( result . url ) . toBe ( 'https://new.example.com/hook' ) ;
233215 } ) ;
234-
235- it ( 'invalidates cache after update' , async ( ) => {
236- mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
237- mockPrisma . webhookEndpoint . update . mockResolvedValue ( mockEndpoint ) ;
238-
239- await service . getEndpoint ( ENDPOINT_ID ) ;
240- expect (
241- cache . get ( `${ WEBHOOK_ENDPOINT_CACHE_PREFIX } ${ ENDPOINT_ID } ` ) ,
242- ) . toBeTruthy ( ) ;
243-
244- await service . updateEndpoint ( ENDPOINT_ID , { description : 'updated' } ) ;
245-
246- expect (
247- cache . get ( `${ WEBHOOK_ENDPOINT_CACHE_PREFIX } ${ ENDPOINT_ID } ` ) ,
248- ) . toBeNull ( ) ;
249- } ) ;
250216 } ) ;
251217
252218 // ─── deleteEndpoint ──────────────────────────────────────────────────────────
@@ -261,18 +227,6 @@ describe('WebhookService', () => {
261227 where : { id : ENDPOINT_ID } ,
262228 } ) ;
263229 } ) ;
264-
265- it ( 'invalidates cache after delete' , async ( ) => {
266- mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
267- mockPrisma . webhookEndpoint . delete . mockResolvedValue ( mockEndpoint ) ;
268-
269- await service . getEndpoint ( ENDPOINT_ID ) ;
270- await service . deleteEndpoint ( ENDPOINT_ID ) ;
271-
272- expect (
273- cache . get ( `${ WEBHOOK_ENDPOINT_CACHE_PREFIX } ${ ENDPOINT_ID } ` ) ,
274- ) . toBeNull ( ) ;
275- } ) ;
276230 } ) ;
277231
278232 // ─── rotateSecret ─────────────────────────────────────────────────────────────
@@ -296,20 +250,22 @@ describe('WebhookService', () => {
296250
297251 describe ( 'getDeliveries' , ( ) => {
298252 it ( 'returns paginated deliveries with default page and limit' , async ( ) => {
253+ mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
299254 mockPrisma . webhookDelivery . findMany . mockResolvedValue ( [ ] ) ;
300255 mockPrisma . webhookDelivery . count . mockResolvedValue ( 0 ) ;
301256
302257 const result = await service . getDeliveries ( ENDPOINT_ID ) ;
303258
304259 expect ( mockPrisma . webhookDelivery . findMany ) . toHaveBeenCalledWith (
305- expect . objectContaining ( { skip : 0 , take : 20 } ) ,
260+ expect . objectContaining ( { skip : 0 , take : 50 } ) ,
306261 ) ;
307262 expect ( result . page ) . toBe ( 1 ) ;
308- expect ( result . limit ) . toBe ( 20 ) ;
263+ expect ( result . limit ) . toBe ( 50 ) ;
309264 expect ( result . total ) . toBe ( 0 ) ;
310265 } ) ;
311266
312267 it ( 'respects custom page and limit' , async ( ) => {
268+ mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
313269 mockPrisma . webhookDelivery . findMany . mockResolvedValue ( [ ] ) ;
314270 mockPrisma . webhookDelivery . count . mockResolvedValue ( 50 ) ;
315271
@@ -324,6 +280,7 @@ describe('WebhookService', () => {
324280 } ) ;
325281
326282 it ( 'returns deliveries in the response' , async ( ) => {
283+ mockPrisma . webhookEndpoint . findUnique . mockResolvedValue ( mockEndpoint ) ;
327284 const delivery = {
328285 id : 'delivery-1' ,
329286 endpointId : ENDPOINT_ID ,
0 commit comments