Skip to content

Commit

Permalink
(PC-34454)[API] feat: add publicationDate to Algolia serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
bpeyrou-pass committed Feb 7, 2025
1 parent 56a3828 commit 41323a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/src/pcapi/core/search/backends/algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def serialize_offer(cls, offer: offers_models.Offer, last_30_days_bookings: int)
"isEvent": offer.isEvent,
"isForbiddenToUnderage": offer.is_forbidden_to_underage,
"isPermanent": offer.isPermanent,
"isReleased": offer.isReleased if offer.publicationDate else None,
"isThing": offer.isThing,
"last30DaysBookings": last_30_days_bookings,
"last30DaysBookingsRange": get_last_30_days_bookings_range(last_30_days_bookings),
Expand All @@ -573,6 +574,7 @@ def serialize_offer(cls, offer: offers_models.Offer, last_30_days_bookings: int)
"name": offer.name,
"nativeCategoryId": offer.subcategory.native_category_id,
"prices": sorted(prices),
"publicationDate": offer.publicationDate.isoformat() if offer.publicationDate else None,
"rankingWeight": offer.rankingWeight,
"releaseDate": release_date,
"bookFormat": extra_data.get("bookFormat"),
Expand Down
16 changes: 16 additions & 0 deletions api/tests/core/search/test_serialize_algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,22 @@ def test_serialize_venue_with_one_bookable_offer():
assert serialized["has_at_least_one_bookable_offer"]


def test_serialize_future_offer():
offer_1 = offers_factories.OfferFactory(isActive=False)
offer_2 = offers_factories.OfferFactory(isActive=True)
publication_date = datetime.datetime.utcnow() + datetime.timedelta(days=30)
offers_factories.FutureOfferFactory(offerId=offer_1.id, publicationDate=publication_date)
offers_factories.FutureOfferFactory(offerId=offer_2.id, publicationDate=publication_date)

serialized = algolia.AlgoliaBackend().serialize_offer(offer_1, 0)
assert serialized["offer"]["publicationDate"] == publication_date.isoformat()
assert serialized["offer"]["isReleased"] == False

serialized = algolia.AlgoliaBackend().serialize_offer(offer_2, 0)
assert serialized["offer"]["publicationDate"] == publication_date.isoformat()
assert serialized["offer"]["isReleased"] == True


def test_serialize_collective_offer_template():
domain1 = educational_factories.EducationalDomainFactory(name="Danse")
domain2 = educational_factories.EducationalDomainFactory(name="Architecture")
Expand Down

0 comments on commit 41323a8

Please sign in to comment.