docs: delete unused doc files (#2732)
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
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__`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sourceMaps: true,
|
||||
presets: ["babel-preset-medusa-package"],
|
||||
ignore,
|
||||
};
|
||||
4
docs-util/fixture-gen/.gitignore
vendored
4
docs-util/fixture-gen/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
dist/
|
||||
node_modules
|
||||
*yarn-error.log
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/auth", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/products", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("authenticates user", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post("/admin/auth", {
|
||||
email: "admin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("user", response.data.user);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,69 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
const productSeeder = require("../../helpers/product-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/collections", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/products", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a product", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const payload = {
|
||||
title: "Summer Collection",
|
||||
handle: "summer-collection",
|
||||
};
|
||||
|
||||
const response = await api
|
||||
.post("/admin/collections", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("product_collection", response.data.collection);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
const path = require("path");
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const { Customer, Address } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/customers", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("GET /admin/customers", () => {
|
||||
let id;
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
const created = manager.create(Customer, {
|
||||
email: "test1@email.com",
|
||||
});
|
||||
|
||||
const newly = await manager.save(created);
|
||||
|
||||
id = newly.id;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "address"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("lists customers and query count", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.get(`/admin/customers/${id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("customer", response.data.customer);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,82 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/discounts", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
let regId;
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
const created = manager.create(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
const newReg = await manager.save(created);
|
||||
regId = newReg.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.post(
|
||||
`/admin/discounts`,
|
||||
{
|
||||
code: "10DISC",
|
||||
rule: {
|
||||
description: "10 Percent",
|
||||
type: "percentage",
|
||||
allocation: "total",
|
||||
value: 10,
|
||||
},
|
||||
regions: [regId],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("discount", getRes.data.discount);
|
||||
fixtureWriter.addFixture("discount_rule", getRes.data.discount.rule);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/discounts", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/gift-cards", () => {
|
||||
let regId;
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
const created = manager.create(Region, {
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
const newReg = await manager.save(created);
|
||||
regId = newReg.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "gift_card"`);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.post(
|
||||
`/admin/gift-cards`,
|
||||
{
|
||||
value: 1000,
|
||||
region_id: regId,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("gift_card", getRes.data.gift_card);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,73 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Notification } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const orderSeeder = require("../../helpers/order-seeder");
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/orders", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("GET /notifications", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
const noti = manager.create(Notification, {
|
||||
event_name: "order.placed",
|
||||
resource_type: "order",
|
||||
resource_id: "order_01F0BF66ZBXNJ98WDQ9SCWH8Y7",
|
||||
provider_id: "test-not",
|
||||
data: {},
|
||||
to: "test@email.com",
|
||||
});
|
||||
await manager.save(noti);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "notification"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a claim", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(`/admin/notifications`, {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("notification", response.data.notifications[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,254 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { ProductVariant } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const orderSeeder = require("../../helpers/order-seeder");
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/orders", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("GET /admin/orders/:id", () => {
|
||||
let id;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
const order = await orderSeeder(dbConnection);
|
||||
id = order.id;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "fulfillment_item"`);
|
||||
await manager.query(`DELETE FROM "fulfillment"`);
|
||||
await manager.query(`DELETE FROM "swap"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "claim_image"`);
|
||||
await manager.query(`DELETE FROM "claim_tag"`);
|
||||
await manager.query(`DELETE FROM "claim_item"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "claim_order"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_option_value"`);
|
||||
await manager.query(`DELETE FROM "product_option"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "payment"`);
|
||||
await manager.query(`DELETE FROM "order"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a claim", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(`/admin/orders/${id}`, {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("order", response.data.order);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /admin/orders/:id/returns", () => {
|
||||
let id;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
const order = await orderSeeder(dbConnection);
|
||||
id = order.id;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "fulfillment_item"`);
|
||||
await manager.query(`DELETE FROM "fulfillment"`);
|
||||
await manager.query(`DELETE FROM "swap"`);
|
||||
await manager.query(`DELETE FROM "return_item"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "claim_image"`);
|
||||
await manager.query(`DELETE FROM "claim_tag"`);
|
||||
await manager.query(`DELETE FROM "claim_item"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "claim_order"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_option_value"`);
|
||||
await manager.query(`DELETE FROM "product_option"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "payment"`);
|
||||
await manager.query(`DELETE FROM "order"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a return", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const { data } = await api.get(`/admin/orders/${id}`, {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
const order = data.order;
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/orders/${id}/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: order.items[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("return", response.data.order.returns[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /admin/orders/:id/swaps", () => {
|
||||
let id;
|
||||
let varId;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
const order = await orderSeeder(dbConnection, {
|
||||
fulfillment_status: "fulfilled",
|
||||
payment_status: "captured",
|
||||
});
|
||||
id = order.id;
|
||||
|
||||
const pVar = await dbConnection.manager.findOne(ProductVariant, {});
|
||||
varId = pVar.id;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "fulfillment_item"`);
|
||||
await manager.query(`DELETE FROM "fulfillment"`);
|
||||
await manager.query(`DELETE FROM "return_item"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "claim_image"`);
|
||||
await manager.query(`DELETE FROM "claim_tag"`);
|
||||
await manager.query(`DELETE FROM "claim_item"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "swap"`);
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "claim_order"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_option_value"`);
|
||||
await manager.query(`DELETE FROM "product_option"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "payment"`);
|
||||
await manager.query(`DELETE FROM "order"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a swap", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const { data } = await api.get(`/admin/orders/${id}`, {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
const order = data.order;
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/orders/${id}/swaps`,
|
||||
{
|
||||
return_items: [
|
||||
{
|
||||
item_id: order.items[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: varId,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("swap", response.data.order.swaps[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,110 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
const productSeeder = require("../../helpers/product-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/products", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/products", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection);
|
||||
await adminSeeder(dbConnection);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "product_option_value"`);
|
||||
await manager.query(`DELETE FROM "product_option"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "product_collection"`);
|
||||
await manager.query(`DELETE FROM "product_tag"`);
|
||||
await manager.query(`DELETE FROM "product_type"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a product", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const payload = {
|
||||
title: "Test product",
|
||||
description: "test-product-description",
|
||||
type: { value: "test-type" },
|
||||
collection_id: "test-collection",
|
||||
tags: [{ value: "123" }, { value: "456" }],
|
||||
options: [{ title: "size" }, { title: "color" }],
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
inventory_quantity: 10,
|
||||
prices: [{ currency_code: "usd", amount: 100 }],
|
||||
options: [{ value: "large" }, { value: "green" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const response = await api
|
||||
.post("/admin/products", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("product", response.data.product);
|
||||
fixtureWriter.addFixture(
|
||||
"product_variant",
|
||||
response.data.product.variants[0]
|
||||
);
|
||||
fixtureWriter.addFixture(
|
||||
"product_option",
|
||||
response.data.product.options[0]
|
||||
);
|
||||
fixtureWriter.addFixture(
|
||||
"product_option_value",
|
||||
response.data.product.variants[0].options[0]
|
||||
);
|
||||
fixtureWriter.addFixture(
|
||||
"money_amount",
|
||||
response.data.product.variants[0].prices[0]
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,83 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/shipping-options", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/shipping-options", () => {
|
||||
let regId;
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
const created = manager.create(Region, {
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
fulfillment_providers: [
|
||||
{
|
||||
id: "test-ful",
|
||||
},
|
||||
],
|
||||
});
|
||||
const newReg = await manager.save(created);
|
||||
regId = newReg.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.post(
|
||||
`/admin/shipping-options`,
|
||||
{
|
||||
name: "Free Shipping",
|
||||
region_id: regId,
|
||||
provider_id: "test-ful",
|
||||
data: {},
|
||||
price_type: "flat_rate",
|
||||
amount: 100,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("region", getRes.data.shipping_option.region);
|
||||
fixtureWriter.addFixture("shipping_option", getRes.data.shipping_option);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,74 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/shipping-profiles", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/shipping-profiles", () => {
|
||||
let regId;
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection);
|
||||
const manager = dbConnection.manager;
|
||||
const created = manager.create(Region, {
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
fulfillment_providers: [
|
||||
{
|
||||
id: "test-ful",
|
||||
},
|
||||
],
|
||||
});
|
||||
const newReg = await manager.save(created);
|
||||
regId = newReg.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.get(`/admin/shipping-profiles`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture(
|
||||
"shipping_profile",
|
||||
getRes.data.shipping_profiles[0]
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,56 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/shipping-profiles", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("GET /admin/store", () => {
|
||||
let regId;
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.get(`/admin/store`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("store", getRes.data.store);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,67 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const cartSeeder = require("../../helpers/cart-seeder");
|
||||
|
||||
const fixtureWriter = require("../../utils/write-fixture").default;
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/store/carts", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.insert(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id='region' WHERE iso_2 = 'us'`
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.post("/store/carts");
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const getRes = await api.post(`/store/carts/${response.data.cart.id}`);
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
fixtureWriter.addFixture("cart", getRes.data.cart);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
const Scrypt = require("scrypt-kdf");
|
||||
const { User } = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
const buf = await Scrypt.kdf("secret_password", { logN: 1, r: 1, p: 1 });
|
||||
const password_hash = buf.toString("base64");
|
||||
|
||||
await manager.insert(User, {
|
||||
id: "admin_user",
|
||||
email: "admin@medusa.js",
|
||||
api_token: "test_token",
|
||||
password_hash,
|
||||
...data,
|
||||
});
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
const { Customer, Region, Cart } = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
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(Customer, {
|
||||
id: "test-customer-2",
|
||||
email: "test-2@email.com",
|
||||
});
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "some-customer",
|
||||
email: "some-customer@email.com",
|
||||
});
|
||||
|
||||
const cart = manager.create(Cart, {
|
||||
id: "test-cart",
|
||||
customer_id: "some-customer",
|
||||
email: "some-customer@email.com",
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
items: [],
|
||||
});
|
||||
|
||||
await manager.save(cart);
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
const { Customer, Address } = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "test-customer-1",
|
||||
email: "test1@email.com",
|
||||
});
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "test-customer-2",
|
||||
email: "test2@email.com",
|
||||
});
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "test-customer-3",
|
||||
email: "test3@email.com",
|
||||
});
|
||||
|
||||
await manager.insert(Address, {
|
||||
id: "test-address",
|
||||
first_name: "Lebron",
|
||||
last_name: "James",
|
||||
customer_id: "test-customer-1",
|
||||
});
|
||||
};
|
||||
@@ -1,152 +0,0 @@
|
||||
const {
|
||||
ShippingProfile,
|
||||
Customer,
|
||||
MoneyAmount,
|
||||
LineItem,
|
||||
Country,
|
||||
ShippingOption,
|
||||
ShippingMethod,
|
||||
Product,
|
||||
ProductOption,
|
||||
ProductVariant,
|
||||
Region,
|
||||
Order,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
const prodOption = manager.create(ProductOption, {
|
||||
title: "Size",
|
||||
});
|
||||
const newProdOption = await manager.save(prodOption);
|
||||
|
||||
const prod = manager.create(Product, {
|
||||
title: "test product",
|
||||
profile_id: defaultProfile.id,
|
||||
options: [newProdOption],
|
||||
});
|
||||
const newProd = await manager.save(prod);
|
||||
|
||||
const prodVar = manager.create(ProductVariant, {
|
||||
title: "test variant",
|
||||
product_id: newProd.id,
|
||||
inventory_quantity: 1,
|
||||
options: [
|
||||
{
|
||||
option_id: newProdOption.id,
|
||||
value: "Size",
|
||||
},
|
||||
],
|
||||
});
|
||||
const newProdVar = await manager.save(prodVar);
|
||||
|
||||
const ma = manager.create(MoneyAmount, {
|
||||
variant_id: newProdVar.id,
|
||||
currency_code: "usd",
|
||||
amount: 8000,
|
||||
});
|
||||
await manager.save(ma);
|
||||
|
||||
const region = manager.create(Region, {
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
const newReg = await manager.save(region);
|
||||
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id='${newReg.id}' WHERE iso_2 = 'us'`
|
||||
);
|
||||
|
||||
const customer = manager.create(Customer, {
|
||||
email: "test@email.com",
|
||||
});
|
||||
const newCustomer = await manager.save(customer);
|
||||
|
||||
const shipOpt = manager.create(ShippingOption, {
|
||||
name: "test-option",
|
||||
provider_id: "test-ful",
|
||||
region_id: newReg.id,
|
||||
profile_id: defaultProfile.id,
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
data: {},
|
||||
});
|
||||
const newShipOpt = await manager.save(shipOpt);
|
||||
|
||||
const order = manager.create(Order, {
|
||||
customer_id: newCustomer.id,
|
||||
email: "test@email.com",
|
||||
billing_address: {
|
||||
first_name: "lebron",
|
||||
},
|
||||
shipping_address: {
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: newReg.id,
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
discounts: [
|
||||
{
|
||||
id: "test-discount",
|
||||
code: "TEST134",
|
||||
is_dynamic: false,
|
||||
rule: {
|
||||
id: "test-rule",
|
||||
description: "Test Discount",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
is_disabled: false,
|
||||
regions: [
|
||||
{
|
||||
id: newReg.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
payments: [
|
||||
{
|
||||
id: "test-payment",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
items: [
|
||||
{
|
||||
id: "test-item",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: newProdVar.id,
|
||||
},
|
||||
],
|
||||
...data,
|
||||
});
|
||||
|
||||
const newOrder = await manager.save(order);
|
||||
|
||||
const shipMeth = manager.create(ShippingMethod, {
|
||||
order_id: newOrder.id,
|
||||
shipping_option_id: newShipOpt.id,
|
||||
price: 1000,
|
||||
data: {},
|
||||
});
|
||||
|
||||
await manager.save(shipMeth);
|
||||
|
||||
return newOrder;
|
||||
};
|
||||
@@ -1,68 +0,0 @@
|
||||
const {
|
||||
ProductCollection,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
Region,
|
||||
Product,
|
||||
ShippingProfile,
|
||||
ProductVariant,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
const coll = manager.create(ProductCollection, {
|
||||
id: "test-collection",
|
||||
title: "Test collection",
|
||||
});
|
||||
|
||||
await manager.save(coll);
|
||||
|
||||
const tag = manager.create(ProductTag, {
|
||||
id: "tag1",
|
||||
value: "123",
|
||||
});
|
||||
|
||||
await manager.save(tag);
|
||||
|
||||
const type = manager.create(ProductType, {
|
||||
id: "test-type",
|
||||
value: "test-type",
|
||||
});
|
||||
|
||||
await manager.save(type);
|
||||
|
||||
await manager.insert(Region, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
|
||||
await manager.insert(Product, {
|
||||
id: "test-product",
|
||||
title: "Test product",
|
||||
profile_id: defaultProfile.id,
|
||||
description: "test-product-description",
|
||||
collection_id: "test-collection",
|
||||
type: { id: "test-type", value: "test-type" },
|
||||
tags: [
|
||||
{ id: "tag1", value: "123" },
|
||||
{ tag: "tag2", value: "456" },
|
||||
],
|
||||
options: [{ id: "test-option", title: "Default value" }],
|
||||
});
|
||||
|
||||
await manager.insert(ProductVariant, {
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
title: "Test variant",
|
||||
product_id: "test-product",
|
||||
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
|
||||
options: [{ id: "test-variant-option", value: "Default variant" }],
|
||||
});
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
module.exports = {
|
||||
plugins: [],
|
||||
projectConfig: {
|
||||
// redis_url: REDIS_URL,
|
||||
database_url: "postgres://localhost/medusa-fixtures",
|
||||
database_type: "postgres",
|
||||
},
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "api",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.11-dev-1615929449260",
|
||||
"medusa-interfaces": "1.1.1-dev-1615929449260"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.0-dev-1615929449260"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
const fixtureWriter = require("./utils/write-fixture").default;
|
||||
const { dropDatabase } = require("pg-god");
|
||||
|
||||
beforeAll(() => {
|
||||
console.log(fixtureWriter);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
console.log(fixtureWriter);
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
await fixtureWriter.execute();
|
||||
});
|
||||
@@ -1,49 +0,0 @@
|
||||
import { FulfillmentService } from "medusa-interfaces";
|
||||
|
||||
class TestFulService extends FulfillmentService {
|
||||
static identifier = "test-ful";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
getFulfillmentOptions() {
|
||||
return [
|
||||
{
|
||||
id: "manual-fulfillment",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
validateFulfillmentData(data, cart) {
|
||||
return data;
|
||||
}
|
||||
|
||||
validateOption(data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
canCalculate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
calculatePrice() {
|
||||
throw Error("Manual Fulfillment service cannot calculatePrice");
|
||||
}
|
||||
|
||||
createOrder() {
|
||||
// No data is being sent anywhere
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
createFulfillment() {
|
||||
// No data is being sent anywhere
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
cancelFulfillment() {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}
|
||||
|
||||
export default TestFulService;
|
||||
@@ -1,19 +0,0 @@
|
||||
import { NotificationService } from "medusa-interfaces";
|
||||
|
||||
class TestNotiService extends NotificationService {
|
||||
static identifier = "test-not";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
async sendNotification() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async resendNotification() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
export default TestNotiService;
|
||||
@@ -1,67 +0,0 @@
|
||||
import { AbstractPaymentService } from "@medusajs/medusa"
|
||||
|
||||
class TestPayService extends AbstractPaymentService {
|
||||
static identifier = "test-pay"
|
||||
|
||||
constructor(_) {
|
||||
super(_)
|
||||
}
|
||||
|
||||
async getStatus(paymentData) {
|
||||
return "authorized"
|
||||
}
|
||||
|
||||
async retrieveSavedMethods(customer) {
|
||||
return Promise.resolve([])
|
||||
}
|
||||
|
||||
async createPayment() {
|
||||
return {}
|
||||
}
|
||||
|
||||
async createPaymentNew() {
|
||||
return {}
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async getPaymentData(sessionData) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(sessionData, context = {}) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async updatePaymentData(sessionData, update) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async updatePayment(sessionData, cart) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async updatePaymentNew(sessionData, paymentInput) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async deletePayment(payment) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async capturePayment(payment) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async refundPayment(payment, amountToRefund) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async cancelPayment(payment) {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export default TestPayService
|
||||
@@ -1,30 +0,0 @@
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
|
||||
class FixtureWriter {
|
||||
constructor() {
|
||||
const resolvedPath = path.resolve("./docs/api/fixtures.json");
|
||||
const existing = require(resolvedPath);
|
||||
|
||||
this.toWrite_ = existing.resources;
|
||||
this.resolvedPath_ = resolvedPath;
|
||||
}
|
||||
|
||||
addFixture(key, data) {
|
||||
this.toWrite_ = {
|
||||
...this.toWrite_,
|
||||
[key]: data,
|
||||
};
|
||||
}
|
||||
|
||||
async execute() {
|
||||
const toSet = {
|
||||
resources: this.toWrite_,
|
||||
};
|
||||
const s = JSON.stringify(toSet, null, 2);
|
||||
return await fs.writeFile(this.resolvedPath_, s);
|
||||
}
|
||||
}
|
||||
|
||||
const instance = new FixtureWriter();
|
||||
export default instance;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
const path = require("path");
|
||||
const { spawn } = require("child_process");
|
||||
|
||||
const { setPort } = require("./use-api");
|
||||
|
||||
module.exports = ({ cwd }) => {
|
||||
const serverPath = path.join(__dirname, "test-server.js");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const medusaProcess = spawn("node", [path.resolve(serverPath)], {
|
||||
cwd,
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_ENV: "development",
|
||||
JWT_SECRET: "test",
|
||||
COOKIE_SECRET: "test",
|
||||
},
|
||||
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
||||
});
|
||||
|
||||
medusaProcess.on("uncaughtException", (err) => {
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
medusaProcess.on("message", (port) => {
|
||||
setPort(port);
|
||||
resolve(medusaProcess);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
const path = require("path")
|
||||
const express = require("express")
|
||||
const getPort = require("get-port")
|
||||
const importFrom = require("import-from")
|
||||
|
||||
const initialize = async () => {
|
||||
const app = express()
|
||||
|
||||
const cwd = process.cwd()
|
||||
const loaders = importFrom(cwd, "@medusajs/medusa/dist/loaders").default
|
||||
|
||||
const { dbConnection } = await loaders({
|
||||
directory: path.resolve(process.cwd()),
|
||||
expressApp: app,
|
||||
})
|
||||
|
||||
const PORT = await getPort()
|
||||
|
||||
return {
|
||||
db: dbConnection,
|
||||
app,
|
||||
port: PORT,
|
||||
}
|
||||
}
|
||||
|
||||
const setup = async () => {
|
||||
const { app, port } = await initialize()
|
||||
|
||||
app.listen(port, (err) => {
|
||||
process.send(port)
|
||||
})
|
||||
}
|
||||
|
||||
setup()
|
||||
@@ -1,21 +0,0 @@
|
||||
const axios = require("axios").default;
|
||||
|
||||
const ServerTestUtil = {
|
||||
port_: null,
|
||||
client_: null,
|
||||
|
||||
setPort: function (port) {
|
||||
this.client_ = axios.create({ baseURL: `http://localhost:${port}` });
|
||||
},
|
||||
};
|
||||
|
||||
const instance = ServerTestUtil;
|
||||
|
||||
module.exports = {
|
||||
setPort: function (port) {
|
||||
instance.setPort(port);
|
||||
},
|
||||
useApi: function () {
|
||||
return instance.client_;
|
||||
},
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
const { dropDatabase, createDatabase } = require("pg-god")
|
||||
const { createConnection } = require("typeorm")
|
||||
|
||||
const path = require("path")
|
||||
|
||||
const DbTestUtil = {
|
||||
db_: null,
|
||||
|
||||
setDb: function (connection) {
|
||||
this.db_ = connection
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
return this.db_.synchronize(true)
|
||||
},
|
||||
|
||||
shutdown: async function () {
|
||||
await this.db_.close()
|
||||
return dropDatabase({ databaseName })
|
||||
},
|
||||
}
|
||||
|
||||
const instance = DbTestUtil
|
||||
|
||||
module.exports = {
|
||||
initDb: async function ({ cwd }) {
|
||||
const migrationDir = path.resolve(
|
||||
path.join(
|
||||
cwd,
|
||||
`node_modules`,
|
||||
`@medusajs`,
|
||||
`medusa`,
|
||||
`dist`,
|
||||
`migrations`
|
||||
)
|
||||
)
|
||||
|
||||
const databaseName = "medusa-fixtures"
|
||||
await createDatabase({ databaseName })
|
||||
|
||||
const connection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-fixtures",
|
||||
migrations: [`${migrationDir}/*.js`],
|
||||
})
|
||||
|
||||
await connection.runMigrations()
|
||||
await connection.close()
|
||||
|
||||
const modelsLoader = require(path.join(
|
||||
cwd,
|
||||
`node_modules`,
|
||||
`@medusajs`,
|
||||
`medusa`,
|
||||
`dist`,
|
||||
`loaders`,
|
||||
`models`
|
||||
)).default
|
||||
|
||||
const entities = modelsLoader({}, { register: false })
|
||||
const dbConnection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-fixtures",
|
||||
entities,
|
||||
})
|
||||
|
||||
instance.setDb(dbConnection)
|
||||
return dbConnection
|
||||
},
|
||||
useDb: function () {
|
||||
return instance
|
||||
},
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
const ServerTestUtil = {
|
||||
server_: null,
|
||||
app_: null,
|
||||
|
||||
setApp: function (app) {
|
||||
this.app_ = app;
|
||||
},
|
||||
|
||||
start: async function () {
|
||||
this.server_ = await new Promise((resolve, reject) => {
|
||||
const s = this.app_.listen(PORT, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
resolve(s);
|
||||
});
|
||||
},
|
||||
|
||||
kill: function () {
|
||||
return new Promise((resolve, _) => {
|
||||
if (this.server_) {
|
||||
this.server_.close(() => resolve());
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const instance = ServerTestUtil;
|
||||
|
||||
module.exports = {
|
||||
setApp: function (app) {
|
||||
instance.setApp(app);
|
||||
return instance;
|
||||
},
|
||||
|
||||
useServer: function () {
|
||||
return instance;
|
||||
},
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
const glob = require(`glob`);
|
||||
|
||||
const pkgs = glob
|
||||
.sync(`${__dirname}/*/`)
|
||||
.map((p) => p.replace(__dirname, `<rootDir>/docs-util`));
|
||||
|
||||
module.exports = {
|
||||
testEnvironment: `node`,
|
||||
rootDir: `../`,
|
||||
roots: pkgs,
|
||||
testPathIgnorePatterns: [
|
||||
`/examples/`,
|
||||
`/www/`,
|
||||
`/dist/`,
|
||||
`/node_modules/`,
|
||||
`__tests__/fixtures`,
|
||||
`__testfixtures__`,
|
||||
`.cache`,
|
||||
],
|
||||
transform: { "^.+\\.[jt]s$": `<rootDir>/jest-transformer.js` },
|
||||
setupFilesAfterEnv: ["<rootDir>/docs-util/setup.js"],
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
const fixtureWriter = require("./fixture-gen/utils/write-fixture").default;
|
||||
const { dropDatabase } = require("pg-god");
|
||||
|
||||
afterAll(async () => {
|
||||
await dropDatabase({ databaseName: "medusa-fixtures" });
|
||||
await fixtureWriter.execute();
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
templateKey: index-page
|
||||
pageTitle: Medusa docs
|
||||
introTtitle: Documentation
|
||||
introSubtitle: Explore and learn how to use Medusa.
|
||||
introDescriptionTitle: Quickstart
|
||||
introDescriptionSubtitle: Get up and running within 5 minutes, with helpful starters that lay the foundation for growth.
|
||||
---
|
||||
@@ -1,184 +0,0 @@
|
||||
# Cart Service
|
||||
In Medusa a cart is where a customer can add items that they intend to purchase
|
||||
later. The Cart service is responsible for making the operations necessary for
|
||||
handling items in the cart and completing a checkout.
|
||||
|
||||
## Creating carts
|
||||
|
||||
### When to create carts
|
||||
You can create a cart when the user enters the site or when they first add
|
||||
something to the cart.
|
||||
|
||||
If you decide to wait with cart creation until the
|
||||
customer adds something to the cart you have to make sure that the customer sees
|
||||
correct prices/products/etc. for the region they are shopping in. You will also
|
||||
have to ensure that you make a `POST /cart` call before you call `POST
|
||||
/cart/line-items`.
|
||||
|
||||
This can be circumvented by creating the cart as soon as the user enters your
|
||||
site. You will then be able to keep the region data in the cart, which will be
|
||||
ready for any `POST /cart/line-items`. This has the trade-off of creating many
|
||||
unnecessary carts, but is easier to implement.
|
||||
|
||||
## Shopping
|
||||
|
||||
### Adding to the cart
|
||||
The typical user journey is that a customer adds an item to her Cart this
|
||||
usually happens with `POST /cart/line-items`. The endpoint takes a `variant_id`
|
||||
and a `quantity`. The endpoint controller will then retrieve the variant and the
|
||||
product it is associated with, compile a valid `LineItem` and use the
|
||||
CartService function `addLineItem` to create the line item on the cart.
|
||||
|
||||
### Updating line items
|
||||
Updating line items happens with `POST /cart/line-items/[line-id]`. The endpoint
|
||||
takes `quantity` to update the line item's quantity. A quantity of 0 results in
|
||||
a removal of the line item. The endpoint controller uses `updateLineItem` to
|
||||
update the line item.
|
||||
|
||||
### Removing line items
|
||||
Deleting line items happens with `DELETE /cart/line-items/[line-id]`. Endpoint
|
||||
removes the line item with the given line id by calling `removeLineItem`.
|
||||
|
||||
:::note Custom add to cart
|
||||
|
||||
It is possible to make custom endpoints to add to cart. For example if you are
|
||||
creating a gift card plugin you may want to create a custom endpoint that
|
||||
accepts values like `amount` which can be set by the customer. As long as the
|
||||
controller compiles a valid `LineItem` it can safely call `addLineItem`
|
||||
|
||||
:::
|
||||
|
||||
## Checking out
|
||||
|
||||
### Initializing the checkout
|
||||
When the customer is ready to check out they will reach your checkout page. At
|
||||
this point you want to display which payment and shipping options are offered.
|
||||
`POST /cart/payment-sessions` and `POST /cart/fulfillment-sessions` will
|
||||
initialize payment sessions and shipping methods offered by fulfillment
|
||||
providers. The payment sessions will typically have to be updated if any further
|
||||
changes to the cart total happens (shipping fee, promo codes, user exits
|
||||
checkout and adds more items to cart and returns to checkout). Medusa will make
|
||||
sure to update any payment sessions that have already been initialized.
|
||||
|
||||
In cases where shipping rates can vary based on order size, shipping address
|
||||
(with higher granularity than region) makes sense to call `POST
|
||||
/cart/fulfillment-providers` multiple times, e.g. if the customer updates their
|
||||
shipping address and new shipping rates have to be calculated. On each call the
|
||||
endpoint will make sure to only return relevant shipping methods.
|
||||
|
||||
Note that `POST /cart/payment-providers` should not be used to fetch available
|
||||
payment providers, only to initialize payment sessions. If you want to display
|
||||
the available payment providers to the customer you can find an array of these
|
||||
in `region.payment_providers`.
|
||||
|
||||
### Getting customer data
|
||||
To complete a purchase the customer has to fill in her details. The endpoints to
|
||||
do this are `POST /cart/email`, `POST /cart/shipping-address` and `POST /cart/
|
||||
billing-address`. The endpoint controllers use the corresponding Cart service
|
||||
methods (`updateEmail`, `updateShippingAddress`, `updateBillingAddress`) to
|
||||
store the customer information in the cart.
|
||||
|
||||
### Handling payments and completing orders
|
||||
Authorization of payments happen with the payment provider. As such the typical
|
||||
payment flow will be:
|
||||
|
||||
1. the customer enters payment details
|
||||
2. details are sent to the payment provider
|
||||
3. the payment provider authorizes the payment
|
||||
4. the payment method is store in the cart
|
||||
5. the order is processed.
|
||||
|
||||
Steps 4. and 5. are handled with one API call in Medusa. Once the payment is
|
||||
authorized you call `POST /order`. The endpoint takes `cart_id` and
|
||||
`payment_provider_id` as data. The controller will call the Cart service
|
||||
function `setPaymentMethod` which will fetch the cart, search the
|
||||
`payment_sessions` array for the payment associated with `payment_provider` and
|
||||
check that the payment session is authorized. When the authorization is verified
|
||||
the payment method is set and the controller can safely call the Order service
|
||||
function `create`.
|
||||
|
||||
|
||||
### How do payment sessions work?
|
||||
|
||||
When the customer first enters the checkout page you should initialize payment
|
||||
sessions for each of the possible payment providers. This is done with a single
|
||||
call to `POST /cart/payment-sessions`. Calls to `POST /cart/payment-sessions`
|
||||
will either create payment sessions for each payment provider or if the payment
|
||||
sessions have already been initialized ensure that the sessions are up to date (
|
||||
i.e. that the cart amount corresponds to the payment sessions' amounts). When
|
||||
the customer reaches the payment part of the checkout (or alternatively when she
|
||||
decides to use one of the payment providers as a checkout provider) the payment
|
||||
method will be saved once authorized.
|
||||
|
||||
### How do fulfillment sessions work?
|
||||
|
||||
When the customer first enters the checkout page, fulfillment sessions should be
|
||||
initialized. The fulfillment session is responsible for fetching shipping
|
||||
options with a fulfillment provider. E.g. your store has an integration with
|
||||
your 3PL as a fulfillment provider. The 3PL has 4 shipping options: standard,
|
||||
express and fragile shipping as well as a parcel shop service where orders are
|
||||
delivered to a local store.
|
||||
|
||||
The store operator will have set up which shipping options are available in the
|
||||
customer's region. I.e. the store operator may have created a shipping option
|
||||
called Free Shipping, which uses the "Standard Shipping" method from the 3PL
|
||||
integration, and which is free when the order value is above 100 USD. The store
|
||||
operator may have also created an Express Shipping option which uses the
|
||||
"Express Shipping" method from the 3PL integration and which costs 20 USD.
|
||||
The store operator has also created a Fragile Shipping option which uses the
|
||||
"Fragile Shipping" method from the 3PL integration and which has variable
|
||||
pricing depending on the size of the shipment. The variable pricing is
|
||||
calculated by the integration depending on cart. Finally, the store operator has
|
||||
defined a parcel shop option, which uses the 3PL's parcel shop shipping method.
|
||||
The customer needs to provide the ID of the local store that she wants her order
|
||||
delivered to and the shipping method therefore takes some additional input to be
|
||||
a valid shipping method for an order.
|
||||
|
||||
When the customer enters the checkout page the `POST /cart/shipping-options`
|
||||
call will fetch each of the shipping options that the store operator has set up.
|
||||
Extending the above example, an array of shipping options would be stored in the
|
||||
cart in the format:
|
||||
|
||||
```
|
||||
[
|
||||
{
|
||||
_id: [some-id],
|
||||
provider_id: "3pl_integration",
|
||||
name: "Free Shipping",
|
||||
price: 0,
|
||||
data: {
|
||||
// This will contain data specific to the shipping method, i.e. the
|
||||
// id that the 3PL needs in order to process the order with this shipping
|
||||
// method
|
||||
}
|
||||
},
|
||||
{
|
||||
_id: [some-id],
|
||||
provider_id: "3pl_integration",
|
||||
name: "Express Shipping",
|
||||
price: 20,
|
||||
data: {
|
||||
// This will contain data specific to the shipping method, i.e. the
|
||||
// id that the 3PL needs in order to process the order with this shipping
|
||||
// method
|
||||
}
|
||||
},
|
||||
{
|
||||
_id: [some-id],
|
||||
provider_id: "3pl_integration",
|
||||
name: "Fragile Shipping",
|
||||
price: 120, // Calculated from the cart
|
||||
data: {
|
||||
// This will contain data specific to the shipping method, i.e. the
|
||||
// id that the 3PL needs in order to process the order with this shipping
|
||||
// method
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
If the customer changes her cart, all shipping options will be recalculated. For
|
||||
example, if the customer removes something from the cart so that they no longer
|
||||
qualify for free shipping, the free shipping method will be removed at the same
|
||||
time the fragile shipping method's price will be updated.
|
||||
@@ -1,31 +0,0 @@
|
||||
## Returns
|
||||
|
||||
Returns refer to the situation when a merchant takes back previously purchased items from a customer. A return will usually result in a refund to the customer, with an amount corresponding to the amount received from the customer at the time of purchase.
|
||||
|
||||
A usual return flow follows the steps below:
|
||||
|
||||
1. The customer requests a return - noting the items that they will be sending back.
|
||||
2. The merchant provides the customer with a return label, that will be used on the package that is being sent back.
|
||||
3. The merchant receives the package at their warehouse, and registers the return as being received.
|
||||
4. The merchant refunds the money to the customer, taking any potential return shipping requests into account.
|
||||
|
||||
A different flow that is less common follows the steps:
|
||||
|
||||
1. The customer arranges a shipment themselves.
|
||||
2. The merchant receives the package at their warehouse, and registers the return as being received.
|
||||
3. The merchant refunds the money to the customer, taking any potential return shipping requests into account.
|
||||
|
||||
In Medusa Admin return shipping options are created in the same way that outgoing shipping options are created. Each return shipping option is associated with a region giving you the flexibility to price returns differently depending on the region the order has been placed in. Returns are not required to have shipping methods as it may be the case that return is arranged independently of a fulfillment provider.
|
||||
|
||||
To create a return in Medusa Admin the store operator finds the original order and clicks "Create Return", the store operator then selects the items to be returned along with a shipping option, once the return is created the fulfillment provider takes care of providing the necessary documentation for the return; this can also be viewed in Medusa Admin.
|
||||
|
||||
## Swaps
|
||||
|
||||
A swap can be used in cases where a customer wishes to exchange previously purchased items for different items. Usually this occurs if the customer wants to change the size or color of an item. In Medusa a swap can be initiated to handle the administrative tasks around swaps i.e. requesting a return, taking a payment from the customer for any shipping expenses and fulfilling the new items.
|
||||
|
||||
When a swap is created in Medusa Admin a return request will be initiated immediately generating return labels with the chosen fulfillment provider, furthermore a cart will be created and a payment link generated which can be sent to the customer to authorize a payment. When the return is received the swap can be marked as received and usually this will be where the new goods are to be sent out. The new goods are sent with the shipping method chosen by the customer in the payment process.
|
||||
|
||||
Limitations:
|
||||
- At the moment only swaps that require a payment are supported i.e. swaps that would result in a refund to the customer are not possible.
|
||||
- The customer must have paid for their swap before the items can be returned.
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# ShippingOptionService
|
||||
|
||||
In Medusa, ShippingOptions represent ways that the customer can have their order shipped. Shipping options are defined by the store operator and are linked to a fulfillment provider. When the customer places their order the fulfillment provider plugin will be notified.
|
||||
|
||||
Shipping Options can have either flat rate prices or calculated prices. As the names suggest a flat rate price is a fixed amount, e.g. for Free Shipping, while calculated rates are prices that are calculated by the fulfillment provider.
|
||||
|
||||
## Creating ShippingOptions
|
||||
|
||||
Shipping options are created with POST calls to `/admin/shipping-options`. You can define requirements that the cart should meet in order to allow the shipping option to be applied to it. Furthermore, you should define what Region the shipping option is available in.
|
||||
|
||||
## Using Shipping Options
|
||||
|
||||
Your fulfillment provider may need additional data in order to validate the shipping option for use. For example, the store operator could make a shipping option called "ShopPickup" which is fulfilled by your warehouse and shipped with CarrierX.
|
||||
|
||||
CarrierX sends the order to the customer's local store where the customer can pick up their order. In this case fulfillment provider needs some additional data about which store CarrierX is shipping to. The additional data should be provided in the data field when calling POST `/store/carts/:id/shipping-method`.
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# ShippingProfileService
|
||||
|
||||
In Medusa, a Shipping Profile represents a group of products and shipping options that can fulfill said products. For example, a store may have to product types "Shirts" and "Shorts" which are produced in Italy and UK respectively. In this case the store operator would create two shipping profiles, one for Shirts and one for Shorts, and add the products correspondingly. The store operator can now decide which shipping options can fulfill the products by adding shipping options to each of the profiles.
|
||||
|
||||
Products and Shipping Options can only belong to one shipping profile at a time.
|
||||
|
||||
|
||||
## Using Shipping Profiles
|
||||
The shipping profiles are used to fetch the correct shipping options for a cart. When GET `/store/shipping-options` is called the ShippingProfileService is asked to find all shipping options that can fulfill the cart's products.
|
||||
@@ -65,7 +65,6 @@
|
||||
"test:integration": "NODE_ENV=test jest --runInBand --bail --config=integration-tests/jest.config.js",
|
||||
"test:integration:api": "NODE_ENV=test jest --detectOpenHandles --forceExit --runInBand --bail --config=integration-tests/jest.config.js --projects=integration-tests/api",
|
||||
"test:integration:plugins": "NODE_ENV=test jest --runInBand --bail --config=integration-tests/jest.config.js --projects=integration-tests/plugins",
|
||||
"test:fixtures": "NODE_ENV=test jest --config=docs-util/jest.config.js --runInBand --bail",
|
||||
"openapi:generate": "node ./scripts/build-openapi.js",
|
||||
"generate:services": "typedoc --options typedoc.services.js",
|
||||
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
||||
|
||||
Reference in New Issue
Block a user