Skip to content

Commit

Permalink
fix core MF
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Apr 30, 2024
1 parent 6eec9cf commit 039b8f4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion adapters/mediafile/MediaFileAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MediaFileAdapter {
let mediaFile = await MediaFile.findOne({ id: imageId });
let toDownload = force;
// Todo: delete it in v3
if (!mediaFile.type) {
if (mediaFile !== undefined && !mediaFile.type) {
mediaFile.type = type;
}
if (mediaFile) {
Expand Down
11 changes: 6 additions & 5 deletions adapters/mediafile/MediaFileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ export default abstract class MediaFileAdapter {
let toDownload = force;

// Todo: delete it in v3
if(!mediaFile.type){
if (mediaFile !== undefined && !mediaFile.type) {
mediaFile.type = type;
}

if(mediaFile) {
if(await this.checkFileExist(mediaFile) === false){

if (mediaFile) {
if (await this.checkFileExist(mediaFile) === false) {
toDownload = true;
}
} else {
Expand All @@ -69,7 +70,7 @@ export default abstract class MediaFileAdapter {
if (target && this.config && this.config[target]) {
loadConfig = this.config[target];
}

switch (type) {
case "image":
mediaFile.images = await this.process(url, "image", loadConfig);
Expand All @@ -91,7 +92,7 @@ export default abstract class MediaFileAdapter {
/**
* The problem remains that we cannot know whether the picture has loaded or not, and therefore. if it doesn't exist you need to somehow remove MF
*/
mediaFile = (await MediaFile.update({id: mediaFile.id},{images: mediaFile.images, original: url, type: type}).fetch())[0]
mediaFile = (await MediaFile.update({ id: mediaFile.id }, { images: mediaFile.images, original: url, type: type }).fetch())[0]
}
return mediaFile;
};
Expand Down
2 changes: 1 addition & 1 deletion adapters/mediafile/default/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const sharp_1 = __importDefault(require("sharp"));
class LocalMediaFileAdapter extends MediaFileAdapter_1.default {
async checkFileExist(mediaFile) {
let allFileExist = true;
if (mediaFile && /* mediaFile.type === "image" && **/ typeof mediaFile.images === "object" && Object.keys(mediaFile.images).length) {
if (mediaFile && /* mediaFile.type === "image" && **/ typeof mediaFile.images === "object" && mediaFile.images !== null && Object.keys(mediaFile.images).length) {
const images = mediaFile.images;
for (const key in images) {
const imageFilePath = path.join(this.getPrefix(), images[key]);
Expand Down
2 changes: 1 addition & 1 deletion adapters/mediafile/default/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class LocalMediaFileAdapter extends MediaFileAdapter {
public async checkFileExist(mediaFile: IMediaFile): Promise<boolean> {
let allFileExist: boolean = true;

if (mediaFile && /* mediaFile.type === "image" && **/ typeof mediaFile.images === "object" && Object.keys(mediaFile.images).length) {
if (mediaFile && /* mediaFile.type === "image" && **/ typeof mediaFile.images === "object" && mediaFile.images !== null && Object.keys(mediaFile.images).length) {
const images = mediaFile.images;

for (const key in images) {
Expand Down
13 changes: 6 additions & 7 deletions libs/DialogBox.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DialogBox = void 0;
const uuid_1 = require("uuid");
const ajv_1 = require("ajv");
const ajv_1 = __importDefault(require("ajv"));
const ajv = new ajv_1.default();
let jsonSchema = require("./schemas/dialogBoxConfig.json");
const validate = ajv.compile(jsonSchema);
class DialogBox {
config;
user;
answerId = null;
askId;
deviceId;
static dialogs = {};
constructor(config, deviceId) {
this.answerId = null;
if (config.type === undefined)
config.type = "routine";
if (config.allowClosing === undefined)
Expand Down Expand Up @@ -73,3 +71,4 @@ class DialogBox {
}
}
exports.DialogBox = DialogBox;
DialogBox.dialogs = {};
6 changes: 3 additions & 3 deletions test/integration/promotionCode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ describe("Promotion code integration test", function () {
await Order.applyPromotionCode({ id: order.id }, null);
result = await Order.findOne({ id: order.id });
(0, chai_1.expect)(result.discountTotal).to.equal(0);
(0, chai_1.expect)(result.total).to.equal(111.3);
(0, chai_1.expect)(result.total).to.equal(211.4);
(0, chai_1.expect)(result.state).to.equal("CART");
// NOT VALID PROMOCODE
await Order.applyPromotionCode({ id: order.id }, "WINTER2024NHATRANG");
result = await Order.findOne({ id: order.id });
(0, chai_1.expect)(result.discountTotal).to.equal(0);
(0, chai_1.expect)(result.total).to.equal(111.3);
(0, chai_1.expect)(result.total).to.equal(211.4);
(0, chai_1.expect)(result.promotionCodeCheckValidTill).to.equal(null);
(0, chai_1.expect)(result.promotionCodeString).to.equal("WINTER2024NHATRANG");
(0, chai_1.expect)(result.promotionCode).to.equal(null);
Expand All @@ -90,7 +90,7 @@ describe("Promotion code integration test", function () {
(0, chai_1.expect)(result.promotionCodeString).to.equal("TEST123");
(0, chai_1.expect)(result.discountTotal).to.equal(1.45);
(0, chai_1.expect)(result.promotionFlatDiscount).to.equal(1.45);
(0, chai_1.expect)(result.total).to.equal(109.85);
(0, chai_1.expect)(result.total).to.equal(209.95);
(0, chai_1.expect)(result.basketTotal).to.equal(111.3);
});
it("Percentage discount by promocode (Hot change existing + apply)", async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/DialogBox/DialogBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ describe('DialogBox', () => {
id: 'button1',
label: 'Button 1',
button: {
label: 'Button 1',
type: 'primary'
}
},
{
id: 'button2',
label: 'Button 2',
button: {
label: 'Button 2',
type: 'secondary'
}
}]
Expand Down

0 comments on commit 039b8f4

Please sign in to comment.