Skip to content
Open
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
49 changes: 48 additions & 1 deletion packages/source-stripe/src/spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import { z } from 'zod'
import spec, { configSchema, streamStateSpec } from './spec.js'
import spec, { configSchema, stripeEventSchema, streamStateSpec } from './spec.js'
import { BUNDLED_API_VERSION, SUPPORTED_API_VERSIONS } from '@stripe/sync-openapi'

describe('configSchema api_version field', () => {
Expand Down Expand Up @@ -70,3 +70,50 @@ describe('streamStateSpec JSON Schema round-trip', () => {
expect(zodFromJson.safeParse(stateInProgress).success).toBe(true)
})
})

describe('stripeEventSchema', () => {
it('accepts request as a plain string (older API versions)', () => {
const event = {
id: 'evt_test',
object: 'event',
api_version: '2020-08-27',
created: 1234567890,
data: { object: {} },
livemode: false,
pending_webhooks: 0,
request: 'req_xxxxx',
type: 'charge.created',
}
expect(stripeEventSchema.safeParse(event).success).toBe(true)
})

it('accepts request as an object (modern API versions)', () => {
const event = {
id: 'evt_test',
object: 'event',
api_version: '2020-08-27',
created: 1234567890,
data: { object: {} },
livemode: false,
pending_webhooks: 0,
request: { id: 'req_xxxxx', idempotency_key: null },
type: 'charge.created',
}
expect(stripeEventSchema.safeParse(event).success).toBe(true)
})

it('accepts request as null', () => {
const event = {
id: 'evt_test',
object: 'event',
api_version: '2020-08-27',
created: 1234567890,
data: { object: {} },
livemode: false,
pending_webhooks: 0,
request: null,
type: 'charge.created',
}
expect(stripeEventSchema.safeParse(event).success).toBe(true)
})
})
11 changes: 7 additions & 4 deletions packages/source-stripe/src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ export const stripeEventSchema = z.object({
"Number of webhooks that haven't been successfully delivered (for example, to return a 20x response) to the URLs you specify."
),
request: z
.object({
id: z.string().nullable(),
idempotency_key: z.string().nullable(),
})
.union([
z.string(),
z.object({
id: z.string().nullable(),
idempotency_key: z.string().nullable(),
}),
])
.nullable()
.describe('Information on the API request that triggers the event.'),
type: z
Expand Down
Loading