diff --git a/packages/api/src/platforms/vtex/resolvers/offer.ts b/packages/api/src/platforms/vtex/resolvers/offer.ts index 4e5a8513b5..03e22084cc 100644 --- a/packages/api/src/platforms/vtex/resolvers/offer.ts +++ b/packages/api/src/platforms/vtex/resolvers/offer.ts @@ -11,7 +11,7 @@ import type { ArrayElementType } from '../../../typings' import type { EnhancedSku } from '../utils/enhanceSku' import type { OrderFormItem } from '../clients/commerce/types/OrderForm' -type OrderFormProduct = OrderFormItem & { product: Promise } +type OrderFormProduct = OrderFormItem & { product: EnhancedSku } type SearchProduct = ArrayElementType< ReturnType > @@ -96,13 +96,16 @@ export const StoreOffer: Record> = { return null }, - itemOffered: async (root) => { + itemOffered: (root) => { if (isSearchItem(root)) { return root.product } if (isOrderFormItem(root)) { - return { ...(await root.product), attachmentsValues: root.attachments } + return { + ...root.product, + attachmentsValues: root.attachments, + } } return null diff --git a/packages/api/src/platforms/vtex/resolvers/validateCart.ts b/packages/api/src/platforms/vtex/resolvers/validateCart.ts index 357838d78f..fad69b07c1 100644 --- a/packages/api/src/platforms/vtex/resolvers/validateCart.ts +++ b/packages/api/src/platforms/vtex/resolvers/validateCart.ts @@ -96,16 +96,16 @@ const equals = (storeOrder: IStoreOrder, orderForm: OrderForm) => { return isSameOrder && orderItemsAreSync } -const orderFormToCart = ( +const orderFormToCart = async ( form: OrderForm, skuLoader: Context['loaders']['skuLoader'] ) => { return { order: { orderNumber: form.orderFormId, - acceptedOffer: form.items.map((item) => ({ + acceptedOffer: form.items.map(async (item) => ({ ...item, - product: skuLoader.load(item.id), // TODO: add channel + product: await skuLoader.load(item.id), // TODO: add channel })), }, messages: form.messages.map(({ text, status }) => ({ diff --git a/packages/api/test/__snapshots__/queries.test.ts.snap b/packages/api/test/__snapshots__/queries.test.ts.snap index 713487a7a0..f2dd88f8ec 100644 --- a/packages/api/test/__snapshots__/queries.test.ts.snap +++ b/packages/api/test/__snapshots__/queries.test.ts.snap @@ -232,7 +232,7 @@ Object { "productID": "99988213", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/4k-philips-monitor/p", "description": "4k Philips Monitor 27\\"", "title": "4k Philips Monitor 27\\"", "titleTemplate": "", @@ -290,7 +290,7 @@ Object { "productID": "99988211", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/aedle-vk1-headphone/p", "description": "Aedle VK-1 L Headphone", "title": "Aedle VK-1 L Headphone", "titleTemplate": "", @@ -348,7 +348,7 @@ Object { "productID": "99988214", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/echo-dot-smart-speaker/p", "description": "Echo Dot Smart Speaker", "title": "Echo Dot Smart Speaker", "titleTemplate": "", @@ -406,7 +406,7 @@ Object { "productID": "99988210", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/oculus-vr-headset/p", "description": "Virtual reality kit", "title": "Oculus VR Headset", "titleTemplate": "", @@ -464,7 +464,7 @@ Object { "productID": "99988212", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/apple-magic-mouse/p", "description": "Apple Magic Mouse", "title": "Apple Magic Mouse", "titleTemplate": "", @@ -601,7 +601,7 @@ Object { "productID": "64953394", "review": Array [], "seo": Object { - "canonical": "", + "canonical": "/unbranded-concrete-table-small/p", "description": "Aut omnis nobis tenetur.", "title": "Unbranded Concrete Table Small", "titleTemplate": "", @@ -771,7 +771,7 @@ Object { "itemCondition": "https://schema.org/NewCondition", "itemOffered": Object { "seo": Object { - "canonical": "", + "canonical": "/licensed-cotton-hat-licensed/p", "description": "Consequatur placeat optio adipisci aut voluptate excepturi.", "title": "Licensed Cotton Hat Licensed", "titleTemplate": "", @@ -843,7 +843,7 @@ Object { "itemCondition": "https://schema.org/NewCondition", "itemOffered": Object { "seo": Object { - "canonical": "", + "canonical": "/handmade-granite-computer-unbranded/p", "description": "Ipsa in sequi incidunt dolores.", "title": "Handmade Granite Computer Unbranded", "titleTemplate": "", @@ -929,7 +929,7 @@ Object { "itemCondition": "https://schema.org/NewCondition", "itemOffered": Object { "seo": Object { - "canonical": "", + "canonical": "/small-cotton-cheese-3325400227651/p", "description": "Dolor harum perferendis voluptatem tempora voluptatum ut et sapiente iure.", "title": "Small Cotton Cheese", "titleTemplate": "", @@ -1001,7 +1001,7 @@ Object { "itemCondition": "https://schema.org/NewCondition", "itemOffered": Object { "seo": Object { - "canonical": "", + "canonical": "/tasty-frozen-tuna-handmade/p", "description": "Recusandae dolores alias.", "title": "Tasty Frozen Tuna Handmade", "titleTemplate": "", @@ -1077,7 +1077,7 @@ Object { "itemCondition": "https://schema.org/NewCondition", "itemOffered": Object { "seo": Object { - "canonical": "", + "canonical": "/sleek-metal-pizza/p", "description": "Aliquam a cumque ratione voluptatem in.", "title": "Sleek Metal Pizza", "titleTemplate": "", diff --git a/packages/api/test/mutations.test.ts b/packages/api/test/mutations.test.ts index 4747631c7b..c72afb86c3 100644 --- a/packages/api/test/mutations.test.ts +++ b/packages/api/test/mutations.test.ts @@ -18,9 +18,6 @@ import { import { getContextFactory, getSchema } from '../src' import type { Options } from '../src' -let schema: GraphQLSchema -let context: Record - const apiOptions = { platform: 'vtex', account: 'storeframework', @@ -33,6 +30,9 @@ const apiOptions = { }, } as Options +let schema: GraphQLSchema +let context: Record +const contextFactory = getContextFactory(apiOptions) const mockedFetch = jest.fn() function pickFetchAPICallResult( @@ -58,15 +58,15 @@ jest.mock('../src/platforms/vtex/clients/fetch.ts', () => ({ beforeAll(async () => { schema = await getSchema(apiOptions) - - const contextFactory = getContextFactory(apiOptions) - - context = contextFactory({}) }) // Always clear the mocked fetch before each test so we can count and validate // the calls performed by each query independently. -beforeEach(() => mockedFetch.mockClear()) +beforeEach(() => { + mockedFetch.mockClear() + + context = contextFactory({}) +}) test('`validateCart` mutation should return `null` when a valid cart is passed', async () => { const fetchAPICalls = [ diff --git a/packages/api/test/queries.test.ts b/packages/api/test/queries.test.ts index 04e8b2bb6b..b6d3681ce7 100644 --- a/packages/api/test/queries.test.ts +++ b/packages/api/test/queries.test.ts @@ -30,9 +30,6 @@ import { attributeSearchCategory1Fetch, } from '../mocks/SearchQuery' -let schema: GraphQLSchema -let context: Record - const apiOptions = { platform: 'vtex', account: 'storeframework', @@ -45,6 +42,9 @@ const apiOptions = { }, } as Options +let schema: GraphQLSchema +let context: Record +const contextFactory = getContextFactory(apiOptions) const mockedFetch = jest.fn() function pickFetchAPICallResult( @@ -70,8 +70,6 @@ jest.mock('../src/platforms/vtex/clients/fetch.ts', () => ({ beforeAll(async () => { schema = await getSchema(apiOptions) - const contextFactory = getContextFactory(apiOptions) - context = contextFactory({}) })