import { parseNotificationData } from './parse';

describe('parseNotificationData', () => {
  it('parses a snake_case booking payload', () => {
    expect(parseNotificationData('booking_confirmed', '{"booking_id":5001}')).toEqual({ kind: 'booking', bookingId: 5001 });
  });

  it('also accepts a camelCase payload', () => {
    expect(parseNotificationData('ticket_message', '{"ticketId":12}')).toEqual({ kind: 'ticket', ticketId: 12 });
  });

  it('maps a refund notification to the booking id', () => {
    expect(parseNotificationData('refund_processed', '{"booking_id":5004}')).toEqual({ kind: 'refund', bookingId: 5004 });
  });

  it('degrades to none for malformed JSON (never throws / trusts a blob)', () => {
    expect(parseNotificationData('booking_confirmed', 'not-json')).toEqual({ kind: 'none' });
  });

  it('degrades to none for an unknown type', () => {
    expect(parseNotificationData('mystery_event', '{"booking_id":1}')).toEqual({ kind: 'none' });
  });

  it('degrades to none when the expected id is missing', () => {
    expect(parseNotificationData('payout_paid', '{}')).toEqual({ kind: 'none' });
    expect(parseNotificationData('booking_confirmed', null)).toEqual({ kind: 'none' });
  });
});
