fix: source-shopify tests (#1192)

This commit is contained in:
Kasper Fabricius Kristensen
2022-03-15 20:12:52 +01:00
committed by GitHub
parent eb8e247e7d
commit 4be991c156
9 changed files with 73 additions and 18 deletions
@@ -1,3 +1,6 @@
module.exports = {
testEnvironment: "node",
transform: {
"^.+\\.[jt]s?$": `../../jest-transformer.js`,
},
}
+1 -1
View File
@@ -45,7 +45,7 @@
"client-sessions": "^0.8.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"jest": "^27.2.0"
"jest": "^26.6.3"
},
"gitHead": "cd1f5afa5aa8c0b15ea957008ee19f1d695cbd2e"
}
@@ -11,4 +11,7 @@ export const ProductCollectionServiceMock = {
retrieveByHandle: jest.fn().mockImplementation((handle) => {
return Promise.resolve(undefined)
}),
addProducts: jest.fn().mockImplementation((id, products) => {
return Promise.resolve()
}),
}
@@ -5,4 +5,14 @@ export const ShopifyRedisServiceMock = {
shouldIgnore: jest.fn().mockImplementation((_id, _event) => {
return false
}),
addUniqueValue: jest.fn().mockImplementation((val, type) => {
return Promise.resolve()
}),
getUniqueValue: jest.fn().mockImplementation((val, type) => {
if (val === "uniq") {
return Promise.resolve("uniq")
} else {
return Promise.resolve(undefined)
}
}),
}
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ShopifyCollectionService create normalizes a collection from Shopify 1`] = `
exports[`ShopifyCollectionService create normalizes a custom collection from Shopify 1`] = `
Object {
"handle": "spring",
"metadata": Object {
@@ -10,3 +10,14 @@ Object {
"title": "Spring",
}
`;
exports[`ShopifyCollectionService create normalizes a smart collection from Shopify 1`] = `
Object {
"handle": "ipods-1",
"metadata": Object {
"sh_body": null,
"sh_id": 1063001322,
},
"title": "IPods",
}
`;
@@ -2,7 +2,6 @@
exports[`ShopifyProductService normalizeProduct_ succesfully normalizes a product from Shopify 1`] = `
Object {
"collection_id": null,
"description": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.</p>",
"external_id": "shopify_ipod",
"handle": "ipod-nano",
@@ -12,6 +11,9 @@ Object {
"https://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1633120966",
],
"is_giftcard": false,
"metadata": Object {
"vendor": "Apple",
},
"options": Array [
Object {
"title": "Color",
@@ -2,7 +2,7 @@ import { MockManager } from "medusa-test-utils"
import ShopifyCollectionService from "../shopify-collection"
import { ProductCollectionServiceMock } from "../__mocks__/product-collection"
import { ShopifyProductServiceMock } from "../__mocks__/shopify-product"
import { shopifyProducts } from "../__mocks__/test-products"
import { medusaProducts } from "../__mocks__/test-products"
describe("ShopifyCollectionService", () => {
describe("create", () => {
@@ -16,7 +16,7 @@ describe("ShopifyCollectionService", () => {
jest.clearAllMocks()
})
it("creates a collection with a product", async () => {
it("creates a collection and adds products", async () => {
const collects = [
{
collection_id: "spring",
@@ -36,9 +36,9 @@ describe("ShopifyCollectionService", () => {
handle: "spring",
},
]
const products = [shopifyProducts.ipod]
const products = [medusaProducts.ipod]
const results = await shopifyCollectionService.createWithProducts(
const results = await shopifyCollectionService.createCustomCollections(
collects,
collections,
products
@@ -48,7 +48,6 @@ describe("ShopifyCollectionService", () => {
ProductCollectionServiceMock.retrieveByHandle
).toHaveBeenCalledTimes(1)
expect(ProductCollectionServiceMock.create).toHaveBeenCalledTimes(1)
expect(ShopifyProductServiceMock.create).toHaveBeenCalledTimes(1)
expect(results).toEqual([
{
id: "col_spring",
@@ -62,7 +61,7 @@ describe("ShopifyCollectionService", () => {
])
})
it("normalizes a collection from Shopify", () => {
it("normalizes a custom collection from Shopify", () => {
const shopifyCollection = {
id: "spring",
body_html: "spring collection",
@@ -70,9 +69,36 @@ describe("ShopifyCollectionService", () => {
handle: "spring",
}
const normalized = shopifyCollectionService.normalizeCollection_(
shopifyCollection
)
const normalized =
shopifyCollectionService.normalizeCustomCollection_(shopifyCollection)
expect(normalized).toMatchSnapshot()
})
it("normalizes a smart collection from Shopify", () => {
const shopifyCollection = {
id: 1063001322,
handle: "ipods-1",
title: "IPods",
updated_at: "2022-03-11T11:00:30-05:00",
body_html: null,
published_at: "2022-03-11T11:00:30-05:00",
sort_order: "best-selling",
template_suffix: null,
disjunctive: false,
rules: [
{
column: "title",
relation: "starts_with",
condition: "iPod",
},
],
published_scope: "web",
admin_graphql_api_id: "gid://shopify/Collection/1063001322",
}
const normalized =
shopifyCollectionService.normalizeCustomCollection_(shopifyCollection)
expect(normalized).toMatchSnapshot()
})
@@ -95,22 +95,22 @@ describe("ShopifyProductService", () => {
],
}))
await shopifyProductService.update(data)
await shopifyProductService.update(medusaProducts.ipod, data)
expect(ProductVariantServiceMock.update).toHaveBeenCalledTimes(8)
expect(ProductServiceMock.update).toHaveBeenCalledTimes(1)
expect(ShopifyClientServiceMock.get).toHaveBeenCalledTimes(1)
})
it("updates a product and deletes 2 existing variants", async () => {
const data = { ...shopifyProducts.ipod, id: "shopify_deleted" }
data.variants = data.variants.slice(1, -1)
await shopifyProductService.update(data)
await shopifyProductService.update(
{ ...medusaProducts.ipod, id: "shopify_deleted" },
data
)
expect(ProductVariantServiceMock.delete).toHaveBeenCalledTimes(2)
expect(ProductServiceMock.update).toHaveBeenCalledTimes(1)
expect(ShopifyClientServiceMock.get).toHaveBeenCalledTimes(1)
})
})
})
+1 -1
View File
@@ -18694,7 +18694,7 @@ jest@^26.6.3:
import-local "^3.0.2"
jest-cli "^26.6.3"
jest@^27.0.6, jest@^27.2.0:
jest@^27.0.6:
version "27.4.7"
resolved "https://registry.yarnpkg.com/jest/-/jest-27.4.7.tgz#87f74b9026a1592f2da05b4d258e57505f28eca4"
integrity sha512-8heYvsx7nV/m8m24Vk26Y87g73Ba6ueUd0MWed/NXMhSZIm62U/llVbS0PJe1SHunbyXjJ/BqG1z9bFjGUIvTg==