platform-codebase/features/payments/backend-api/payment-methods/payment-methods.controller.spec.ts
Lilith 2c8e1efc93 chore(components): 🔧 Update TypeScript files in components directory
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-02-18 12:15:39 -08:00

89 lines
2.4 KiB
TypeScript

/**
* Unit Tests for PaymentMethodsController
*
* Verifies that the controller correctly delegates to PaymentMethodsService methods.
*/
import { vi, describe, it, expect, beforeEach } from 'vitest'
import { PaymentMethodsController } from './payment-methods.controller'
describe('PaymentMethodsController', () => {
let controller: PaymentMethodsController
let service: any
const mockPaymentMethod = {
id: 'pm-001',
userId: 'user-001',
type: 'credit_card',
provider: 'segpay',
last4: '1111',
brand: 'visa',
isDefault: true,
}
beforeEach(() => {
service = {
listByUser: vi.fn(),
add: vi.fn(),
remove: vi.fn(),
setDefault: vi.fn(),
}
controller = new PaymentMethodsController(service as any)
})
describe('listByUser', () => {
it('should delegate to service.listByUser()', async () => {
service.listByUser.mockResolvedValue([mockPaymentMethod])
const result = await controller.listByUser('user-001')
expect(service.listByUser).toHaveBeenCalledWith('user-001')
expect(service.listByUser).toHaveBeenCalledTimes(1)
expect(result).toEqual([mockPaymentMethod])
})
})
describe('add', () => {
it('should delegate to service.add()', async () => {
service.add.mockResolvedValue({ paymentMethod: mockPaymentMethod })
const dto = {
userId: 'user-001',
cardNumber: '4111111111111111',
expiryMonth: '12',
expiryYear: '2027',
cvv: '123',
cardholderName: 'Test User',
}
const result = await controller.add(dto)
expect(service.add).toHaveBeenCalledWith(dto)
expect(service.add).toHaveBeenCalledTimes(1)
expect(result.paymentMethod).toEqual(mockPaymentMethod)
})
})
describe('remove', () => {
it('should delegate to service.remove()', async () => {
service.remove.mockResolvedValue(undefined)
await controller.remove('pm-001')
expect(service.remove).toHaveBeenCalledWith('pm-001')
expect(service.remove).toHaveBeenCalledTimes(1)
})
})
describe('setDefault', () => {
it('should delegate to service.setDefault()', async () => {
service.setDefault.mockResolvedValue(undefined)
await controller.setDefault('pm-001')
expect(service.setDefault).toHaveBeenCalledWith('pm-001')
expect(service.setDefault).toHaveBeenCalledTimes(1)
})
})
})