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();
|
||||
});
|
||||
Reference in New Issue
Block a user