|
| 1 | +import { SeatMap } from 'types' |
| 2 | +import { hasService } from './hasService' |
| 3 | + |
| 4 | +describe('hasService', () => { |
| 5 | + // A basic offer with no available services |
| 6 | + const baseOffer = { |
| 7 | + available_services: [], |
| 8 | + } as any |
| 9 | + |
| 10 | + it('should return false when no seat maps passed and no available services on offer (no services available at all)', () => { |
| 11 | + // No seat maps provided and the offer has no available services |
| 12 | + expect(hasService(baseOffer)).toBe(false) |
| 13 | + }) |
| 14 | + |
| 15 | + it('should return false when seat maps is an empty array and no available services on offer', () => { |
| 16 | + // Seat maps provided as empty array and no service on the offer |
| 17 | + expect(hasService(baseOffer, [])).toBe(false) |
| 18 | + }) |
| 19 | + |
| 20 | + it('should return true when no seat maps passed but offer has a service available', () => { |
| 21 | + // Offer has a service (e.g. a baggage service) with maximum_quantity > 0 |
| 22 | + // and seat maps are not provided |
| 23 | + |
| 24 | + const offerWithService = { |
| 25 | + available_services: [{ maximum_quantity: 1, type: 'baggage' }], |
| 26 | + } as any |
| 27 | + |
| 28 | + expect(hasService(offerWithService)).toBe(true) |
| 29 | + }) |
| 30 | + |
| 31 | + it('should return true when only seats available in seat maps', () => { |
| 32 | + // Offer has no available services, but seat maps include a seat with available services |
| 33 | + const seatMaps: SeatMap[] = [ |
| 34 | + { |
| 35 | + cabins: [ |
| 36 | + { |
| 37 | + rows: [ |
| 38 | + { |
| 39 | + sections: [ |
| 40 | + { |
| 41 | + elements: [ |
| 42 | + { |
| 43 | + type: 'seat', |
| 44 | + available_services: ['service1', 'service2'], |
| 45 | + }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | + ] as any |
| 55 | + |
| 56 | + expect(hasService(baseOffer, seatMaps)).toBe(true) |
| 57 | + }) |
| 58 | + it('should return true when only baggages available in offer', () => { |
| 59 | + // Offer has an available baggage service and seat maps are empty |
| 60 | + const offerWithBaggage = { |
| 61 | + available_services: [{ maximum_quantity: 1, type: 'baggage' }], |
| 62 | + } as any |
| 63 | + |
| 64 | + expect(hasService(offerWithBaggage, [])).toBe(true) |
| 65 | + expect(hasService(offerWithBaggage, undefined)).toBe(true) |
| 66 | + }) |
| 67 | +}) |
0 commit comments