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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ The module enable / disable hooks were always mutations, so nothing changes in y
| `useEnableFilesMutation`, `useDisableFilesMutation` | `PUT /{version}/files/enable\|disable` | invalidates `Files` |
| `useEnableLoggingMutation`, `useDisableLoggingMutation` | `PUT /{version}/logs/enable\|disable` | invalidates `Logs` |
| `useEnablePaymentsMutation`, `useDisablePaymentsMutation` | `PUT /{version}/payments/enable\|disable` | invalidates `Payments` |
| `useGetPaymentsWebhookLogQuery` | `GET /{version}/payments/webhooks/log` | provides `PaymentIntegrations` |
| `useEnableMembershipMutation`, `useDisableMembershipMutation` | `PUT /{version}/membership/enable\|disable` | invalidates `Membership` |
| `useEnableEmailMutation`, `useDisableEmailMutation` | `PUT /{version}/notifications/email/enable\|disable` | invalidates `Emails` |
| `useEnableSmsMutation`, `useDisableSmsMutation` | `PUT /{version}/notifications/sms/enable\|disable` | invalidates `Sms` |
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/hub/payments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AUTO-GENERATED — full coverage of `norbix.hub.payments` (16 endpoints).
// AUTO-GENERATED — full coverage of `norbix.hub.payments` (17 endpoints).
// Synced from the norbix core SDK surface. Re-run the hook sync to refresh.
import type { Norbix } from '@norbix.ai/ts';

Expand All @@ -21,9 +21,10 @@ type GetPaymentsIntegration = Norbix['hub']['payments']['getPaymentsIntegration'
type GetPaymentsIntegrations = Norbix['hub']['payments']['getPaymentsIntegrations'];
type SavePaymentsIntegration = Norbix['hub']['payments']['savePaymentsIntegration'];
type TestPaymentsIntegration = Norbix['hub']['payments']['testPaymentsIntegration'];
type GetPaymentsWebhookLog = Norbix['hub']['payments']['getPaymentsWebhookLog'];

/**
* `hub.payments` — 16 endpoints, 1:1 with the core SDK.
* `hub.payments` — 17 endpoints, 1:1 with the core SDK.
*/
export const hubPayments = (b: Builder) => ({
disablePayments: b.mutation<Result<DisablePayments>, Arg<DisablePayments>>({
Expand Down Expand Up @@ -105,4 +106,13 @@ export const hubPayments = (b: Builder) => ({
query: (args) => (norbix) => norbix.hub.payments.testPaymentsIntegration(args),
invalidatesTags: ['PaymentIntegrations'],
}),

// The received payment webhooks of the project (newest first). Tagged
// 'PaymentIntegrations' so it refetches when an integration changes; it is a
// log the gateway writes as callbacks arrive, so callers poll it
// (pollingInterval).
getPaymentsWebhookLog: b.query<Result<GetPaymentsWebhookLog>, Arg<GetPaymentsWebhookLog>>({
query: (args) => (norbix) => norbix.hub.payments.getPaymentsWebhookLog(args),
providesTags: ['PaymentIntegrations'],
}),
});
57 changes: 57 additions & 0 deletions tests/payments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, expect, it } from 'vitest';

import { hubPayments } from '../src/hooks/hub/payments.js';

/**
* `hub.payments` hooks (gateway campaign audit/payments, item 8). Same fake
* builder and fake client as the files tests: the hooks are a 1:1 wrapper of
* the core SDK, so "it reached the right SDK method with my arguments" and the
* cache tags are the whole contract.
*/
function fakeBuilder() {
return {
query: (def: Record<string, unknown>) => ({ ...def, __kind: 'query' }),
mutation: (def: Record<string, unknown>) => ({ ...def, __kind: 'mutation' }),
} as never;
}

type Def = {
__kind: 'query' | 'mutation';
query: (args: unknown) => (norbix: unknown) => unknown;
providesTags?: unknown;
invalidatesTags?: unknown;
};

function fakeNorbix() {
const calls: Array<{ method: string; args: unknown }> = [];
const payments = new Proxy(
{},
{
get: (_t, name: string) => (args: unknown) => {
calls.push({ method: `hub.${name}`, args });
return Promise.resolve({ ok: true });
},
},
);
return { calls, client: { hub: { payments } } };
}

describe('hubPayments', () => {
const endpoints = hubPayments(fakeBuilder()) as unknown as Record<string, Def>;

it('covers all 17 hub Payments endpoints of the core SDK', () => {
expect(Object.keys(endpoints)).toHaveLength(17);
expect(endpoints).toHaveProperty('getPaymentsWebhookLog');
});

it('getPaymentsWebhookLog is a query that reaches the SDK method with the caller args', async () => {
const { calls, client } = fakeNorbix();
const args = { integrationId: 'int_stripe', limit: 20 };

await endpoints.getPaymentsWebhookLog.query(args)(client);

expect(endpoints.getPaymentsWebhookLog.__kind).toBe('query');
expect(endpoints.getPaymentsWebhookLog.providesTags).toEqual(['PaymentIntegrations']);
expect(calls).toEqual([{ method: 'hub.getPaymentsWebhookLog', args }]);
});
});