Stripped redundant fields from public member offers endpoint#26737
Stripped redundant fields from public member offers endpoint#26737
Conversation
WalkthroughAdds a new 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/server/services/offers/application/offers-api.test.js (1)
116-138: Assert the nestedtierpayload too.This only validates top-level keys, so it would still pass if
toPublicDTO()started leakingtier.name. Since the new contract is about stripping admin-only fields, please pin the nested shape as well.Suggested assertion
assert.deepEqual(keys.sort(), [ 'amount', 'cadence', 'currency', 'display_description', 'display_title', 'duration', 'duration_in_months', 'id', 'redemption_type', 'status', 'tier', 'type' ]); + + assert.deepEqual(result[0].tier, {id: tierId}); assert.equal(result[0].name, undefined); assert.equal(result[0].code, undefined); assert.equal(result[0].currency_restriction, undefined); assert.equal(result[0].redemption_count, undefined);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/services/offers/application/offers-api.test.js` around lines 116 - 138, The test currently only checks top-level keys; extend it to assert the nested tier payload from the public DTO to prevent admin-only fields leaking. Locate the returned object used in the test (result[0]) and add assertions that check Object.keys(result[0].tier).sort() equals the expected public tier keys (pin the exact allowed keys for the public contract) and also assert result[0].tier.name === undefined (or any other admin-only fields are undefined). Reference the public serialization path (toPublicDTO / the code that produces result) and ensure the nested assertions explicitly validate the tier shape and absence of admin-only properties.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ghost/core/test/unit/server/services/offers/application/offers-api.test.js`:
- Around line 116-138: The test currently only checks top-level keys; extend it
to assert the nested tier payload from the public DTO to prevent admin-only
fields leaking. Locate the returned object used in the test (result[0]) and add
assertions that check Object.keys(result[0].tier).sort() equals the expected
public tier keys (pin the exact allowed keys for the public contract) and also
assert result[0].tier.name === undefined (or any other admin-only fields are
undefined). Reference the public serialization path (toPublicDTO / the code that
produces result) and ensure the nested assertions explicitly validate the tier
shape and absence of admin-only properties.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 81d57db6-b1d0-4d9e-8bb6-10f26af69870
📒 Files selected for processing (5)
ghost/core/core/server/services/offers/application/offer-mapper.jsghost/core/core/server/services/offers/application/offers-api.jsghost/core/test/e2e-api/members/member-offers.test.jsghost/core/test/unit/server/services/members/members-api/controllers/router-controller.test.jsghost/core/test/unit/server/services/offers/application/offers-api.test.js
no ref The `/members/api/member/offers/` endpoint was returning the full admin DTO but some of the fields were not are not needed by Portal. Added a `PublicOfferDTO` and `toPublicDTO` mapper that returns only the fields the public endpoint requires
b9554bf to
a808131
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/core/server/services/offers/application/offer-mapper.js (1)
88-112: LGTM! Clean implementation of public DTO mapping.The
toPublicDTOmethod correctly maps only the fields intended for public consumption. The separation fromtoDTOprovides clear intent and makes it easy to evolve each DTO independently.Minor observation: There's duplicated logic for computing
duration_in_monthsandcurrencybetweentoDTOandtoPublicDTO. If this mapper evolves further, consider extracting these computations into small private helpers. However, given the current scope and clarity of the code, this is purely optional.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/services/offers/application/offer-mapper.js` around lines 88 - 112, toPublicDTO duplicates logic present in toDTO for computing duration_in_months and currency; extract those expressions into small private helper functions (e.g., computeDurationInMonths(offer) and computeCurrency(offer)) and replace the inline ternaries in both toPublicDTO and toDTO with calls to those helpers so the duration_in_months and currency calculations are centralized and avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ghost/core/core/server/services/offers/application/offer-mapper.js`:
- Around line 88-112: toPublicDTO duplicates logic present in toDTO for
computing duration_in_months and currency; extract those expressions into small
private helper functions (e.g., computeDurationInMonths(offer) and
computeCurrency(offer)) and replace the inline ternaries in both toPublicDTO and
toDTO with calls to those helpers so the duration_in_months and currency
calculations are centralized and avoid duplication.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e2cee779-9a39-48ec-9e95-36aae91a9458
📒 Files selected for processing (5)
ghost/core/core/server/services/offers/application/offer-mapper.jsghost/core/core/server/services/offers/application/offers-api.jsghost/core/test/e2e-api/members/member-offers.test.jsghost/core/test/unit/server/services/members/members-api/controllers/router-controller.test.jsghost/core/test/unit/server/services/offers/application/offers-api.test.js
🚧 Files skipped from review as they are similar to previous changes (3)
- ghost/core/test/unit/server/services/offers/application/offers-api.test.js
- ghost/core/test/unit/server/services/members/members-api/controllers/router-controller.test.js
- ghost/core/core/server/services/offers/application/offers-api.js
no ref
The
/members/api/member/offers/endpoint was returning the full admin DTO but some of the fields were not are not needed by Portal. Added aPublicOfferDTOandtoPublicDTOmapper that returns only the fields the public endpoint requires