Skip to content

Commit

Permalink
Merge pull request #311 from macder/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
macder authored Aug 14, 2022
2 parents 91507f4 + 8d2043c commit c1e64c7
Show file tree
Hide file tree
Showing 63 changed files with 1,828 additions and 739 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
.DS_store
.env*
.idea/
!index.js
!.eslintrc.js
yarn.lock
Expand Down
1 change: 1 addition & 0 deletions src/services/__mocks__/address/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { addressSchema } from "./schema"
export { addressState } from "./state"
9 changes: 9 additions & 0 deletions src/services/__mocks__/address/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const addressState = (key) =>
({
empty: {
is_empty: true,
},
complete: {
is_empty: false,
},
}[key])
3 changes: 1 addition & 2 deletions src/services/__mocks__/cart/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { cartMock } from "./mock"
export { cartStub } from "./stub"
export { cartSchema } from "./schema"
export { cartServiceMock } from "./service"
export { cartState } from "./state"
17 changes: 0 additions & 17 deletions src/services/__mocks__/cart/mock.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/services/__mocks__/cart/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cartMock } from "./mock"
import { cartStub } from "./stub"

export const cartServiceMock = (state) => ({
retrieve: jest.fn(async (id) => cartMock(state)(id)),
retrieve: jest.fn(async (id) => cartStub(state)),
})
60 changes: 0 additions & 60 deletions src/services/__mocks__/cart/state.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/services/__mocks__/cart/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { addressSchema } from "../address"
import { cartSchema } from "./schema"
import { lineItemStub } from "../line-item"

export const cartStub = ({ ...state }) =>
cartSchema({
...state,
id: state.cart_id,
address: addressSchema({ ...state.address }),
items: state.line_items.map((item) => lineItemStub({ ...state, ...item })),
})
3 changes: 2 additions & 1 deletion src/services/__mocks__/fulfillment/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { fulfillmentMock } from "./mock"
export { fulfillmentStub } from "./stub"
export { fulfillmentRepoMock } from "./repo"
export { fulfillmentServiceMock } from "./service"
export { fulfillmentSchema, fulfillmentItemSchema } from "./schema"
export { fulfillmentState } from "./state"
24 changes: 0 additions & 24 deletions src/services/__mocks__/fulfillment/mock.js

This file was deleted.

8 changes: 2 additions & 6 deletions src/services/__mocks__/fulfillment/repo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { MockRepository } from "medusa-test-utils"
import { fulfillmentMock } from "./mock"
import { fulfillmentStub } from "./stub"

export const fulfillmentRepoMock = ({ ...state }) =>
MockRepository({
find: async (params) =>
state.fulfillments.map(({ items, shippo_order_id, id, tracking_links }) =>
fulfillmentMock({ ...state, shippo_order_id })(items, tracking_links)(
id
)
),
state.fulfillments.map((ful) => fulfillmentStub({ ...state, ...ful })),
})
8 changes: 5 additions & 3 deletions src/services/__mocks__/fulfillment/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const fulfillmentSchema = ({ ...props }) =>
no_notification: false,
provider_id: "shippo",
tracking_numbers: [],
data: Object.freeze({
shippo_order_id: props.shippo_order_id,
}),
data: props.shippo_order_id
? Object.freeze({
shippo_order_id: props.shippo_order_id,
})
: {},
shipped_at: "",
canceled_at: null,
metadata: {},
Expand Down
11 changes: 3 additions & 8 deletions src/services/__mocks__/fulfillment/service.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { fulfillmentMock } from "./mock"
import { fulfillmentStub } from "./stub"

