|
| 1 | +import { |
| 2 | + CollectiveOfferDisplayedStatus, |
| 3 | + EacFormat, |
| 4 | + OfferStatus, |
| 5 | +} from 'apiClient/v1' |
| 6 | +import { Audience } from 'core/shared/types' |
| 7 | +import { |
| 8 | + translateApiParamsToQueryParams, |
| 9 | + translateQueryParamsToApiParams, |
| 10 | +} from 'utils/translate' |
| 11 | + |
| 12 | +describe('translate', () => { |
| 13 | + it('should translate between query params to api params for collective offers', () => { |
| 14 | + expect( |
| 15 | + translateQueryParamsToApiParams( |
| 16 | + { |
| 17 | + 'nom-ou-isbn': 'input de recherche', |
| 18 | + structure: '883', |
| 19 | + lieu: '891', |
| 20 | + format: 'Concert', |
| 21 | + 'periode-evenement-debut': '2024-08-08', |
| 22 | + 'periode-evenement-fin': '2024-08-24', |
| 23 | + statut: ['en-attente', 'active'], |
| 24 | + }, |
| 25 | + Audience.COLLECTIVE |
| 26 | + ) |
| 27 | + ).toEqual( |
| 28 | + expect.objectContaining({ |
| 29 | + nameOrIsbn: 'input de recherche', |
| 30 | + offererId: '883', |
| 31 | + venueId: '891', |
| 32 | + format: 'Concert', |
| 33 | + periodBeginningDate: '2024-08-08', |
| 34 | + periodEndingDate: '2024-08-24', |
| 35 | + status: ['PENDING', 'ACTIVE'], |
| 36 | + }) |
| 37 | + ) |
| 38 | + |
| 39 | + expect( |
| 40 | + translateApiParamsToQueryParams( |
| 41 | + { |
| 42 | + nameOrIsbn: 'input de recherche', |
| 43 | + offererId: '883', |
| 44 | + venueId: '891', |
| 45 | + format: EacFormat.CONCERT, |
| 46 | + periodBeginningDate: '2024-08-08', |
| 47 | + periodEndingDate: '2024-08-24', |
| 48 | + status: [ |
| 49 | + CollectiveOfferDisplayedStatus.PENDING, |
| 50 | + CollectiveOfferDisplayedStatus.ACTIVE, |
| 51 | + ], |
| 52 | + }, |
| 53 | + Audience.COLLECTIVE |
| 54 | + ) |
| 55 | + ).toEqual( |
| 56 | + expect.objectContaining({ |
| 57 | + 'nom-ou-isbn': 'input de recherche', |
| 58 | + structure: '883', |
| 59 | + lieu: '891', |
| 60 | + format: 'Concert', |
| 61 | + 'periode-evenement-debut': '2024-08-08', |
| 62 | + 'periode-evenement-fin': '2024-08-24', |
| 63 | + statut: ['en-attente', 'active'], |
| 64 | + }) |
| 65 | + ) |
| 66 | + }) |
| 67 | + |
| 68 | + it('should translate query params to api params for individual offers', () => { |
| 69 | + expect( |
| 70 | + translateQueryParamsToApiParams( |
| 71 | + { |
| 72 | + 'nom-ou-isbn': 'input de recherche', |
| 73 | + structure: '883', |
| 74 | + lieu: '891', |
| 75 | + 'periode-evenement-debut': '2024-08-08', |
| 76 | + 'periode-evenement-fin': '2024-08-24', |
| 77 | + statut: 'draft', |
| 78 | + }, |
| 79 | + Audience.INDIVIDUAL |
| 80 | + ) |
| 81 | + ).toEqual( |
| 82 | + expect.objectContaining({ |
| 83 | + nameOrIsbn: 'input de recherche', |
| 84 | + offererId: '883', |
| 85 | + venueId: '891', |
| 86 | + periodBeginningDate: '2024-08-08', |
| 87 | + periodEndingDate: '2024-08-24', |
| 88 | + status: 'DRAFT', |
| 89 | + }) |
| 90 | + ) |
| 91 | + |
| 92 | + expect( |
| 93 | + translateApiParamsToQueryParams( |
| 94 | + { |
| 95 | + nameOrIsbn: 'input de recherche', |
| 96 | + offererId: '883', |
| 97 | + venueId: '891', |
| 98 | + periodBeginningDate: '2024-08-08', |
| 99 | + periodEndingDate: '2024-08-24', |
| 100 | + status: OfferStatus.DRAFT, |
| 101 | + }, |
| 102 | + Audience.INDIVIDUAL |
| 103 | + ) |
| 104 | + ).toEqual( |
| 105 | + expect.objectContaining({ |
| 106 | + 'nom-ou-isbn': 'input de recherche', |
| 107 | + structure: '883', |
| 108 | + lieu: '891', |
| 109 | + 'periode-evenement-debut': '2024-08-08', |
| 110 | + 'periode-evenement-fin': '2024-08-24', |
| 111 | + statut: 'draft', |
| 112 | + }) |
| 113 | + ) |
| 114 | + }) |
| 115 | + |
| 116 | + it('should not translate user inputs for collective offers', () => { |
| 117 | + expect( |
| 118 | + translateQueryParamsToApiParams( |
| 119 | + { |
| 120 | + 'nom-ou-isbn': 'en-attente', |
| 121 | + }, |
| 122 | + Audience.COLLECTIVE |
| 123 | + ) |
| 124 | + ).toEqual(expect.objectContaining({ nameOrIsbn: 'en-attente' })) |
| 125 | + }) |
| 126 | + |
| 127 | + it('should not translate user inputs for individual offers', () => { |
| 128 | + expect( |
| 129 | + translateQueryParamsToApiParams( |
| 130 | + { |
| 131 | + 'nom-ou-isbn': 'remboursements', |
| 132 | + }, |
| 133 | + Audience.INDIVIDUAL |
| 134 | + ) |
| 135 | + ).toEqual(expect.objectContaining({ nameOrIsbn: 'remboursements' })) |
| 136 | + }) |
| 137 | +}) |
0 commit comments