diff --git a/integration-tests/api/.babelrc.js b/integration-tests/api/.babelrc.js index 39c0fa3e45..bde709c495 100644 --- a/integration-tests/api/.babelrc.js +++ b/integration-tests/api/.babelrc.js @@ -1,13 +1,13 @@ -let ignore = [`**/dist`]; +let ignore = [`**/dist`] // Jest needs to compile this code, but generally we don't want this copied // to output folders if (process.env.NODE_ENV !== `test`) { - ignore.push(`**/__tests__`); + ignore.push(`**/__tests__`) } module.exports = { sourceMaps: true, presets: ["babel-preset-medusa-package"], ignore, -}; +} diff --git a/integration-tests/api/__tests__/store/draft-order.js b/integration-tests/api/__tests__/store/draft-order.js index 6821163f8d..f36bac585f 100644 --- a/integration-tests/api/__tests__/store/draft-order.js +++ b/integration-tests/api/__tests__/store/draft-order.js @@ -1,63 +1,63 @@ -const path = require("path"); +const path = require("path") -const setupServer = require("../../../helpers/setup-server"); -const { useApi } = require("../../../helpers/use-api"); -const { initDb, useDb } = require("../../../helpers/use-db"); +const setupServer = require("../../../helpers/setup-server") +const { useApi } = require("../../../helpers/use-api") +const { initDb, useDb } = require("../../../helpers/use-db") -const draftOrderSeeder = require("../../helpers/draft-order-seeder"); +const draftOrderSeeder = require("../../helpers/draft-order-seeder") -jest.setTimeout(30000); +jest.setTimeout(30000) describe("/store/carts (draft-orders)", () => { - let medusaProcess; - let dbConnection; + let medusaProcess + let dbConnection beforeAll(async () => { - const cwd = path.resolve(path.join(__dirname, "..", "..")); - dbConnection = await initDb({ cwd }); - medusaProcess = await setupServer({ cwd }); - }); + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ cwd }) + medusaProcess = await setupServer({ cwd }) + }) afterAll(async () => { - const db = useDb(); - await db.shutdown(); + const db = useDb() + await db.shutdown() - medusaProcess.kill(); - }); + medusaProcess.kill() + }) describe("POST /admin/draft-order", () => { beforeEach(async () => { try { - await draftOrderSeeder(dbConnection); + await draftOrderSeeder(dbConnection) } catch (err) { - console.log(err); - throw err; + console.log(err) + throw err } - }); + }) afterEach(async () => { - const db = useDb(); - await db.teardown(); - }); + const db = useDb() + await db.teardown() + }) it("completes a cart for a draft order thereby creating an order for the draft order", async () => { - const api = useApi(); + const api = useApi() const response = await api .post("/store/carts/test-cart/complete-cart", {}) .catch((err) => { - console.log(err); - }); + console.log(err) + }) - expect(response.status).toEqual(200); + expect(response.status).toEqual(200) const createdOrder = await api .get(`/store/orders/${response.data.data.id}`, {}) .catch((err) => { - console.log(err); - }); + console.log(err) + }) - expect(createdOrder.data.order.cart_id).toEqual("test-cart"); - }); - }); -}); + expect(createdOrder.data.order.cart_id).toEqual("test-cart") + }) + }) +}) diff --git a/integration-tests/api/__tests__/store/gift-cards.js b/integration-tests/api/__tests__/store/gift-cards.js index 7b69120fa2..83b72f86ff 100644 --- a/integration-tests/api/__tests__/store/gift-cards.js +++ b/integration-tests/api/__tests__/store/gift-cards.js @@ -1,63 +1,63 @@ -const path = require("path"); -const { Region, GiftCard } = require("@medusajs/medusa"); +const path = require("path") +const { Region, GiftCard } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server"); -const { useApi } = require("../../../helpers/use-api"); -const { initDb, useDb } = require("../../../helpers/use-db"); +const setupServer = require("../../../helpers/setup-server") +const { useApi } = require("../../../helpers/use-api") +const { initDb, useDb } = require("../../../helpers/use-db") -jest.setTimeout(30000); +jest.setTimeout(30000) describe("/store/gift-cards", () => { - let medusaProcess; - let dbConnection; + let medusaProcess + let dbConnection beforeAll(async () => { - const cwd = path.resolve(path.join(__dirname, "..", "..")); - dbConnection = await initDb({ cwd }); - medusaProcess = await setupServer({ cwd }); - }); + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ cwd }) + medusaProcess = await setupServer({ cwd }) + }) afterAll(async () => { - const db = useDb(); - await db.shutdown(); - medusaProcess.kill(); - }); + const db = useDb() + await db.shutdown() + medusaProcess.kill() + }) describe("GET /store/gift-cards/:code", () => { beforeEach(async () => { - const manager = dbConnection.manager; + const manager = dbConnection.manager await manager.insert(Region, { id: "region", name: "Test Region", currency_code: "usd", tax_rate: 0, - }); + }) await manager.insert(GiftCard, { id: "gift_test", code: "GC_TEST", value: 200, balance: 120, region_id: "region", - }); - }); + }) + }) afterEach(async () => { - const db = useDb(); - await db.teardown(); - }); + const db = useDb() + await db.teardown() + }) it("retrieves a gift card", async () => { - const api = useApi(); + const api = useApi() - const response = await api.get("/store/gift-cards/GC_TEST"); - expect(response.status).toEqual(200); + const response = await api.get("/store/gift-cards/GC_TEST") + expect(response.status).toEqual(200) expect(response.data.gift_card).toEqual({ id: "gift_test", code: "GC_TEST", value: 200, balance: 120, region: expect.any(Object), - }); - }); - }); -}); + }) + }) + }) +}) diff --git a/integration-tests/api/__tests__/store/return-reason.js b/integration-tests/api/__tests__/store/return-reason.js index 8aa0c4c9d4..9cc8138daf 100644 --- a/integration-tests/api/__tests__/store/return-reason.js +++ b/integration-tests/api/__tests__/store/return-reason.js @@ -1,94 +1,96 @@ -const path = require("path"); +const path = require("path") -const { ReturnReason } = require("@medusajs/medusa"); +const { ReturnReason } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server"); -const { useApi } = require("../../../helpers/use-api"); -const { initDb, useDb } = require("../../../helpers/use-db"); +const setupServer = require("../../../helpers/setup-server") +const { useApi } = require("../../../helpers/use-api") +const { initDb, useDb } = require("../../../helpers/use-db") -jest.setTimeout(30000); +jest.setTimeout(30000) describe("/store/return-reasons", () => { - let medusaProcess; - let dbConnection; + let medusaProcess + let dbConnection beforeAll(async () => { - const cwd = path.resolve(path.join(__dirname, "..", "..")); - dbConnection = await initDb({ cwd }); - medusaProcess = await setupServer({ cwd }); - }); + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ cwd }) + medusaProcess = await setupServer({ cwd }) + }) afterAll(async () => { - const db = useDb(); - await db.shutdown(); - medusaProcess.kill(); - }); + const db = useDb() + await db.shutdown() + medusaProcess.kill() + }) describe("GET /store/return-reasons", () => { - let rrId; - let rrId_1; - let rrId_2; + let rrId + let rrId_1 + let rrId_2 beforeEach(async () => { try { const created = dbConnection.manager.create(ReturnReason, { value: "wrong_size", label: "Wrong size", - }); + }) - const result = await dbConnection.manager.save(created); - rrId = result.id; + const result = await dbConnection.manager.save(created) + rrId = result.id const created_child = dbConnection.manager.create(ReturnReason, { value: "too_big", label: "Too Big", - parent_return_reason_id: rrId - }); + parent_return_reason_id: rrId, + }) - const result_child = await dbConnection.manager.save(created_child); - rrId_1 = result_child.id; + const result_child = await dbConnection.manager.save(created_child) + rrId_1 = result_child.id const created_2 = dbConnection.manager.create(ReturnReason, { value: "too_big_1", label: "Too Big 1", - }); + }) - const result_2 = await dbConnection.manager.save(created_2); - rrId_2 = result_2.id; + const result_2 = await dbConnection.manager.save(created_2) + rrId_2 = result_2.id } catch (err) { - console.log(err); - throw err; + console.log(err) + throw err } - }); + }) afterEach(async () => { - const db = useDb(); - await db.teardown(); - }); + const db = useDb() + await db.teardown() + }) it("list return reasons", async () => { - const api = useApi(); + const api = useApi() const response = await api.get("/store/return-reasons").catch((err) => { - console.log(err); - }); + console.log(err) + }) - expect(response.status).toEqual(200); + expect(response.status).toEqual(200) expect(response.data.return_reasons).toEqual([ expect.objectContaining({ id: rrId, value: "wrong_size", - return_reason_children:[expect.objectContaining({ - id: rrId_1, - value: "too_big", - }),] + return_reason_children: [ + expect.objectContaining({ + id: rrId_1, + value: "too_big", + }), + ], }), expect.objectContaining({ id: rrId_2, value: "too_big_1", }), - ]); - }); - }); -}); + ]) + }) + }) +}) diff --git a/integration-tests/api/__tests__/store/returns.js b/integration-tests/api/__tests__/store/returns.js index 3d5151dedb..d01a90047e 100644 --- a/integration-tests/api/__tests__/store/returns.js +++ b/integration-tests/api/__tests__/store/returns.js @@ -1,4 +1,4 @@ -const path = require("path"); +const path = require("path") const { Region, ReturnReason, @@ -12,56 +12,56 @@ const { LineItem, Discount, DiscountRule, -} = require("@medusajs/medusa"); +} = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server"); -const { useApi } = require("../../../helpers/use-api"); -const { initDb, useDb } = require("../../../helpers/use-db"); +const setupServer = require("../../../helpers/setup-server") +const { useApi } = require("../../../helpers/use-api") +const { initDb, useDb } = require("../../../helpers/use-db") -jest.setTimeout(30000); +jest.setTimeout(30000) describe("/store/carts", () => { - let medusaProcess; - let dbConnection; + let medusaProcess + let dbConnection beforeAll(async () => { - const cwd = path.resolve(path.join(__dirname, "..", "..")); - dbConnection = await initDb({ cwd }); - medusaProcess = await setupServer({ cwd }); - }); + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ cwd }) + medusaProcess = await setupServer({ cwd }) + }) afterAll(async () => { - const db = useDb(); - await db.shutdown(); - medusaProcess.kill(); - }); + const db = useDb() + await db.shutdown() + medusaProcess.kill() + }) describe("POST /store/returns", () => { - let rrId; - let rrId_child; - let rrResult; + let rrId + let rrId_child + let rrResult beforeEach(async () => { - const manager = dbConnection.manager; + const manager = dbConnection.manager await manager.query( `ALTER SEQUENCE order_display_id_seq RESTART WITH 111` - ); + ) const defaultProfile = await manager.findOne(ShippingProfile, { type: "default", - }); - + }) + await manager.insert(Region, { id: "region", name: "Test Region", currency_code: "usd", tax_rate: 0, - }); - + }) + await manager.insert(Customer, { id: "cus_1234", email: "test@email.com", - }); + }) await manager.insert(Order, { id: "order_test", @@ -71,7 +71,7 @@ describe("/store/carts", () => { region_id: "region", tax_rate: 0, currency_code: "usd", - }); + }) await manager.insert(DiscountRule, { id: "discount_rule_id", @@ -79,7 +79,7 @@ describe("/store/carts", () => { value: 10, allocation: "total", type: "percentage", - }); + }) const d = manager.create(Discount, { id: "test-discount", @@ -87,9 +87,9 @@ describe("/store/carts", () => { is_dynamic: false, is_disabled: false, rule_id: "discount_rule_id", - }); + }) - await manager.save(d); + await manager.save(d) const ord = manager.create(Order, { id: "order_with_discount", @@ -99,18 +99,18 @@ describe("/store/carts", () => { region_id: "region", tax_rate: 0, currency_code: "usd", - }); + }) - ord.discounts = [d]; + ord.discounts = [d] - await manager.save(ord); + await manager.save(ord) await manager.insert(Product, { id: "test-product", title: "test product", profile_id: defaultProfile.id, options: [{ id: "test-option", title: "Size" }], - }); + }) await manager.insert(ProductVariant, { id: "test-variant", @@ -123,7 +123,7 @@ describe("/store/carts", () => { value: "Size", }, ], - }); + }) await manager.insert(LineItem, { id: "test-item", @@ -135,7 +135,7 @@ describe("/store/carts", () => { unit_price: 8000, quantity: 1, variant_id: "test-variant", - }); + }) await manager.insert(ShippingOption, { id: "test-option", @@ -147,35 +147,35 @@ describe("/store/carts", () => { price_type: "flat_rate", amount: 1000, is_return: true, - }); + }) const created = dbConnection.manager.create(ReturnReason, { value: "wrong_size", label: "Wrong Size", - }); - const result = await dbConnection.manager.save(created); + }) + const result = await dbConnection.manager.save(created) rrResult = result - rrId = result.id; + rrId = result.id const created_1 = dbConnection.manager.create(ReturnReason, { value: "too_big", label: "Too Big", parent_return_reason_id: rrId, - }); + }) - const result_1 = await dbConnection.manager.save(created_1); + const result_1 = await dbConnection.manager.save(created_1) - rrId_child = result_1.id; - }); + rrId_child = result_1.id + }) afterEach(async () => { - const db = useDb(); - await db.teardown(); - }); + const db = useDb() + await db.teardown() + }) it("creates a return", async () => { - const api = useApi(); + const api = useApi() const response = await api .post("/store/returns", { @@ -188,16 +188,16 @@ describe("/store/carts", () => { ], }) .catch((err) => { - return err.response; - }); - expect(response.status).toEqual(200); + return err.response + }) + expect(response.status).toEqual(200) - expect(response.data.return.refund_amount).toEqual(8000); - }); + expect(response.data.return.refund_amount).toEqual(8000) + }) it("failes to create a return with a reason category", async () => { - const api = useApi(); - + const api = useApi() + const response = await api .post("/store/returns", { order_id: "order_test", @@ -211,17 +211,18 @@ describe("/store/carts", () => { ], }) .catch((err) => { - return err.response; - }); + return err.response + }) - expect(response.status).toEqual(400); - expect(response.data.message).toEqual('Cannot apply return reason category') - - }); + expect(response.status).toEqual(400) + expect(response.data.message).toEqual( + "Cannot apply return reason category" + ) + }) it("creates a return with reasons", async () => { - const api = useApi(); - + const api = useApi() + const response = await api .post("/store/returns", { order_id: "order_test", @@ -236,28 +237,28 @@ describe("/store/carts", () => { }) .catch((err) => { console.log(err.response) - return err.response; - }); - expect(response.status).toEqual(200); + return err.response + }) + expect(response.status).toEqual(200) expect(response.data.return.items).toEqual([ expect.objectContaining({ reason_id: rrId_child, note: "TOO small", }), - ]); - }); + ]) + }) it("creates a return with discount and non-discountable item", async () => { - const api = useApi(); + const api = useApi() await dbConnection.manager.query( `UPDATE line_item set allow_discounts=false where id='test-item'` - ); + ) await dbConnection.manager.query( `UPDATE line_item set order_id='order_with_discount' where id='test-item'` - ); + ) const response = await api .post("/store/returns", { @@ -270,15 +271,15 @@ describe("/store/carts", () => { ], }) .catch((err) => { - return err.response; - }); + return err.response + }) - expect(response.status).toEqual(200); - expect(response.data.return.refund_amount).toEqual(8000); - }); + expect(response.status).toEqual(200) + expect(response.data.return.refund_amount).toEqual(8000) + }) it("creates a return with shipping method", async () => { - const api = useApi(); + const api = useApi() const response = await api .post("/store/returns", { @@ -294,12 +295,11 @@ describe("/store/carts", () => { ], }) .catch((err) => { - return err.response; - }); - expect(response.status).toEqual(200); + return err.response + }) + expect(response.status).toEqual(200) - expect(response.data.return.refund_amount).toEqual(7000); - }); - - }); -}); + expect(response.data.return.refund_amount).toEqual(7000) + }) + }) +}) diff --git a/integration-tests/api/__tests__/store/shipping-options.js b/integration-tests/api/__tests__/store/shipping-options.js index 2a9858facd..5f929bf008 100644 --- a/integration-tests/api/__tests__/store/shipping-options.js +++ b/integration-tests/api/__tests__/store/shipping-options.js @@ -1,51 +1,51 @@ -const path = require("path"); -const { Region, ShippingProfile, ShippingOption } = require("@medusajs/medusa"); +const path = require("path") +const { Region, ShippingProfile, ShippingOption } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server"); -const { useApi } = require("../../../helpers/use-api"); -const { initDb, useDb } = require("../../../helpers/use-db"); +const setupServer = require("../../../helpers/setup-server") +const { useApi } = require("../../../helpers/use-api") +const { initDb, useDb } = require("../../../helpers/use-db") -jest.setTimeout(30000); +jest.setTimeout(30000) describe("/store/shipping-options", () => { - let medusaProcess; - let dbConnection; + let medusaProcess + let dbConnection beforeAll(async () => { - const cwd = path.resolve(path.join(__dirname, "..", "..")); - dbConnection = await initDb({ cwd }); - medusaProcess = await setupServer({ cwd }); - }); + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ cwd }) + medusaProcess = await setupServer({ cwd }) + }) afterAll(async () => { - const db = useDb(); - await db.shutdown(); - medusaProcess.kill(); - }); + const db = useDb() + await db.shutdown() + medusaProcess.kill() + }) describe("POST /store/shipping-options", () => { beforeEach(async () => { - const manager = dbConnection.manager; + const manager = dbConnection.manager await manager.query( `ALTER SEQUENCE order_display_id_seq RESTART WITH 111` - ); + ) await manager.insert(Region, { id: "region", name: "Test Region", currency_code: "usd", tax_rate: 0, - }); + }) await manager.insert(Region, { id: "region2", name: "Test Region 2", currency_code: "usd", tax_rate: 0, - }); + }) const defaultProfile = await manager.findOne(ShippingProfile, { type: "default", - }); + }) await manager.insert(ShippingOption, { id: "test-out", @@ -57,7 +57,7 @@ describe("/store/shipping-options", () => { price_type: "flat_rate", amount: 2000, is_return: false, - }); + }) await manager.insert(ShippingOption, { id: "test-return", @@ -69,7 +69,7 @@ describe("/store/shipping-options", () => { price_type: "flat_rate", amount: 1000, is_return: true, - }); + }) await manager.insert(ShippingOption, { id: "test-region2", @@ -81,51 +81,51 @@ describe("/store/shipping-options", () => { price_type: "flat_rate", amount: 1000, is_return: false, - }); - }); + }) + }) afterEach(async () => { - const db = useDb(); - await db.teardown(); - }); + const db = useDb() + await db.teardown() + }) it("retrieves all shipping options", async () => { - const api = useApi(); + const api = useApi() const response = await api.get("/store/shipping-options").catch((err) => { - return err.response; - }); + return err.response + }) - expect(response.status).toEqual(200); - expect(response.data.shipping_options.length).toEqual(3); - }); + expect(response.status).toEqual(200) + expect(response.data.shipping_options.length).toEqual(3) + }) it("creates a return with shipping method", async () => { - const api = useApi(); + const api = useApi() const response = await api .get("/store/shipping-options?is_return=true") .catch((err) => { - return err.response; - }); + return err.response + }) - expect(response.status).toEqual(200); - expect(response.data.shipping_options.length).toEqual(1); - expect(response.data.shipping_options[0].id).toEqual("test-return"); - }); + expect(response.status).toEqual(200) + expect(response.data.shipping_options.length).toEqual(1) + expect(response.data.shipping_options[0].id).toEqual("test-return") + }) it("creates a return with shipping method", async () => { - const api = useApi(); + const api = useApi() const response = await api .get("/store/shipping-options?region_id=region2") .catch((err) => { - return err.response; - }); + return err.response + }) - expect(response.status).toEqual(200); - expect(response.data.shipping_options.length).toEqual(1); - expect(response.data.shipping_options[0].id).toEqual("test-region2"); - }); - }); -}); + expect(response.status).toEqual(200) + expect(response.data.shipping_options.length).toEqual(1) + expect(response.data.shipping_options[0].id).toEqual("test-region2") + }) + }) +}) diff --git a/integration-tests/api/helpers/call-helpers.js b/integration-tests/api/helpers/call-helpers.js index 9ecc592811..9a9233d42d 100644 --- a/integration-tests/api/helpers/call-helpers.js +++ b/integration-tests/api/helpers/call-helpers.js @@ -1,33 +1,33 @@ -const { useApi } = require("../../helpers/use-api"); +const { useApi } = require("../../helpers/use-api") const header = { headers: { authorization: "Bearer test_token", }, -}; +} const resolveCall = async (path, payload, header) => { - const api = useApi(); - let res; + const api = useApi() + let res try { - const resp = await api.post(path, payload, header); - res = resp.status; + const resp = await api.post(path, payload, header) + res = resp.status } catch (expectedException) { try { - res = expectedException.response.status; + res = expectedException.response.status } catch (_) { - console.error(expectedException); + console.error(expectedException) } } - return res; -}; + return res +} const determineFail = (actual, expected, path) => { if (expected !== actual) { - console.log(`failed at path : ${path}`); + console.log(`failed at path : ${path}`) } - expect(actual).toEqual(expected); -}; + expect(actual).toEqual(expected) +} /** * Allows you to wrap a Call function so that you may reuse some input values. @@ -36,8 +36,8 @@ const determineFail = (actual, expected, path) => { * @returns */ module.exports.partial = function (fun, input = {}) { - return async (remaining) => await fun({ ...remaining, ...input }); -}; + return async (remaining) => await fun({ ...remaining, ...input }) +} /** * Allows you to assert a specific code result from a POST call. @@ -51,9 +51,9 @@ module.exports.expectPostCallToReturn = async function ( payload: {}, } ) { - const res = await resolveCall(input.path, input.payload, header); - determineFail(res, input.code, input.path); -}; + const res = await resolveCall(input.path, input.payload, header) + determineFail(res, input.code, input.path) +} /** * Allows you to assert a specific code result from multiple POST @@ -76,10 +76,10 @@ module.exports.expectAllPostCallsToReturn = async function ( input.pathf(i), input.payloadf ? input.payloadf(i) : {}, header - ); - determineFail(res, input.code, input.pathf(i)); + ) + determineFail(res, input.code, input.pathf(i)) } -}; +} /** * Allows you to retrieve a specific object the response @@ -92,9 +92,9 @@ module.exports.expectAllPostCallsToReturn = async function ( * to the get parameter provided. */ module.exports.callGet = async function ({ path, get }) { - const api = useApi(); - const res = await api.get(path, header); + const api = useApi() + const res = await api.get(path, header) - determineFail(res.status, 200, path); - return res?.data[get]; -}; + determineFail(res.status, 200, path) + return res?.data[get] +} diff --git a/integration-tests/api/helpers/claim-seeder.js b/integration-tests/api/helpers/claim-seeder.js index 7c34d987e8..ae19e09e68 100644 --- a/integration-tests/api/helpers/claim-seeder.js +++ b/integration-tests/api/helpers/claim-seeder.js @@ -4,10 +4,10 @@ const { LineItem, Fulfillment, Return, -} = require("@medusajs/medusa"); +} = require("@medusajs/medusa") module.exports = async (connection, data = {}) => { - const manager = connection.manager; + const manager = connection.manager let orderWithClaim = manager.create(Order, { id: "order-with-claim", @@ -40,9 +40,9 @@ module.exports = async (connection, data = {}) => { ], items: [], ...data, - }); + }) - await manager.save(orderWithClaim); + await manager.save(orderWithClaim) const li = manager.create(LineItem, { id: "test-item-co-2", @@ -54,9 +54,9 @@ module.exports = async (connection, data = {}) => { quantity: 1, variant_id: "test-variant", order_id: orderWithClaim.id, - }); + }) - await manager.save(li); + await manager.save(li) const li2 = manager.create(LineItem, { id: "test-item-co-3", @@ -68,9 +68,9 @@ module.exports = async (connection, data = {}) => { quantity: 4, variant_id: "test-variant", order_id: orderWithClaim.id, - }); + }) - await manager.save(li2); + await manager.save(li2) const claimWithFulfillment = manager.create(ClaimOrder, { id: "claim-w-f", @@ -79,23 +79,23 @@ module.exports = async (connection, data = {}) => { fulfillment_status: "not_fulfilled", order_id: "order-with-claim", ...data, - }); + }) const ful1 = manager.create(Fulfillment, { id: "fulfillment-co-1", data: {}, provider_id: "test-ful", - }); + }) const ful2 = manager.create(Fulfillment, { id: "fulfillment-co-2", data: {}, provider_id: "test-ful", - }); + }) - claimWithFulfillment.fulfillments = [ful1, ful2]; + claimWithFulfillment.fulfillments = [ful1, ful2] - await manager.save(claimWithFulfillment); + await manager.save(claimWithFulfillment) const claimWithReturn = manager.create(ClaimOrder, { id: "claim-w-r", @@ -104,9 +104,9 @@ module.exports = async (connection, data = {}) => { fulfillment_status: "not_fulfilled", order_id: "order-with-claim", ...data, - }); + }) - await manager.save(claimWithReturn); + await manager.save(claimWithReturn) await manager.insert(Return, { id: "return-id-2", @@ -114,5 +114,5 @@ module.exports = async (connection, data = {}) => { status: "requested", refund_amount: 0, data: {}, - }); -}; + }) +} diff --git a/integration-tests/api/helpers/draft-order-seeder.js b/integration-tests/api/helpers/draft-order-seeder.js index 5adfc9bf30..19b63b0d7c 100644 --- a/integration-tests/api/helpers/draft-order-seeder.js +++ b/integration-tests/api/helpers/draft-order-seeder.js @@ -14,35 +14,35 @@ const { Discount, DiscountRule, Payment, -} = require("@medusajs/medusa"); +} = require("@medusajs/medusa") module.exports = async (connection, data = {}) => { - const manager = connection.manager; + const manager = connection.manager const defaultProfile = await manager.findOne(ShippingProfile, { type: "default", - }); + }) await manager.insert(Product, { id: "test-product", title: "test product", profile_id: defaultProfile.id, options: [{ id: "test-option", title: "Size" }], - }); + }) await manager.insert(Address, { id: "oli-shipping", first_name: "oli", last_name: "test", country_code: "us", - }); + }) await manager.insert(Product, { id: "test-product-2", title: "test product 2", profile_id: defaultProfile.id, options: [{ id: "test-option-color", title: "Color" }], - }); + }) await manager.insert(ProductVariant, { id: "test-variant", @@ -55,7 +55,7 @@ module.exports = async (connection, data = {}) => { value: "Size", }, ], - }); + }) await manager.insert(ProductVariant, { id: "test-variant-2", @@ -68,22 +68,22 @@ module.exports = async (connection, data = {}) => { value: "Color", }, ], - }); + }) const ma = manager.create(MoneyAmount, { variant_id: "test-variant", currency_code: "usd", amount: 8000, - }); - await manager.save(ma); + }) + await manager.save(ma) const ma2 = manager.create(MoneyAmount, { variant_id: "test-variant-2", currency_code: "usd", amount: 10000, - }); + }) - await manager.save(ma2); + await manager.save(ma2) await manager.insert(Region, { id: "test-region", @@ -96,7 +96,7 @@ module.exports = async (connection, data = {}) => { is_installed: true, }, ], - }); + }) await manager.insert(Region, { id: "test-region-2", @@ -109,7 +109,7 @@ module.exports = async (connection, data = {}) => { is_installed: true, }, ], - }); + }) await manager.insert(DiscountRule, { id: "discount_rule_id", @@ -117,7 +117,7 @@ module.exports = async (connection, data = {}) => { value: 10, allocation: "total", type: "percentage", - }); + }) const d = manager.create(Discount, { id: "test-discount", @@ -125,7 +125,7 @@ module.exports = async (connection, data = {}) => { is_dynamic: false, is_disabled: false, rule_id: "discount_rule_id", - }); + }) d.regions = [ { @@ -134,27 +134,27 @@ module.exports = async (connection, data = {}) => { currency_code: "usd", tax_rate: 0, }, - ]; + ] - await manager.save(d); + await manager.save(d) await manager.query( `UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'` - ); + ) await manager.query( `UPDATE "country" SET region_id='test-region-2' WHERE iso_2 = 'de'` - ); + ) await manager.insert(Customer, { id: "oli-test", email: "oli@test.dk", - }); + }) await manager.insert(Customer, { id: "lebron-james", email: "lebron@james.com", - }); + }) await manager.insert(ShippingOption, { id: "test-option", @@ -165,7 +165,7 @@ module.exports = async (connection, data = {}) => { price_type: "flat_rate", amount: 1000, data: {}, - }); + }) await manager.insert(ShippingOption, { id: "test-option-req", @@ -176,14 +176,14 @@ module.exports = async (connection, data = {}) => { price_type: "flat_rate", amount: 1000, data: {}, - }); + }) await manager.insert(ShippingOptionRequirement, { id: "option-req", shipping_option_id: "test-option-req", type: "min_subtotal", amount: 10, - }); + }) const c = manager.create(Cart, { id: "test-cart", @@ -207,7 +207,7 @@ module.exports = async (connection, data = {}) => { ], type: "draft_order", metadata: { draft_order_id: "test-draft-order" }, - }); + }) const pay = manager.create(Payment, { id: "test-payment", @@ -216,13 +216,13 @@ module.exports = async (connection, data = {}) => { amount_refunded: 0, provider_id: "test-pay", data: {}, - }); + }) - await manager.save(pay); + await manager.save(pay) - c.payment = pay; + c.payment = pay - await manager.save(c); + await manager.save(c) await manager.insert(PaymentSession, { id: "test-session", @@ -231,7 +231,7 @@ module.exports = async (connection, data = {}) => { is_selected: true, data: {}, status: "authorized", - }); + }) const draftOrder = manager.create(DraftOrder, { id: "test-draft-order", @@ -255,7 +255,7 @@ module.exports = async (connection, data = {}) => { region_id: "test-region", discounts: [], ...data, - }); + }) - await manager.save(draftOrder); -}; + await manager.save(draftOrder) +} diff --git a/integration-tests/api/helpers/order-seeder.js b/integration-tests/api/helpers/order-seeder.js index ac3bde962c..dcd270a139 100644 --- a/integration-tests/api/helpers/order-seeder.js +++ b/integration-tests/api/helpers/order-seeder.js @@ -12,21 +12,21 @@ const { Payment, Order, Swap, -} = require("@medusajs/medusa"); +} = require("@medusajs/medusa") module.exports = async (connection, data = {}) => { - const manager = connection.manager; + const manager = connection.manager const defaultProfile = await manager.findOne(ShippingProfile, { type: "default", - }); + }) await manager.insert(Product, { id: "test-product", title: "test product", profile_id: defaultProfile.id, options: [{ id: "test-option", title: "Size" }], - }); + }) await manager.insert(ProductVariant, { id: "test-variant", @@ -39,7 +39,7 @@ module.exports = async (connection, data = {}) => { value: "Size", }, ], - }); + }) await manager.insert(ProductVariant, { id: "test-variant-2", @@ -52,37 +52,37 @@ module.exports = async (connection, data = {}) => { value: "Large", }, ], - }); + }) const ma2 = manager.create(MoneyAmount, { variant_id: "test-variant-2", currency_code: "usd", amount: 8000, - }); - await manager.save(ma2); + }) + await manager.save(ma2) const ma = manager.create(MoneyAmount, { variant_id: "test-variant", currency_code: "usd", amount: 8000, - }); - await manager.save(ma); + }) + await manager.save(ma) await manager.insert(Region, { id: "test-region", name: "Test Region", currency_code: "usd", tax_rate: 0, - }); + }) await manager.query( `UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'` - ); + ) await manager.insert(Customer, { id: "test-customer", email: "test@email.com", - }); + }) await manager.insert(ShippingOption, { id: "test-option", @@ -93,7 +93,7 @@ module.exports = async (connection, data = {}) => { price_type: "flat_rate", amount: 1000, data: {}, - }); + }) await manager.insert(ShippingOption, { id: "test-return-option", @@ -105,7 +105,7 @@ module.exports = async (connection, data = {}) => { price_type: "flat_rate", amount: 1000, is_return: true, - }); + }) const order = manager.create(Order, { id: "test-order", @@ -157,9 +157,9 @@ module.exports = async (connection, data = {}) => { ], items: [], ...data, - }); + }) - await manager.save(order); + await manager.save(order) const li = manager.create(LineItem, { id: "test-item", @@ -172,9 +172,9 @@ module.exports = async (connection, data = {}) => { quantity: 1, variant_id: "test-variant", order_id: "test-order", - }); + }) - await manager.save(li); + await manager.save(li) await manager.insert(ShippingMethod, { id: "test-method", @@ -183,7 +183,7 @@ module.exports = async (connection, data = {}) => { order_id: "test-order", price: 1000, data: {}, - }); + }) const orderTemplate = () => { return { @@ -195,8 +195,8 @@ module.exports = async (connection, data = {}) => { currency_code: "usd", tax_rate: 0, ...data, - }; - }; + } + } const paymentTemplate = () => { return { @@ -204,8 +204,8 @@ module.exports = async (connection, data = {}) => { currency_code: "usd", provider_id: "test-pay", data: {}, - }; - }; + } + } const orderWithClaim = manager.create(Order, { id: "test-order-w-c", @@ -219,59 +219,59 @@ module.exports = async (connection, data = {}) => { }, ], ...orderTemplate(), - }); + }) - await manager.save(orderWithClaim); + await manager.save(orderWithClaim) await manager.insert(Payment, { order_id: "test-order-w-c", id: "o-pay1", ...paymentTemplate(), - }); + }) const orderWithSwap = manager.create(Order, { id: "test-order-w-s", ...orderTemplate(), - }); + }) - await manager.save(orderWithSwap); + await manager.save(orderWithSwap) await manager.insert(Payment, { order_id: "test-order-w-s", id: "o-pay2", ...paymentTemplate(), - }); + }) const swap1 = manager.create(Swap, { id: "swap-1", order_id: "test-order-w-s", fulfillment_status: "not_fulfilled", payment_status: "not_paid", - }); + }) const pay1 = manager.create(Payment, { id: "pay1", ...paymentTemplate(), - }); + }) - swap1.payment = pay1; + swap1.payment = pay1 const swap2 = manager.create(Swap, { id: "swap-2", order_id: "test-order-w-s", fulfillment_status: "not_fulfilled", payment_status: "not_paid", - }); + }) const pay2 = manager.create(Payment, { id: "pay2", ...paymentTemplate(), - }); + }) - swap2.payment = pay2; + swap2.payment = pay2 - await manager.save(swap1); - await manager.save(swap2); + await manager.save(swap1) + await manager.save(swap2) const orderWithFulfillment = manager.create(Order, { id: "test-order-w-f", @@ -288,15 +288,15 @@ module.exports = async (connection, data = {}) => { }, ], ...orderTemplate(), - }); + }) - await manager.save(orderWithFulfillment); + await manager.save(orderWithFulfillment) await manager.insert(Payment, { order_id: "test-order-w-f", id: "o-pay3", ...paymentTemplate(), - }); + }) const orderWithReturn = manager.create(Order, { id: "test-order-w-r", @@ -311,13 +311,13 @@ module.exports = async (connection, data = {}) => { }, ], ...orderTemplate(), - }); + }) - await manager.save(orderWithReturn); + await manager.save(orderWithReturn) await manager.insert(Payment, { order_id: "test-order-w-r", id: "o-pay4", ...paymentTemplate(), - }); -}; + }) +} diff --git a/integration-tests/api/helpers/swap-seeder.js b/integration-tests/api/helpers/swap-seeder.js index e19203493f..eff5553017 100644 --- a/integration-tests/api/helpers/swap-seeder.js +++ b/integration-tests/api/helpers/swap-seeder.js @@ -112,13 +112,13 @@ module.exports = async (connection, data = {}) => { type: "swap", metadata: {}, ...data, - }); + }) - await manager.save(cart); - }; + await manager.save(cart) + } const swapTemplate = async (cartId) => { - await cartTemplate(cartId); + await cartTemplate(cartId) return { order_id: orderWithSwap.id, fulfillment_status: "fulfilled", @@ -132,8 +132,8 @@ module.exports = async (connection, data = {}) => { data: {}, }, ...data, - }; - }; + } + } const swapWithFulfillments = manager.create(Swap, { id: "swap-w-f", @@ -150,9 +150,9 @@ module.exports = async (connection, data = {}) => { }, ], ...(await swapTemplate("sc-w-f")), - }); + }) - await manager.save(swapWithFulfillments); + await manager.save(swapWithFulfillments) const swapWithReturn = manager.create(Swap, { id: "swap-w-r", @@ -162,9 +162,9 @@ module.exports = async (connection, data = {}) => { refund_amount: 0, }, ...(await swapTemplate("sc-w-r")), - }); + }) - await manager.save(swapWithReturn); + await manager.save(swapWithReturn) const li = manager.create(LineItem, { id: "return-item-1", fulfilled_quantity: 1, diff --git a/integration-tests/api/jest.config.js b/integration-tests/api/jest.config.js index af00a0c2f4..caebf0e68a 100644 --- a/integration-tests/api/jest.config.js +++ b/integration-tests/api/jest.config.js @@ -13,4 +13,4 @@ module.exports = { ], transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` }, setupFilesAfterEnv: ["../setup.js"], -}; +} diff --git a/integration-tests/api/src/services/test-ful.js b/integration-tests/api/src/services/test-ful.js index b73427707c..f7726108ac 100644 --- a/integration-tests/api/src/services/test-ful.js +++ b/integration-tests/api/src/services/test-ful.js @@ -1,10 +1,10 @@ -import { FulfillmentService } from "medusa-interfaces"; +import { FulfillmentService } from "medusa-interfaces" class TestFulService extends FulfillmentService { - static identifier = "test-ful"; + static identifier = "test-ful" constructor() { - super(); + super() } getFulfillmentOptions() { @@ -12,42 +12,42 @@ class TestFulService extends FulfillmentService { { id: "manual-fulfillment", }, - ]; + ] } validateFulfillmentData(data, cart) { - return data; + return data } validateOption(data) { - return true; + return true } canCalculate() { - return false; + return false } calculatePrice() { - throw Error("Manual Fulfillment service cannot calculatePrice"); + throw Error("Manual Fulfillment service cannot calculatePrice") } createOrder() { // No data is being sent anywhere - return Promise.resolve({}); + return Promise.resolve({}) } createReturn() { - return Promise.resolve({}); + return Promise.resolve({}) } createFulfillment() { // No data is being sent anywhere - return Promise.resolve({}); + return Promise.resolve({}) } cancelFulfillment() { - return Promise.resolve({}); + return Promise.resolve({}) } } -export default TestFulService; +export default TestFulService diff --git a/integration-tests/api/src/services/test-not.js b/integration-tests/api/src/services/test-not.js index 852bed1b72..39c5ba665a 100644 --- a/integration-tests/api/src/services/test-not.js +++ b/integration-tests/api/src/services/test-not.js @@ -1,19 +1,19 @@ -import { NotificationService } from "medusa-interfaces"; +import { NotificationService } from "medusa-interfaces" class TestNotiService extends NotificationService { - static identifier = "test-not"; + static identifier = "test-not" constructor() { - super(); + super() } async sendNotification() { - return Promise.resolve(); + return Promise.resolve() } async resendNotification() { - return Promise.resolve(); + return Promise.resolve() } } -export default TestNotiService; +export default TestNotiService diff --git a/integration-tests/api/src/services/test-pay.js b/integration-tests/api/src/services/test-pay.js index 22725965ab..7536c45a45 100644 --- a/integration-tests/api/src/services/test-pay.js +++ b/integration-tests/api/src/services/test-pay.js @@ -1,59 +1,59 @@ -import { PaymentService } from "medusa-interfaces"; +import { PaymentService } from "medusa-interfaces" class TestPayService extends PaymentService { - static identifier = "test-pay"; + static identifier = "test-pay" constructor() { - super(); + super() } async getStatus(paymentData) { - return "authorized"; + return "authorized" } async retrieveSavedMethods(customer) { - return Promise.resolve([]); + return Promise.resolve([]) } async createPayment() { - return {}; + return {} } async retrievePayment(data) { - return {}; + return {} } async getPaymentData(sessionData) { - return {}; + return {} } async authorizePayment(sessionData, context = {}) { - return { data: {}, status: "authorized" }; + return { data: {}, status: "authorized" } } async updatePaymentData(sessionData, update) { - return {}; + return {} } async updatePayment(sessionData, cart) { - return {}; + return {} } async deletePayment(payment) { - return {}; + return {} } async capturePayment(payment) { - return {}; + return {} } async refundPayment(payment, amountToRefund) { - return {}; + return {} } async cancelPayment(payment) { - return {}; + return {} } } -export default TestPayService; +export default TestPayService diff --git a/integration-tests/helpers/test-server.js b/integration-tests/helpers/test-server.js index a06bc12ab8..7feb62d855 100644 --- a/integration-tests/helpers/test-server.js +++ b/integration-tests/helpers/test-server.js @@ -6,8 +6,10 @@ const importFrom = require("import-from") const initialize = async () => { const app = express() - const loaders = importFrom(process.cwd(), "@medusajs/medusa/dist/loaders") - .default + const loaders = importFrom( + process.cwd(), + "@medusajs/medusa/dist/loaders" + ).default const { dbConnection } = await loaders({ directory: path.resolve(process.cwd()), diff --git a/integration-tests/jest.config.js b/integration-tests/jest.config.js index bf175fbbeb..83f803a68e 100644 --- a/integration-tests/jest.config.js +++ b/integration-tests/jest.config.js @@ -1,8 +1,8 @@ -const glob = require(`glob`); +const glob = require(`glob`) const pkgs = glob .sync(`${__dirname}/*/`) - .map((p) => p.replace(__dirname, `/integration-tests`)); + .map((p) => p.replace(__dirname, `/integration-tests`)) module.exports = { testEnvironment: `node`, @@ -19,4 +19,4 @@ module.exports = { ], transform: { "^.+\\.[jt]s$": `/jest-transformer.js` }, setupFilesAfterEnv: ["/integration-tests/setup.js"], -}; +}