diff --git a/packages/api/src/platforms/vtex/utils/productStock.ts b/packages/api/src/platforms/vtex/utils/productStock.ts index a3acdb29c2..6bb6f24a07 100644 --- a/packages/api/src/platforms/vtex/utils/productStock.ts +++ b/packages/api/src/platforms/vtex/utils/productStock.ts @@ -3,8 +3,8 @@ import type { CommertialOffer } from '../clients/search/types/ProductSearchResul export const inStock = (offer: Pick) => offer.AvailableQuantity > 0 -export const price = (offer: Pick) => - offer.spotPrice ?? 0 +export const price = (offer: Pick) => offer.Price ?? 0 + export const sellingPrice = (offer: CommertialOffer) => offer.Price ?? 0 export const availability = (available: boolean) => @@ -12,8 +12,8 @@ export const availability = (available: boolean) => // Smallest Available Spot Price First export const bestOfferFirst = ( - a: Pick, - b: Pick + a: Pick, + b: Pick ) => { if (inStock(a) && !inStock(b)) { return -1 diff --git a/packages/api/test/vtex.aggregateOffer.test.ts b/packages/api/test/vtex.aggregateOffer.test.ts index 65248873f6..d46388c48a 100644 --- a/packages/api/test/vtex.aggregateOffer.test.ts +++ b/packages/api/test/vtex.aggregateOffer.test.ts @@ -1,26 +1,26 @@ import { bestOfferFirst } from '../src/platforms/vtex/utils/productStock' import type { CommertialOffer } from '../src/platforms/vtex/clients/search/types/ProductSearchResult' -type TestItem = Pick +type TestItem = Pick describe('AggregateOffer', () => { it('Should return best offers first', () => { const testItems: TestItem[] = [ - { AvailableQuantity: 1, spotPrice: 10 }, - { AvailableQuantity: 0, spotPrice: 20 }, - { AvailableQuantity: 1, spotPrice: 30 }, - { AvailableQuantity: 0, spotPrice: 10 }, - { AvailableQuantity: 1, spotPrice: 1 }, + { AvailableQuantity: 1, Price: 10 }, + { AvailableQuantity: 0, Price: 20 }, + { AvailableQuantity: 1, Price: 30 }, + { AvailableQuantity: 0, Price: 10 }, + { AvailableQuantity: 1, Price: 1 }, ] const sorted = testItems.sort(bestOfferFirst) expect(sorted).toEqual([ - { AvailableQuantity: 1, spotPrice: 1 }, - { AvailableQuantity: 1, spotPrice: 10 }, - { AvailableQuantity: 1, spotPrice: 30 }, - { AvailableQuantity: 0, spotPrice: 10 }, - { AvailableQuantity: 0, spotPrice: 20 }, + { AvailableQuantity: 1, Price: 1 }, + { AvailableQuantity: 1, Price: 10 }, + { AvailableQuantity: 1, Price: 30 }, + { AvailableQuantity: 0, Price: 10 }, + { AvailableQuantity: 0, Price: 20 }, ]) }) })