diff --git a/packages/backend/src/graphql/resolvers/webhooks.test.ts b/packages/backend/src/graphql/resolvers/webhooks.test.ts index 3572f65993..2d2198081a 100644 --- a/packages/backend/src/graphql/resolvers/webhooks.test.ts +++ b/packages/backend/src/graphql/resolvers/webhooks.test.ts @@ -127,7 +127,30 @@ describe('Webhook Events Query', (): void => { expect(typesWithout).not.toContain('outgoing_payment.funded') expect(typesWithout).not.toContain('outgoing_payment.cancelled') - // When explicitly requested via filter, they should appear + // Explicit empty array filter should behave like no filter and still exclude them + const withEmptyIn = await appContainer.apolloClient + .query({ + query: gql` + query WebhookEvents($filter: WebhookEventFilter) { + webhookEvents(filter: $filter) { + edges { + node { + id + type + } + } + } + } + `, + variables: { filter: { type: { in: [] } } } + }) + .then((q): WebhookEventsConnection => q.data!.webhookEvents) + + const typesEmpty = withEmptyIn.edges.map((e) => e.node.type) + expect(typesEmpty).not.toContain('outgoing_payment.funded') + expect(typesEmpty).not.toContain('outgoing_payment.cancelled') + + // When explicitly requested via filter, they still should not appear const withFilter = await appContainer.apolloClient .query({ query: gql` @@ -145,7 +168,8 @@ describe('Webhook Events Query', (): void => { variables: { filter: { type: { - in: ['outgoing_payment.funded', 'outgoing_payment.cancelled'] + in: ['outgoing_payment.funded', 'outgoing_payment.cancelled'], + notIn: [] } } } @@ -153,8 +177,7 @@ describe('Webhook Events Query', (): void => { .then((q): WebhookEventsConnection => q.data!.webhookEvents) const typesWith = withFilter.edges.map((e) => e.node.type) - expect(typesWith).toContain('outgoing_payment.funded') - expect(typesWith).toContain('outgoing_payment.cancelled') + expect(typesWith).toStrictEqual([]) }) describe('tenant boundaries', (): void => { diff --git a/packages/backend/src/graphql/resolvers/webhooks.ts b/packages/backend/src/graphql/resolvers/webhooks.ts index 8e0fef8cde..a0b7d9d456 100644 --- a/packages/backend/src/graphql/resolvers/webhooks.ts +++ b/packages/backend/src/graphql/resolvers/webhooks.ts @@ -22,9 +22,15 @@ export const getWebhookEvents: QueryResolvers['webhookEve const { filter, sortOrder, tenantId, ...pagination } = args const order = sortOrder === 'ASC' ? SortOrder.Asc : SortOrder.Desc const webhookService = await ctx.container.use('webhookService') - const filterOrDefaults = filter ?? { - type: { notIn: DEFAULT_EXCLUDED_TYPES } + const type = { ...(filter?.type ?? {}) } + if ( + !('notIn' in type) || + !Array.isArray(type.notIn) || + type.notIn.length === 0 + ) { + type.notIn = DEFAULT_EXCLUDED_TYPES } + const filterOrDefaults = { ...filter, type } const getPageFn = (pagination_: Pagination, sortOrder_?: SortOrder) => webhookService.getPage({ pagination: pagination_,