feat(schemas): accept cadence field on subscription + contribution updates
This commit is contained in:
parent
47f2d666dd
commit
35197c465b
2 changed files with 69 additions and 2 deletions
|
|
@ -75,7 +75,8 @@ export const helcimSubscriptionSchema = z.object({
|
|||
customerId: z.union([z.string().min(1), z.number()]),
|
||||
contributionTier: z.enum(['0', '5', '15', '30', '50']),
|
||||
customerCode: z.union([z.string().min(1).max(200), z.number()]).transform(String),
|
||||
cardToken: z.string().max(500).optional().nullable()
|
||||
cardToken: z.string().max(500).optional().nullable(),
|
||||
cadence: z.enum(['monthly', 'annual']).default('monthly')
|
||||
})
|
||||
|
||||
export const helcimUpdateBillingSchema = z.object({
|
||||
|
|
@ -135,7 +136,8 @@ export const eventPaymentSchema = z.object({
|
|||
// --- Member schemas ---
|
||||
|
||||
export const updateContributionSchema = z.object({
|
||||
contributionTier: z.enum(['0', '5', '15', '30', '50'])
|
||||
contributionTier: z.enum(['0', '5', '15', '30', '50']),
|
||||
cadence: z.enum(['monthly', 'annual']).default('monthly')
|
||||
})
|
||||
|
||||
export const updateCircleSchema = z.object({
|
||||
|
|
|
|||
|
|
@ -160,6 +160,48 @@ describe('helcimSubscriptionSchema', () => {
|
|||
})
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it('accepts cadence: monthly', () => {
|
||||
const result = helcimSubscriptionSchema.safeParse({
|
||||
customerId: '12345',
|
||||
contributionTier: '15',
|
||||
customerCode: 'CST123',
|
||||
cadence: 'monthly'
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('monthly')
|
||||
})
|
||||
|
||||
it('accepts cadence: annual', () => {
|
||||
const result = helcimSubscriptionSchema.safeParse({
|
||||
customerId: '12345',
|
||||
contributionTier: '15',
|
||||
customerCode: 'CST123',
|
||||
cadence: 'annual'
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('annual')
|
||||
})
|
||||
|
||||
it('rejects cadence: weekly', () => {
|
||||
const result = helcimSubscriptionSchema.safeParse({
|
||||
customerId: '12345',
|
||||
contributionTier: '15',
|
||||
customerCode: 'CST123',
|
||||
cadence: 'weekly'
|
||||
})
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it('defaults cadence to monthly when omitted', () => {
|
||||
const result = helcimSubscriptionSchema.safeParse({
|
||||
customerId: '12345',
|
||||
contributionTier: '15',
|
||||
customerCode: 'CST123'
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('monthly')
|
||||
})
|
||||
})
|
||||
|
||||
describe('helcimUpdateBillingSchema', () => {
|
||||
|
|
@ -310,6 +352,29 @@ describe('updateContributionSchema', () => {
|
|||
expect(result.success).toBe(true)
|
||||
expect(result.data).not.toHaveProperty('role')
|
||||
})
|
||||
|
||||
it('accepts cadence: monthly', () => {
|
||||
const result = updateContributionSchema.safeParse({ contributionTier: '15', cadence: 'monthly' })
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('monthly')
|
||||
})
|
||||
|
||||
it('accepts cadence: annual', () => {
|
||||
const result = updateContributionSchema.safeParse({ contributionTier: '15', cadence: 'annual' })
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('annual')
|
||||
})
|
||||
|
||||
it('rejects cadence: weekly', () => {
|
||||
const result = updateContributionSchema.safeParse({ contributionTier: '15', cadence: 'weekly' })
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it('defaults cadence to monthly when omitted', () => {
|
||||
const result = updateContributionSchema.safeParse({ contributionTier: '15' })
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.data.cadence).toBe('monthly')
|
||||
})
|
||||
})
|
||||
|
||||
// --- Series schemas ---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue