Merge branch 'develop' into feat/disabling-of-notification
This commit is contained in:
@@ -104,6 +104,82 @@ describe("/admin/discounts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on discount codes", () => {
|
||||
const manager = dbConnection.manager;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Test discount rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
});
|
||||
await manager.insert(Discount, {
|
||||
id: "test-discount",
|
||||
code: "TESTING",
|
||||
rule_id: "test-discount-rule",
|
||||
});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("successfully creates discount with soft-deleted discount code", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the discount
|
||||
await api
|
||||
.delete("/admin/discounts/test-discount", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
// Lets try to create a discount with same code as deleted one
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "TESTING",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 10,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /admin/discounts/:discount_id/dynamic-codes", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
@@ -224,4 +224,208 @@ describe("/admin/products", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
|
||||
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 "image"`);
|
||||
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("successfully deletes a product", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "test-product",
|
||||
deleted: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("successfully creates product with soft-deleted product handle", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the product
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-product");
|
||||
|
||||
// Lets try to create a product with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Test product",
|
||||
handle: "test-product",
|
||||
description: "test-product-description",
|
||||
type: { value: "test-type" },
|
||||
images: ["test-image.png", "test-image-2.png"],
|
||||
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 res = await api.post("/admin/products", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.product.handle).toEqual("test-product");
|
||||
});
|
||||
|
||||
it("successfully deletes product collection", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the product collection
|
||||
const response = await api
|
||||
.delete("/admin/collections/test-collection", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-collection");
|
||||
});
|
||||
|
||||
it("successfully creates soft-deleted product collection", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/collections/test-collection", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-collection");
|
||||
|
||||
// Lets try to create a product collection with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Another test collection",
|
||||
handle: "test-collection",
|
||||
};
|
||||
|
||||
const res = await api.post("/admin/collections", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.collection.handle).toEqual("test-collection");
|
||||
});
|
||||
|
||||
it("successfully creates soft-deleted product variant", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product/variants/test-variant", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.variant_id).toEqual("test-variant");
|
||||
|
||||
// Lets try to create a product collection with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Second variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const res = await api.post(
|
||||
"/admin/products/test-product/variants",
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.product.variants).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Second variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
134
integration-tests/api/__tests__/store/customer.js
Normal file
134
integration-tests/api/__tests__/store/customer.js
Normal file
@@ -0,0 +1,134 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Customer } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
|
||||
const customerSeeder = require("../../helpers/customer-seeder");
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/store/customers", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
const doAfterEach = async (manager) => {
|
||||
await manager.query(`DELETE FROM "address"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
};
|
||||
|
||||
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-integration" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /store/customers", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.insert(Customer, {
|
||||
id: "test_customer",
|
||||
first_name: "John",
|
||||
last_name: "Deere",
|
||||
email: "john@deere.com",
|
||||
has_account: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("creates a customer", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.post("/store/customers", {
|
||||
first_name: "James",
|
||||
last_name: "Bond",
|
||||
email: "james@bond.com",
|
||||
password: "test",
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.customer).not.toHaveProperty("password_hash");
|
||||
});
|
||||
|
||||
it("responds 409 on duplicate", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post("/store/customers", {
|
||||
first_name: "James",
|
||||
last_name: "Bond",
|
||||
email: "john@deere.com",
|
||||
password: "test",
|
||||
})
|
||||
.catch((err) => err.response);
|
||||
|
||||
expect(response.status).toEqual(409);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /store/customers/:id", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.insert(Customer, {
|
||||
id: "test_customer",
|
||||
first_name: "John",
|
||||
last_name: "Deere",
|
||||
email: "john@deere.com",
|
||||
password_hash:
|
||||
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
|
||||
has_account: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("updates a customer", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const authResponse = await api.post("/store/auth", {
|
||||
email: "john@deere.com",
|
||||
password: "test",
|
||||
});
|
||||
|
||||
const customerId = authResponse.data.customer.id;
|
||||
const [authCookie] = authResponse.headers["set-cookie"][0].split(";");
|
||||
|
||||
const response = await api.post(
|
||||
`/store/customers/${customerId}`,
|
||||
{
|
||||
password: "test",
|
||||
metadata: { key: "value" },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.customer).not.toHaveProperty("password_hash");
|
||||
expect(response.data.customer).toEqual(
|
||||
expect.objectContaining({
|
||||
metadata: { key: "value" },
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,7 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
const coll = manager.create(ProductCollection, {
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
});
|
||||
|
||||
@@ -54,6 +55,7 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
const p = manager.create(Product, {
|
||||
id: "test-product",
|
||||
handle: "test-product",
|
||||
title: "Test product",
|
||||
profile_id: defaultProfile.id,
|
||||
description: "test-product-description",
|
||||
@@ -74,6 +76,10 @@ module.exports = async (connection, data = {}) => {
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
title: "Test variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
product_id: "test-product",
|
||||
prices: [],
|
||||
options: [{ id: "test-variant-option", value: "Default variant" }],
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.23-dev-1623081876060",
|
||||
"medusa-interfaces": "1.1.10-dev-1623081876060",
|
||||
"@medusajs/medusa": "1.1.28-dev-1624556551881",
|
||||
"medusa-interfaces": "1.1.16-dev-1624556551881",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.3-dev-1623168481467",
|
||||
"babel-preset-medusa-package": "1.1.9-dev-1624556551881",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,10 +1215,10 @@
|
||||
"@types/yargs" "^15.0.0"
|
||||
chalk "^4.0.0"
|
||||
|
||||
"@medusajs/medusa@1.1.23-dev-1623081876060":
|
||||
version "1.1.23"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.23.tgz#420eae69b20bc3b5a4c8f81825ba46252a1f1c92"
|
||||
integrity sha512-1n9unNwt1jQV0SGd7053BIIb5P/PzPhX3fFgpwT4OzVbMOewnF6CLNMDaiQ1gI53JbkFY1rbjUPsRZk+9jVrYg==
|
||||
"@medusajs/medusa@1.1.28-dev-1624556551881":
|
||||
version "1.1.28-dev-1624556551881"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.28-dev-1624556551881.tgz#263dac3aae36b656899dde61910e170e20647a1d"
|
||||
integrity sha512-v6Rry8J7/z99dhn7uIWSt/IeFQ3o+O3zmdN1aYejLz2q0NWXdT9eSlicEEoznHFd/4EEZa1BYYqR4U1FqmGgUw==
|
||||
dependencies:
|
||||
"@hapi/joi" "^16.1.8"
|
||||
"@types/lodash" "^4.14.168"
|
||||
@@ -1239,8 +1239,8 @@
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
jsonwebtoken "^8.5.1"
|
||||
medusa-core-utils "^1.1.9"
|
||||
medusa-test-utils "^1.1.12"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
medusa-test-utils "1.1.18-dev-1624556551881"
|
||||
morgan "^1.9.1"
|
||||
multer "^1.4.2"
|
||||
passport "^0.4.0"
|
||||
@@ -1696,10 +1696,10 @@ babel-preset-jest@^26.6.2:
|
||||
babel-plugin-jest-hoist "^26.6.2"
|
||||
babel-preset-current-node-syntax "^1.0.0"
|
||||
|
||||
babel-preset-medusa-package@1.1.3-dev-1623168481467:
|
||||
version "1.1.3-dev-1623168481467"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.3-dev-1623168481467.tgz#ae9167644267c52c1016c4695294d81059dfc2ff"
|
||||
integrity sha512-QombHh4IHvYll+DwUgeL93+uNCcFCSW6/rv/rrmcS4MMB+TeZ5iQrK+i1Gf/ns10v1WH2q0+VdExu9GDrdwU3Q==
|
||||
babel-preset-medusa-package@1.1.9-dev-1624556551881:
|
||||
version "1.1.9-dev-1624556551881"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.9-dev-1624556551881.tgz#02631e1bc7ae0c6b28b6172d44f144dcc9ec9e0f"
|
||||
integrity sha512-gbenDSqRQm0IoI4vqgwvL9DMsR/b3UgGu2ZzpTXZeM070wH4LsBeckNpXf0k5douOUIpqvhk5xhyIYBprZz5LQ==
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-class-properties" "^7.12.1"
|
||||
"@babel/plugin-proposal-decorators" "^7.12.1"
|
||||
@@ -4150,28 +4150,28 @@ media-typer@0.3.0:
|
||||
resolved "http://localhost:4873/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
||||
|
||||
medusa-core-utils@^1.1.9:
|
||||
version "1.1.9"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.9.tgz#7b93c72d9c318ff4ab971381401158eee7d3edd9"
|
||||
integrity sha512-XBxwpCQT82gi/S92Bc0qfCSYyD5Hj+zstUbyOCKGp7nhwFPvYwJ0hp6NPKDSwHZ1uPEmb4rdHcW2qyf1bM4L1Q==
|
||||
medusa-core-utils@1.1.15-dev-1624556551881:
|
||||
version "1.1.15-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.15-dev-1624556551881.tgz#3cd5ac7a40ecd870d6cf22873ddbcfe362b84215"
|
||||
integrity sha512-KicW2VFP0nKNozJ/XvBQ7pGcML50cnj0IWThGBiak+S9+6+DBHPKmUVOWMwO4ocQgXUY9VV+ZjUzXYxKUrM0fA==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-interfaces@1.1.10-dev-1623081876060:
|
||||
version "1.1.10"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.10.tgz#e81b885e11d6c2f05db8d2971edf30b8f8e7ddaa"
|
||||
integrity sha512-FJSpX3CE5jx2mYqRARFSp5C6x5Hq+MEZ6p2UikuWnm40qjGsbHNl4naZFdBS1u/vSnXq+607oHuZnCNnpRDrPQ==
|
||||
medusa-interfaces@1.1.16-dev-1624556551881:
|
||||
version "1.1.16-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.16-dev-1624556551881.tgz#4644df88d49dac014a8c1c7170efa5fff45df15e"
|
||||
integrity sha512-oWLD8qDGhByty3mIWnv4cIgdJ0sWDDy1/Yz4rL5fNhENtRhwzH0vvw5rEBvpFAFF5TZuwMap+Co61ldRyN6xBA==
|
||||
dependencies:
|
||||
medusa-core-utils "^1.1.9"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
|
||||
medusa-test-utils@^1.1.12:
|
||||
version "1.1.12"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.12.tgz#1a731a3bd0c7266105b75d88dce7c09657432002"
|
||||
integrity sha512-h/xpN0Mq1DRS7pDzEDjHfkZtpw1iLDKnytwBd12Lzs9RsWpQOJArfqSocAqdDrIO7GbxykhkFDCdl3Yi/q59gw==
|
||||
medusa-test-utils@1.1.18-dev-1624556551881:
|
||||
version "1.1.18-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.18-dev-1624556551881.tgz#fb2b2cd25755251c37545d1cfe725eecb96288af"
|
||||
integrity sha512-lJyEvvSxM5mv+mxePSqt3Fcj/g+mkwSsN+NnURhiEG1vVi9s6t/kZf55mSu+IRqXQhs/FQMHzkgCHzUgmAjMqg==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "^1.1.9"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
export const MedusaErrorTypes = {
|
||||
/** Errors stemming from the database */
|
||||
DB_ERROR: "database_error",
|
||||
DUPLICATE_ERROR: "duplicate_error",
|
||||
INVALID_ARGUMENT: "invalid_argument",
|
||||
INVALID_DATA: "invalid_data",
|
||||
NOT_FOUND: "not_found",
|
||||
NOT_ALLOWED: "not_allowed"
|
||||
NOT_ALLOWED: "not_allowed",
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3740,12 +3740,7 @@ lodash.sortby@^4.7.0:
|
||||
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
|
||||
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
|
||||
|
||||
lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15:
|
||||
version "4.17.20"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
|
||||
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
|
||||
|
||||
lodash@^4.17.19:
|
||||
lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
|
||||
version "4.17.21"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||
|
||||
@@ -9,6 +9,9 @@ export default () => {
|
||||
|
||||
let statusCode = 500
|
||||
switch (err.name) {
|
||||
case MedusaError.Types.DUPLICATE_ERROR:
|
||||
statusCode = 409
|
||||
break
|
||||
case MedusaError.Types.NOT_ALLOWED:
|
||||
case MedusaError.Types.INVALID_DATA:
|
||||
statusCode = 400
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { CustomerServiceMock } from "../../../../../services/__mocks__/customer"
|
||||
import { defaultFields, defaultRelations } from "../"
|
||||
|
||||
describe("POST /store/customers", () => {
|
||||
describe("successfully creates a customer", () => {
|
||||
@@ -34,7 +35,7 @@ describe("POST /store/customers", () => {
|
||||
expect(CustomerServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
||||
expect(CustomerServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
IdMap.getId("lebron"),
|
||||
{ relations: ["shipping_addresses"] }
|
||||
{ relations: defaultRelations, select: defaultFields }
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { defaultFields, defaultRelations } from "../"
|
||||
import { CustomerServiceMock } from "../../../../../services/__mocks__/customer"
|
||||
|
||||
describe("POST /store/customers/:id", () => {
|
||||
@@ -42,7 +43,7 @@ describe("POST /store/customers/:id", () => {
|
||||
expect(CustomerServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
||||
expect(CustomerServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
IdMap.getId("lebron"),
|
||||
{ relations: ["shipping_addresses"] }
|
||||
{ relations: defaultRelations, select: defaultFields }
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [post] /customers/{id}/addresses
|
||||
@@ -45,7 +46,8 @@ export default async (req, res) => {
|
||||
|
||||
let customer = await customerService.addAddress(id, value.address)
|
||||
customer = await customerService.retrieve(id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
|
||||
res.status(200).json({ customer })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import jwt from "jsonwebtoken"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import config from "../../../../config"
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [post] /customers
|
||||
@@ -40,6 +41,7 @@ export default async (req, res) => {
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const customerService = req.scope.resolve("customerService")
|
||||
let customer = await customerService.create(value)
|
||||
@@ -50,7 +52,8 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
customer = await customerService.retrieve(customer.id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
|
||||
res.status(200).json({ customer })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [delete] /customers/{id}/addresses/{address_id}
|
||||
* operationId: DeleteCustomersCustomerAddressesAddress
|
||||
@@ -25,7 +27,8 @@ export default async (req, res) => {
|
||||
try {
|
||||
await customerService.removeAddress(id, address_id)
|
||||
customer = await customerService.retrieve(id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
|
||||
res.json({ customer })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [get] /customers/{id}
|
||||
* operationId: GetCustomersCustomer
|
||||
@@ -22,7 +24,8 @@ export default async (req, res) => {
|
||||
try {
|
||||
const customerService = req.scope.resolve("customerService")
|
||||
const customer = await customerService.retrieve(id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
res.json({ customer })
|
||||
} catch (err) {
|
||||
|
||||
@@ -57,3 +57,39 @@ export default (app, container) => {
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
export const defaultRelations = ["shipping_addresses"]
|
||||
|
||||
export const defaultFields = [
|
||||
"id",
|
||||
"email",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"billing_address_id",
|
||||
"phone",
|
||||
"has_account",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"metadata",
|
||||
]
|
||||
|
||||
export const allowedRelations = [
|
||||
"shipping_addresses",
|
||||
"billing_address",
|
||||
"orders",
|
||||
]
|
||||
|
||||
export const allowedFields = [
|
||||
"id",
|
||||
"email",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"billing_address_id",
|
||||
"phone",
|
||||
"has_account",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"metadata",
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [post] /customers/{id}/addresses/{address_id}
|
||||
@@ -50,7 +51,8 @@ export default async (req, res) => {
|
||||
)
|
||||
|
||||
customer = await customerService.retrieve(id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
|
||||
res.json({ customer })
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { defaultRelations, defaultFields } from "./"
|
||||
|
||||
/**
|
||||
* @oas [post] /customers/{id}
|
||||
@@ -24,6 +25,9 @@ import { Validator, MedusaError } from "medusa-core-utils"
|
||||
* phone:
|
||||
* description: "The Customer's phone number."
|
||||
* type: string
|
||||
* metadata:
|
||||
* description: "Metadata about the customer."
|
||||
* type: object
|
||||
* tags:
|
||||
* - Customer
|
||||
* responses:
|
||||
@@ -44,6 +48,7 @@ export default async (req, res) => {
|
||||
last_name: Validator.string().optional(),
|
||||
password: Validator.string().optional(),
|
||||
phone: Validator.string().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -56,7 +61,8 @@ export default async (req, res) => {
|
||||
let customer = await customerService.update(id, value)
|
||||
|
||||
customer = await customerService.retrieve(customer.id, {
|
||||
relations: ["shipping_addresses"],
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
})
|
||||
|
||||
res.status(200).json({ customer })
|
||||
|
||||
@@ -4,28 +4,16 @@ export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
|
||||
name = "gcRemoveUniqueOrder1624287602631"
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
|
||||
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`)
|
||||
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
|
||||
export class softDeletingUniqueConstraints1624610325746 implements MigrationInterface {
|
||||
name = 'softDeletingUniqueConstraints1624610325746'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_6910923cb678fd6e99011a21cc"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_db7355f7bd36c547c8a4f539e5"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_087926f6fec32903be3c8eedfa"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_f4dc2c0888b66d547c175f090e"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_9db95c4b71f632fc93ecbc3d8b"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_7124082c8846a06a857cca386c"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_a0a3f124dc5b167622217fee02"`);
|
||||
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e08af711f3493df1e921c4c9ef" ON "product_collection" ("handle") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_77c4073c30ea7793f484750529" ON "product" ("handle") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ae3e22c67d7c7a969a363533c0" ON "discount" ("code") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0683952543d7d3f4fffc427034" ON "product_variant" ("sku") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_410649600ce31c10c4b667ca10" ON "product_variant" ("barcode") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_5248fda27b9f16ef818604bb6f" ON "product_variant" ("ean") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_832f86daf8103491d634a967da" ON "product_variant" ("upc") WHERE deleted_at IS NOT NULL`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_ae3e22c67d7c7a969a363533c0"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_77c4073c30ea7793f484750529"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_e08af711f3493df1e921c4c9ef"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_832f86daf8103491d634a967da"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_5248fda27b9f16ef818604bb6f"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_410649600ce31c10c4b667ca10"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_0683952543d7d3f4fffc427034"`);
|
||||
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_087926f6fec32903be3c8eedfa" ON "discount" ("code") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_db7355f7bd36c547c8a4f539e5" ON "product" ("handle") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6910923cb678fd6e99011a21cc" ON "product_collection" ("handle") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a0a3f124dc5b167622217fee02" ON "product_variant" ("upc") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_7124082c8846a06a857cca386c" ON "product_variant" ("ean") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_9db95c4b71f632fc93ecbc3d8b" ON "product_variant" ("barcode") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f4dc2c0888b66d547c175f090e" ON "product_variant" ("sku") `);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ export class Discount {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column()
|
||||
code: string
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export class ProductCollection {
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column({ nullable: true })
|
||||
handle: string
|
||||
|
||||
|
||||
@@ -50,19 +50,19 @@ export class ProductVariant {
|
||||
prices: MoneyAmount[]
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
sku: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
barcode: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
ean: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
upc: string
|
||||
|
||||
@Column({ type: "int" })
|
||||
|
||||
@@ -39,7 +39,7 @@ export class Product {
|
||||
@Column({ nullable: true })
|
||||
description: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column({ nullable: true })
|
||||
handle: string
|
||||
|
||||
|
||||
@@ -135,8 +135,8 @@ describe("ProductCollectionService", () => {
|
||||
it("successfully removes a product collection", async () => {
|
||||
await productCollectionService.delete(IdMap.getId("bathrobe"))
|
||||
|
||||
expect(productCollectionRepository.remove).toHaveBeenCalledTimes(1)
|
||||
expect(productCollectionRepository.remove).toHaveBeenCalledWith({
|
||||
expect(productCollectionRepository.softRemove).toHaveBeenCalledTimes(1)
|
||||
expect(productCollectionRepository.softRemove).toHaveBeenCalledWith({
|
||||
id: IdMap.getId("bathrobe"),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -318,6 +318,13 @@ class CustomerService extends BaseService {
|
||||
|
||||
const existing = await this.retrieveByEmail(email).catch(err => undefined)
|
||||
|
||||
if (existing && existing.has_account) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.DUPLICATE_ERROR,
|
||||
"A customer with the given email already has an account. Log in instead"
|
||||
)
|
||||
}
|
||||
|
||||
if (existing && password && !existing.has_account) {
|
||||
const hashedPassword = await this.hashPassword_(password)
|
||||
customer.password_hash = hashedPassword
|
||||
|
||||
@@ -129,7 +129,7 @@ class ProductCollectionService extends BaseService {
|
||||
|
||||
if (!collection) return Promise.resolve()
|
||||
|
||||
await productCollectionRepo.remove(collection)
|
||||
await productCollectionRepo.softRemove(collection)
|
||||
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user