Skip to content

Commit

Permalink
(PC-32988) fix(offerToHeadlineOfferData): fix naming and upgrade cove…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
yleclercq-pass committed Feb 3, 2025
1 parent c3b1062 commit 581e840
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { offerToHeadlineOfferData } from 'features/headlineOffer/adapters/offerToHeadlineOfferData'
import { mockLabelMapping, mockMapping } from 'features/headlineOffer/fixtures/mockMapping'
import { Currency } from 'shared/currency/useGetCurrencyToDisplay'
import { offersFixture } from 'shared/offer/offer.fixture'

describe('offerToHeadlineOfferData', () => {
it('should transform headline offer data correctly', () => {
const result = offerToHeadlineOfferData({
offer: offersFixture[0],
transformParameters: {
mapping: mockMapping,
labelMapping: mockLabelMapping,
currency: Currency.EURO,
euroToPacificFrancRate: 10,
userLocation: { latitude: 1, longitude: 1 },
},
})

expect(result).toEqual({
id: '102280',
categoryId: 'LIVRE',
category: 'Livre papier',
imageUrl:
'https://storage.googleapis.com/passculture-metier-prod-production-assets-fine-grained/thumbs/mediations/CDNQ',
offerTitle: 'La nuit des temps',
price: 'Dès 28\u00a0€',
distance: '900+ km',
})
})

it('should return null if offer is null', () => {
const result = offerToHeadlineOfferData({
offer: null,
transformParameters: {
mapping: mockMapping,
labelMapping: mockLabelMapping,
currency: Currency.EURO,
euroToPacificFrancRate: 10,
userLocation: { latitude: 1, longitude: 1 },
},
})

expect(result).toBeNull()
})

it('should return an empty string if imageUrl is undefined', () => {
const offerWithoutImage = {
...offersFixture[0],
offer: { ...offersFixture[0].offer, thumbUrl: undefined },
}

const result = offerToHeadlineOfferData({
offer: offerWithoutImage,
transformParameters: {
mapping: mockMapping,
labelMapping: mockLabelMapping,
currency: Currency.EURO,
euroToPacificFrancRate: 10,
userLocation: { latitude: 1, longitude: 1 },
},
})

expect(result?.imageUrl).toBe('')
})

it('should return undefined if geolocation is missing', () => {
const offerWithoutGeoloc = {
...offersFixture[0],
_geoloc: {
lat: null,
lng: null,
},
}

const result = offerToHeadlineOfferData({
offer: offerWithoutGeoloc,
transformParameters: {
mapping: mockMapping,
labelMapping: mockLabelMapping,
currency: Currency.EURO,
euroToPacificFrancRate: 10,
userLocation: { latitude: 1, longitude: 1 },
},
})

expect(result?.distance).toBeUndefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type OfferToHeadlineOfferData = {
}

type OfferToHeadlineParams = {
offer: Offer
offer: Offer | null
transformParameters: OfferToHeadlineOfferData
}

Expand Down
2 changes: 1 addition & 1 deletion src/features/venue/components/VenueBody/VenueBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled, { useTheme } from 'styled-components/native'

import { VenueResponse } from 'api/gen'
import { GtlPlaylistData } from 'features/gtlPlaylist/types'
import { offerToHeadlineOfferData } from 'features/headlineOffer/adapters/headlineOfferData'
import { offerToHeadlineOfferData } from 'features/headlineOffer/adapters/offerToHeadlineOfferData'
import { HeadlineOffer } from 'features/headlineOffer/components/HeadlineOffer/HeadlineOffer'
import { PracticalInformation } from 'features/venue/components/PracticalInformation/PracticalInformation'
import { TabLayout } from 'features/venue/components/TabLayout/TabLayout'
Expand Down

0 comments on commit 581e840

Please sign in to comment.