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:
@@ -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",
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user