release: next (#315)

Co-authored-by: Sebastian Mateos Nicolajsen <sebastian.m.nicolajsen@gmail.com>
Co-authored-by: Abraham Ugbeshe <abrahamugbeshe@gmail.com>
Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
Sebastian Rindom
2021-07-15 09:21:03 +02:00
parent 44d31b4d83
commit 2585e958de
144 changed files with 2554 additions and 240 deletions
@@ -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",
}),
])
);
});
});
});
@@ -0,0 +1,230 @@
const { dropDatabase } = require("pg-god");
const path = require("path");
const { Address, 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 "customer"`);
await manager.query(`DELETE FROM "address"`);
};
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(Address, {
id: "addr_test",
first_name: "String",
last_name: "Stringson",
address_1: "String st",
city: "Stringville",
postal_code: "1236",
province: "ca",
country_code: "us",
});
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" },
})
);
});
it("updates customer billing address", 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}`,
{
billing_address: {
first_name: "test",
last_name: "testson",
address_1: "Test st",
city: "Testion",
postal_code: "1235",
province: "ca",
country_code: "us",
},
},
{
headers: {
Cookie: authCookie,
},
}
);
expect(response.status).toEqual(200);
expect(response.data.customer).not.toHaveProperty("password_hash");
expect(response.data.customer.billing_address).toEqual(
expect.objectContaining({
first_name: "test",
last_name: "testson",
address_1: "Test st",
city: "Testion",
postal_code: "1235",
province: "ca",
country_code: "us",
})
);
});
it("updates customer billing address with string", 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}`,
{
billing_address: "addr_test",
},
{
headers: {
Cookie: authCookie,
},
}
);
expect(response.status).toEqual(200);
expect(response.data.customer).not.toHaveProperty("password_hash");
expect(response.data.customer.billing_address).toEqual(
expect.objectContaining({
first_name: "String",
last_name: "Stringson",
address_1: "String st",
city: "Stringville",
postal_code: "1236",
province: "ca",
country_code: "us",
})
);
});
});
});
@@ -18,6 +18,7 @@ module.exports = async (connection, data = {}) => {
const coll = manager.create(ProductCollection, {
id: "test-collection",
handle: "test-collection",
title: "Test collection",
});
@@ -53,6 +54,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",
@@ -73,6 +75,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: [{ id: "test-price", currency_code: "usd", amount: 100 }],
options: [{ id: "test-variant-option", value: "Default variant" }],
+3 -3
View File
@@ -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.29-dev-1626162503472",
"medusa-interfaces": "1.1.17-dev-1626162503472",
"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.10-dev-1626162503472",
"jest": "^26.6.3"
}
}
+24 -24
View File
@@ -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.29-dev-1626162503472":
version "1.1.29-dev-1626162503472"
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.29-dev-1626162503472.tgz#973ec19d02a66864c8cc11ac3e045cda2a82215d"
integrity sha512-8JDjTzOh056panREJIpN6uh2nwhauKqJHeGopG0Kdaw7sxOS3GJMBIfkwmUeNjju+cnpzj0nKlnJ56UgNMZSvA==
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.16-dev-1626162503472"
medusa-test-utils "1.1.19-dev-1626162503472"
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.10-dev-1626162503472:
version "1.1.10-dev-1626162503472"
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.10-dev-1626162503472.tgz#65bba4e47361d9298b894fe9c08122fd60e0fd54"
integrity sha512-kQIZbFKnCnngCxxnPI3Ri+TC+6sadQOPgPGSMxd2X3yLm/W9RU+BLxRCLPEQcvvt6jeUA8dil8n0NUSl51cQnQ==
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.16-dev-1626162503472:
version "1.1.16-dev-1626162503472"
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.16-dev-1626162503472.tgz#f72029605508928f689df3e35969db8c90be9cfd"
integrity sha512-AsI8UNF2VaJIUppJHjipsQnO6o7O/HNjIx5yPamriZRHatevZpWnRAD3aCejz25gaPvUQHWZ66b+UunPz1YKmQ==
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.17-dev-1626162503472:
version "1.1.17-dev-1626162503472"
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.17-dev-1626162503472.tgz#5cb72816c241a0074fbdbc64c2dfb0bedc073c03"
integrity sha512-aQcK39oMGBvb27aIHW3ko5sRdP2GRUAllXzrsTy3aQbUYzZxqnq3FHRlTjmBUWa9zbzwvfu3JLwdCEgZTfgr6Q==
dependencies:
medusa-core-utils "^1.1.9"
medusa-core-utils "1.1.16-dev-1626162503472"
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.19-dev-1626162503472:
version "1.1.19-dev-1626162503472"
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.19-dev-1626162503472.tgz#0a112fa9d5df2a2ce913312bb0527049ceb23e48"
integrity sha512-e9VsUYh0B1dzrmg0OAyHAMaEV+Ifrf2yqWl2ecGkwCX75whLgjfDxjR6dXlkahy+oL1Uqm3eGWZol04ZjIol7A==
dependencies:
"@babel/plugin-transform-classes" "^7.9.5"
medusa-core-utils "^1.1.9"
medusa-core-utils "1.1.16-dev-1626162503472"
randomatic "^3.1.1"
merge-descriptors@1.0.1: