Real World

advanced7 of 7

Learn about real world in fp-ts validation

Code Editor

07-real-world.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('Real-world validation', () => {
  it('validates complete payment request', () => {
    const request = {
      amount: 100,
      currency: 'USD',
      card: {
        number: '1234567812345678',
        cvv: '123',
        expiryMonth: 12,
        expiryYear: 2026,
      },
      billingName: 'Alice Johnson',
    }
    const result = validatePaymentRequest(request)
    expect(result._tag).toBe('Right')
  })

  it('accumulates all payment validation errors', () => {
    const request = {
      amount: -50,
      currency: 'INVALID',
      card: {
        number: '123',
        cvv: '12345',
        expiryMonth: 13,
        expiryYear: 2020,
      },
      billingName: '',
    }
    const result = validatePaymentRequest(request)
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left.length).toBeGreaterThan(5)
    }
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

Pro Tips

💡 Stuck? Here's what to try:

  • • Read the comments in the code carefully
  • • Run tests frequently to get feedback
  • • Check the fp-ts documentation
  • • Use the solution if you need help

🚀 Learning Approach:

  • • Focus on understanding, not just solving
  • • Experiment with different approaches
  • • Think about real-world applications
  • • Build on previous exercises