Issue #442 Prettier rules not applied to some integration tests files (#445)

This commit is contained in:
Mark authored and GitHub committed 2021-10-08 12:11:58 +02:00
1 parent fe0696569c
commit 3d891c9b4f
17 files changed
+419 -415

No files matched your search

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