Skip to content

Commit

Permalink
all tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Jan 31, 2024
1 parent 320c0a2 commit 141647f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 26 deletions.
3 changes: 2 additions & 1 deletion models/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ let Model = {
}
}
}
// NOTE: All dishes with modifiers add as uniq dish
if (replace) {
orderDish = (await OrderDish.update({ id: orderDishId }, {
dish: dishObj.id,
Expand Down Expand Up @@ -1054,7 +1055,7 @@ let Model = {
if (!currentModifier) {
sails.log.error(`Order with id [${order.id}] has unknown modifier [${modifier.id}]`);
}
if (currentModifier.freeOfChargeAmount && typeof currentModifier.freeOfChargeAmount === "number" && currentModifier.freeOfChargeAmount > 0) {
if (currentModifier && currentModifier.freeOfChargeAmount && typeof currentModifier.freeOfChargeAmount === "number" && currentModifier.freeOfChargeAmount > 0) {
const freeAmountCost = new decimal_js_1.default(currentModifier.freeOfChargeAmount).times(modifierObj.price).toNumber();
const modifierCost = new decimal_js_1.default(modifier.amount).times(modifierObj.price).minus(freeAmountCost).toNumber();
itemCost = new decimal_js_1.default(itemCost).plus(modifierCost).toNumber();
Expand Down
5 changes: 4 additions & 1 deletion models/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ let Model = {
}

}

// NOTE: All dishes with modifiers add as uniq dish


if (replace) {
orderDish = (
Expand Down Expand Up @@ -1283,7 +1286,7 @@ let Model = {
if (!currentModifier) {
sails.log.error(`Order with id [${order.id}] has unknown modifier [${modifier.id}]`)
}
if (currentModifier.freeOfChargeAmount && typeof currentModifier.freeOfChargeAmount === "number" && currentModifier.freeOfChargeAmount > 0) {
if (currentModifier && currentModifier.freeOfChargeAmount && typeof currentModifier.freeOfChargeAmount === "number" && currentModifier.freeOfChargeAmount > 0) {
const freeAmountCost = new Decimal(currentModifier.freeOfChargeAmount).times(modifierObj.price).toNumber();
const modifierCost = new Decimal(modifier.amount).times(modifierObj.price).minus(freeAmountCost).toNumber();
itemCost = new Decimal(itemCost).plus(modifierCost).toNumber();
Expand Down
5 changes: 0 additions & 5 deletions test/integration/models/discount.test.ts

This file was deleted.

8 changes: 3 additions & 5 deletions test/integration/models/order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ExternalTestPaymentSystem_1 = __importDefault(require("../../unit/external
const decimal_js_1 = __importDefault(require("decimal.js"));
const customer_1 = require("../../mocks/customer");
describe("Order", function () {
this.timeout(10000);
this.timeout(60000);
let order;
let dishes;
let fullOrder;
Expand All @@ -17,12 +17,10 @@ describe("Order", function () {
// return true;
// });
// });
it("get dishes", async function () {
before;
before(async function () {
dishes = await Dish.find({});
});
it("create Сart", async function () {
order = await Order.create({ id: "create-cart" }).fetch();
(0, chai_1.expect)(order).to.be.an("object");
});
it("check model fields", async function () {
await Order.addDish({ id: order.id }, dishes[0], 1, [], "", "user");
Expand Down
11 changes: 5 additions & 6 deletions test/integration/models/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { customer, address } from "../../mocks/customer"

describe("Order", function () {

this.timeout(10000);
this.timeout(60000);
let order: Order;
let dishes: Dish[];
let fullOrder: Order;
Expand All @@ -24,13 +24,12 @@ describe("Order", function () {
// });
// });

it("get dishes", async function () {
dishes = await Dish.find({});
});

it("create Сart", async function () {
before

before(async function () {
dishes = await Dish.find({});
order = await Order.create({id:"create-cart"}).fetch();
expect(order).to.be.an("object");
});

it("check model fields", async function () {
Expand Down
6 changes: 4 additions & 2 deletions test/mocks/adapter/RMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ class TestRMS extends RMSAdapter_1.default {
return dishes;
}
createOrder(orderData) {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return;
}
checkOrder(orderData) {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return;
}
api(method, params) {
throw process.env[method] = JSON.stringify(params);
Expand Down
6 changes: 4 additions & 2 deletions test/mocks/adapter/RMS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ export class TestRMS extends RMSAdapter {


public createOrder(orderData: Order): Promise<Order> {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return
}

public checkOrder(orderData: Order): Promise<Order> {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return
}

public api(method: string, params: any): Promise<any> {
Expand Down
3 changes: 2 additions & 1 deletion test/mocks/adapter/bonusProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const BonusProgramAdapter_1 = __importDefault(require("../../../adapters/bonuspr
const fakerStatic = require("faker");
class InMemoryBonusProgramAdapter extends BonusProgramAdapter_1.default {
getUserInfo(user) {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return;
}
constructor(config) {
super(config);
Expand Down
3 changes: 2 additions & 1 deletion test/mocks/adapter/bonusProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import fakerStatic = require("faker");
import { RequiredField } from "../../../interfaces/toolsTS";
export class InMemoryBonusProgramAdapter extends BonusProgramAdapter {
public getUserInfo(user: User): Promise<RequiredField<Partial<Pick<Omit<UserBonusProgram, "id"> & User, "id" | "firstName" | "lastName" | "sex" | "email" | "birthday" | "externalId" | "externalCustomerId" | "balance">>, "id" | "externalId" | "externalCustomerId">> {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
return
}
private transactions: Map<string, BonusTransaction[]> = new Map();
private users: Map<string, User> = new Map();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/external_payments/ExternalTestPaymentSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PaymentAdapter_1 = __importDefault(require("../../../adapters/payment/Paym
var database = {};
class TestPaymentSystem extends PaymentAdapter_1.default {
cancelPayment(paymentDocument) {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
}
async createPayment(payment, backLinkSuccess, backLinkFail, testing) {
let paid_latency;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/external_payments/ExternalTestPaymentSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var database: any = {};

export default class TestPaymentSystem extends PaymentAdapter {
public cancelPayment(paymentDocument: PaymentDocument): Promise<PaymentDocument> {
throw new Error("Method not implemented.");
console.log("Method not implemented.");
}
private static instance: TestPaymentSystem;

Expand Down

0 comments on commit 141647f

Please sign in to comment.