export const fulfillmentServiceMock = (state) => {
const fulfillment = (id) => {
const { fulfillments } = state
const { items, shippo_order_id, tracking_links } = fulfillments.find(
(ful) => ful.id === id
)
return fulfillmentMock({ ...state, shippo_order_id })(
items,
tracking_links
)(id)
const fulfillment = fulfillments.find((ful) => ful.id === id)
return fulfillmentStub({ ...state, ...fulfillment })
}

return {
Expand Down
39 changes: 39 additions & 0 deletions src/services/__mocks__/fulfillment/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const fulfillmentState = (key) =>
({
no_shippo_order: {
id: "ful_no_shippo_order",
// shippo_order_id: "shippo_order_no_transactions",
items: ["item_123", "item_321"],
tracking_links: [],
},
has_shippo_order: {
id: "ful_has_shippo_order",
shippo_order_id: "shippo_order_no_transactions",
items: ["item_123", "item_321"],
tracking_links: [],
},
no_transaction: {
id: "ful_no_transactions",
shippo_order_id: "shippo_order_no_transactions",
items: ["item_123", "item_321"],
tracking_links: [],
},

has_transaction_for_label: {
id: "ful_has_transaction_for_label",
shippo_order_id: "shippo_order_has_transaction_for_label",
items: ["item_123", "item_321"],
tracking_links: ["track_label_01234567890"],
},

has_transaction_for_label_with_return: {
id: "ful_has_transaction_for_label_and_return_label",
shippo_order_id:
"shippo_order_has_transaction_for_label_and_return_label",
items: ["item_123", "item_321"],
tracking_links: [
"track_label_01234567890",
"track_return_label_01234567890",
],
},
}[key])
20 changes: 20 additions & 0 deletions src/services/__mocks__/fulfillment/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fulfillmentSchema, fulfillmentItemSchema } from "./schema"
import { trackingLinkSchema } from "../tracking-link"

export const fulfillmentStub = ({ ...state }) =>
fulfillmentSchema({
...state,
items: state.items.map((item_id) =>
fulfillmentItemSchema({
item_id,
fulfillment_id: state.id,
quantity: 2,
})
),
tracking_links: state.tracking_links.map((track) =>
trackingLinkSchema({
tracking_number: track,
fulfillment_id: state.id,
})
),
})
3 changes: 2 additions & 1 deletion src/services/__mocks__/line-item/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { lineItemMock } from "./mock"
export { lineItemStub } from "./stub"
export { lineItemServiceMock } from "./service"
export { lineItemSchema } from "./schema"
export { lineItemState } from "./state"
10 changes: 0 additions & 10 deletions src/services/__mocks__/line-item/mock.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/services/__mocks__/line-item/service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { lineItemMock } from "./mock"
import { lineItemStub } from "./stub"

export const lineItemServiceMock = ({ ...state }) => ({
list: jest.fn(),
retrieve: jest.fn(async (id) =>
lineItemMock(state)({ id: "product_id" })({ id: "variant_id" })(id)
),
retrieve: jest.fn(async (id) => lineItemStub(state)),
})
3 changes: 3 additions & 0 deletions src/services/__mocks__/line-item/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const lineItemState = ({ quantity = 1 }) => ({
quantity,
})
11 changes: 11 additions & 0 deletions src/services/__mocks__/line-item/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { lineItemSchema } from "./schema"
import { variantStub } from "../variant"

export const lineItemStub = ({ ...state }) =>
lineItemSchema({
...state,
variant: variantStub({
id: state.variant_id,
product_id: state.product_id,
}),
})
3 changes: 1 addition & 2 deletions src/services/__mocks__/order/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { orderMock } from "./mock"
export { orderStub } from "./stub"
export { orderSchema } from "./schema"
export { orderServiceMock } from "./service"
export { orderState } from "./state"
23 changes: 0 additions & 23 deletions src/services/__mocks__/order/mock.js

This file was deleted.

14 changes: 5 additions & 9 deletions src/services/__mocks__/order/service.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { orderMock } from "./mock"
import { orderStub } from "./stub"

export const orderServiceMock = (state) => {
const order = orderMock(state)

return {
list: jest.fn(async ({ display_id }) => [order(state.order_id)]),
retrieve: jest.fn(async (id) => order(id)),
}
}
export const orderServiceMock = (state) => ({
list: jest.fn(async ({ display_id }) => [orderStub(state)]),
retrieve: jest.fn(async (id) => orderStub(state)),
})
Loading

0 comments on commit c1e64c7

Please sign in to comment.