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