chore(gatsby-source-medusa): Cleanup plugin setup (#4419)

* chore(gatsby-source-medusa): Cleanup plugin setup

* fix process-node

* Create gentle-cups-crash.md
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-06-27 14:00:11 +02:00
1 parent 85eb12883e
commit 627bdb689f
14 files changed
+74 -92

No files matched your search

@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`helper functions should return return a new node from processNode 1`] = `
Array [
Object {
"children": Array [],
"description": "A test product",
"id": "prod_test_1234",
"internal": Object {
"content": "{\\"id\\":\\"prod_test_1234\\",\\"title\\":\\"Test Shirt\\",\\"description\\":\\"A test product\\",\\"unit_price\\":2500}",
"contentDigest": "digest_string",
"type": "MedusaProduct",
},
"parent": null,
"title": "Test Shirt",
"unit_price": 2500,
},
]
`;
@@ -0,0 +1,20 @@
const { processNode } = require("../process-node.ts")
describe("helper functions", () => {
it("should return return a new node from processNode", () => {
const fieldName = "product"
const node = {
id: "prod_test_1234",
title: "Test Shirt",
description: "A test product",
unit_price: 2500,
}
const createContentDigest = jest.fn(() => "digest_string")
const processNodeResult = processNode(node, fieldName, createContentDigest)
expect(createContentDigest).toBeCalled()
expect(processNodeResult).toMatchSnapshot()
})
})
@@ -0,0 +1,29 @@
interface MedusaPluginOptions {
storeUrl: string
apiKey: string
}
interface MedusaProductImage {
url: string
metadata: Record<string, unknown> | null
id: string
created_at: string
updated_at: string
deleted_at: string | null
}
interface IMedusaOperation {
execute: () => Promise<any[]>
name: string
}
interface IOperations {
createProductsOperation: IMedusaOperation
createCollectionsOperation: IMedusaOperation
createRegionsOperation: IMedusaOperation
createOrdersOperation: IMedusaOperation
incrementalProductsOperation: (date: string) => IMedusaOperation
incrementalCollectionsOperation: (date: string) => IMedusaOperation
incrementalRegionsOperation: (date: string) => IMedusaOperation
incrementalOrdersOperation: (date: string) => IMedusaOperation
}
@@ -1,5 +1,3 @@
import { capitalize } from "./utils/capitalize"
export const processNode = (
node: any,
fieldName: string,
@@ -34,12 +32,14 @@ export const processNode = (
delete node.images
}
// TODO: use upperFirstCase from medusajs/utils when it's available
const type = `Medusa${fieldName[0].toUpperCase() + fieldName.slice(1)}`
const nodeData = Object.assign({}, node, {
id: nodeId,
parent: null,
children: [],
internal: {
type: `Medusa${capitalize(fieldName)}`,
type,
content: nodeContent,
contentDigest: nodeContentDigest,
},
@@ -1,3 +0,0 @@
export function capitalize(s: string): string {
return s[0].toUpperCase() + s.slice(1)
}