Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Jun 2, 2022
1 parent 0c96a5d commit 092c9a3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
9 changes: 6 additions & 3 deletions packages/api/src/platforms/vtex/resolvers/offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnhancedSku> }
type OrderFormProduct = OrderFormItem & { product: EnhancedSku }
type SearchProduct = ArrayElementType<
ReturnType<typeof StoreAggregateOffer.offers>
>
Expand Down Expand Up @@ -96,13 +96,16 @@ export const StoreOffer: Record<string, Resolver<Root>> = {

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
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/platforms/vtex/resolvers/validateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => ({
Expand Down
22 changes: 11 additions & 11 deletions packages/api/test/__snapshots__/queries.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down
16 changes: 8 additions & 8 deletions packages/api/test/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import {
import { getContextFactory, getSchema } from '../src'
import type { Options } from '../src'

let schema: GraphQLSchema
let context: Record<string, any>

const apiOptions = {
platform: 'vtex',
account: 'storeframework',
Expand All @@ -33,6 +30,9 @@ const apiOptions = {
},
} as Options

let schema: GraphQLSchema
let context: Record<string, any>
const contextFactory = getContextFactory(apiOptions)
const mockedFetch = jest.fn()

function pickFetchAPICallResult(
Expand All @@ -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 = [
Expand Down
8 changes: 3 additions & 5 deletions packages/api/test/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import {
attributeSearchCategory1Fetch,
} from '../mocks/SearchQuery'

let schema: GraphQLSchema
let context: Record<string, any>

const apiOptions = {
platform: 'vtex',
account: 'storeframework',
Expand All @@ -45,6 +42,9 @@ const apiOptions = {
},
} as Options

let schema: GraphQLSchema
let context: Record<string, any>
const contextFactory = getContextFactory(apiOptions)
const mockedFetch = jest.fn()

function pickFetchAPICallResult(
Expand All @@ -70,8 +70,6 @@ jest.mock('../src/platforms/vtex/clients/fetch.ts', () => ({
beforeAll(async () => {
schema = await getSchema(apiOptions)

const contextFactory = getContextFactory(apiOptions)

context = contextFactory({})
})

Expand Down

0 comments on commit 092c9a3

Please sign in to comment.