Skip to content

Commit

Permalink
fix final tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdstock committed Jan 31, 2024
1 parent 153a7c0 commit cc9bd83
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions src/Apps/Order/Routes/Shipping2/__tests__/Shipping2.jest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,27 +266,6 @@ let mockTrackEvent: jest.Mock

// FIXME: MockBoot interfering somehow...
describe("Shipping", () => {
const exhaustRelayOperations = async (env: MockEnvironment) => {
while (env.mock.getAllOperations().length > 0) {
await new Promise<void>((resolve, reject) => {
act(() => {
try {
const operation = env.mock.getMostRecentOperation()
const error = new Error(
"Unresolved operation after test: " +
operation.request.node.operation.name
)
env.mock.rejectMostRecentOperation(error)
console.log(error.message)
resolve()
} catch (error) {
reject(error)
}
})
})
}
}

const mockUseRouter = useRouter as jest.Mock
const mockPush = jest.fn()

Expand Down Expand Up @@ -1823,14 +1802,18 @@ describe("Shipping", () => {
meWithDefaultAddressInSpain.addressConnection.edges[0].node.isDefault = true // Spain
meWithDefaultAddressInSpain.addressConnection.edges[1].node.isDefault = false // US

const { env } = renderWithRelay({
const { env, mockResolveLastOperation } = renderWithRelay({
CommerceOrder: () =>
UntouchedBuyOrderWithArtsyShippingInternationalFromGermany,
Me: () => meWithDefaultAddressInSpain,
})
await flushPromiseQueue()

expect(() => env.mock.getMostRecentOperation()).toThrow()
await resolveSaveFulfillmentDetails(
mockResolveLastOperation,
settingOrderShipmentSuccess.commerceSetShipping
)

expect(getAllPendingOperationNames(env)).toEqual([])
expect(
screen.queryByRole("radio", {
name: /(^Standard|^Express|^White Glove|^Rush|^Premium)/,
Expand Down Expand Up @@ -1920,14 +1903,18 @@ describe("Shipping", () => {
})

it("does not set shipping on order if the collector is in the US", async () => {
const { env } = renderWithRelay({
const { env, mockResolveLastOperation } = renderWithRelay({
CommerceOrder: () =>
UntouchedBuyOrderWithArtsyShippingDomesticFromGermany,
Me: () => meWithAddresses,
})
await flushPromiseQueue()

expect(() => env.mock.getMostRecentOperation()).toThrow()
await resolveSaveFulfillmentDetails(
mockResolveLastOperation,
settingOrderShipmentSuccess.commerceSetShipping
)

expect(getAllPendingOperationNames(env)).toEqual([])
expect(
screen.queryByRole("radio", {
name: /(^Standard|^Express|^White Glove|^Rush|^Premium)/,
Expand All @@ -1944,14 +1931,18 @@ describe("Shipping", () => {
meWithDefaultAddressInSpain.addressConnection.edges[0].node.isDefault = true // Spain
meWithDefaultAddressInSpain.addressConnection.edges[1].node.isDefault = false // US

const { env } = renderWithRelay({
const { env, mockResolveLastOperation } = renderWithRelay({
CommerceOrder: () =>
UntouchedBuyOrderWithArtsyShippingDomesticFromUS,
Me: () => meWithDefaultAddressInSpain,
})
await flushPromiseQueue()

expect(() => env.mock.getMostRecentOperation()).toThrow()
await resolveSaveFulfillmentDetails(
mockResolveLastOperation,
settingOrderShipmentSuccess.commerceSetShipping
)

expect(getAllPendingOperationNames(env)).toEqual([])
expect(
screen.queryByRole("radio", {
name: /(^Standard|^Express|^White Glove|^Rush|^Premium)/,
Expand Down

0 comments on commit cc9bd83

Please sign in to comment.