Skip to content
Merged
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
31 changes: 27 additions & 4 deletions packages/backend/src/graphql/resolvers/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -145,16 +168,16 @@ describe('Webhook Events Query', (): void => {
variables: {
filter: {
type: {
in: ['outgoing_payment.funded', 'outgoing_payment.cancelled']
in: ['outgoing_payment.funded', 'outgoing_payment.cancelled'],
notIn: []
}
}
}
})
.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 => {
Expand Down
10 changes: 8 additions & 2 deletions packages/backend/src/graphql/resolvers/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ export const getWebhookEvents: QueryResolvers<TenantedApolloContext>['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_,
Expand Down
Loading