Feat/nested return reasons (#418)
* api endpoints for nested return_reasons * add nested return reasons to database * add parent reason to update * integration tests * add children relation * integration tests for nested returns and failing doubly nesting returns * add delete-route and nested relations * delete return reason route * doubly nested return reason creation check and deletion * nested return reasons migration * list only parent reasons * removed null filter * remove empty migration * add return reason filter to get list of categories with children * removed console log * corrected delete route * return reason testing * return reasons query * listREasonsFromIDs * create return testing * listReasonsFromIds * return reason tests * failing if returnreason has child on return * integration tests * cascading deletes on return reasons * more elegant checking for children of return reasons when creating a return * remove console.log * pr adjust Co-authored-by: Philip Korsholm <phko@MacBook-Pro.localdomain>
This commit is contained in:
co-authored by
Philip Korsholm
parent
4db860f9ab
commit
42cdfde6d9
@@ -26,16 +26,35 @@ describe("/store/return-reasons", () => {
|
||||
|
||||
describe("GET /store/return-reasons", () => {
|
||||
let rrId;
|
||||
let rrId_1;
|
||||
let rrId_2;
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
});
|
||||
|
||||
const result = await dbConnection.manager.save(created);
|
||||
rrId = result.id;
|
||||
|
||||
const created_child = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId
|
||||
});
|
||||
|
||||
const result_child = await dbConnection.manager.save(created_child);
|
||||
rrId_1 = result_child.id;
|
||||
|
||||
const created_2 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big_1",
|
||||
label: "Too Big 1",
|
||||
});
|
||||
|
||||
const result_2 = await dbConnection.manager.save(created_2);
|
||||
rrId_2 = result_2.id;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
@@ -59,7 +78,15 @@ describe("/store/return-reasons", () => {
|
||||
expect(response.data.return_reasons).toEqual([
|
||||
expect.objectContaining({
|
||||
id: rrId,
|
||||
value: "too_big",
|
||||
value: "wrong_size",
|
||||
return_reason_children:[expect.objectContaining({
|
||||
id: rrId_1,
|
||||
value: "too_big",
|
||||
}),]
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: rrId_2,
|
||||
value: "too_big_1",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ const {
|
||||
Product,
|
||||
ProductVariant,
|
||||
ShippingOption,
|
||||
FulfillmentProvider,
|
||||
LineItem,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
@@ -37,6 +38,8 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/returns", () => {
|
||||
let rrId;
|
||||
let rrId_child;
|
||||
let rrResult;
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
@@ -44,13 +47,17 @@ describe("/store/carts", () => {
|
||||
`ALTER SEQUENCE order_display_id_seq RESTART WITH 111`
|
||||
);
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
await manager.insert(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "cus_1234",
|
||||
email: "test@email.com",
|
||||
@@ -98,10 +105,6 @@ describe("/store/carts", () => {
|
||||
|
||||
await manager.save(ord);
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
await manager.insert(Product, {
|
||||
id: "test-product",
|
||||
title: "test product",
|
||||
@@ -147,12 +150,23 @@ describe("/store/carts", () => {
|
||||
});
|
||||
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
value: "wrong_size",
|
||||
label: "Wrong Size",
|
||||
});
|
||||
const result = await dbConnection.manager.save(created);
|
||||
|
||||
rrResult = result
|
||||
rrId = result.id;
|
||||
|
||||
const created_1 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId,
|
||||
});
|
||||
|
||||
const result_1 = await dbConnection.manager.save(created_1);
|
||||
|
||||
rrId_child = result_1.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -181,6 +195,59 @@ describe("/store/carts", () => {
|
||||
expect(response.data.return.refund_amount).toEqual(8000);
|
||||
});
|
||||
|
||||
it("failes to create a return with a reason category", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
order_id: "order_test",
|
||||
items: [
|
||||
{
|
||||
reason_id: rrId,
|
||||
note: "TOO small",
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.data.message).toEqual('Cannot apply return reason category')
|
||||
|
||||
});
|
||||
|
||||
it("creates a return with reasons", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
order_id: "order_test",
|
||||
items: [
|
||||
{
|
||||
reason_id: rrId_child,
|
||||
note: "TOO small",
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response)
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.return.items).toEqual([
|
||||
expect.objectContaining({
|
||||
reason_id: rrId_child,
|
||||
note: "TOO small",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("creates a return with discount and non-discountable item", async () => {
|
||||
const api = useApi();
|
||||
|
||||
@@ -234,32 +301,5 @@ describe("/store/carts", () => {
|
||||
expect(response.data.return.refund_amount).toEqual(7000);
|
||||
});
|
||||
|
||||
it("creates a return with reasons", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
order_id: "order_test",
|
||||
items: [
|
||||
{
|
||||
reason_id: rrId,
|
||||
note: "TOO small",
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.return.items).toEqual([
|
||||
expect.objectContaining({
|
||||
reason_id: rrId,
|
||||
note: "TOO small",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user