Skip to content

Commit

Permalink
added error message in design method of unlayer2be
Browse files Browse the repository at this point in the history
  • Loading branch information
barakaally committed Jan 29, 2022
1 parent b942783 commit 2a1a0a2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/model/bee.model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Style = exports.Text = exports.Descriptor = exports.ComputedStyle = exports.Content = exports.Column = exports.Module = exports.Container = exports.Row = exports.Body = exports.Template = exports.Page = exports.BeeDesign = void 0;
exports.Style = exports.Image = exports.Button = exports.Text = exports.Descriptor = exports.ComputedStyle = exports.Content = exports.Column = exports.Module = exports.Container = exports.Row = exports.Body = exports.Template = exports.Page = exports.BeeDesign = void 0;
class BeeDesign {
}
exports.BeeDesign = BeeDesign;
Expand Down Expand Up @@ -37,6 +37,12 @@ exports.Descriptor = Descriptor;
class Text {
}
exports.Text = Text;
class Button {
}
exports.Button = Button;
class Image {
}
exports.Image = Image;
class Style {
}
exports.Style = Style;
12 changes: 10 additions & 2 deletions lib/util/Unlayer2be.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/util/UnlayerEmailJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ class UnlayerEmailJson {
* @returns UnlayerDesign
*/
getDesign(data) {
var _a;
let design = {};
Object.entries(data["page"]).forEach(([key, value]) => {
if (!data["page"])
throw new Error("design must have page");
(_a = Object.entries(data["page"])) === null || _a === void 0 ? void 0 : _a.forEach(([key, value]) => {
switch (key) {
case "body":
design.body = {
Expand Down
15 changes: 13 additions & 2 deletions src/util/Unlayer2be.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asset from 'assert';
import { BeeDesign } from '../model/bee.model';
import { Unlayer2be } from './Unlayer2be';

describe('from', function () {
it("should return UnlayerDesign ", function () {
describe('Util:Unlayer2be', function () {

it("from, should return UnlayerDesign ", function () {

Object.keys(Unlayer2be.from("%7B%22counters%22%3A%7B%22u_column%22%3A1%2C%22u_row%22%3A1%2C%22u_content_heading%22%3A1%7D%2C%22body%22%3A%7B%22rows%22%3A%5B%7B%22cells%22%3A%5B1%5D%2C%22columns%22%3A%5B%7B%22contents%22%3A%5B%7B%22type%22%3A%22heading%22%2C%22values%22%3A%7B%22containerPadding%22%3A%2210px%22%2C%22headingType%22%3A%22h1%22%2C%22fontFamily%22%3A%7B%22label%22%3A%22Arial%22%2C%22value%22%3A%22arial%2Chelvetica%2Csans-serif%22%7D%2C%22fontSize%22%3A%2222px%22%2C%22textAlign%22%3A%22left%22%2C%22lineHeight%22%3A%22140%25%22%2C%22linkStyle%22%3A%7B%22inherit%22%3Atrue%2C%22linkColor%22%3A%22%230000ee%22%2C%22linkHoverColor%22%3A%22%230000ee%22%2C%22linkUnderline%22%3Atrue%2C%22linkHoverUnderline%22%3Atrue%7D%2C%22displayCondition%22%3Anull%2C%22_meta%22%3A%7B%22htmlID%22%3A%22u_content_heading_1%22%2C%22htmlClassNames%22%3A%22u_content_heading%22%7D%2C%22selectable%22%3Atrue%2C%22draggable%22%3Atrue%2C%22duplicatable%22%3Atrue%2C%22deletable%22%3Atrue%2C%22hideable%22%3Atrue%2C%22text%22%3A%22Heading%22%7D%7D%5D%2C%22values%22%3A%7B%22backgroundColor%22%3A%22%22%2C%22padding%22%3A%220px%22%2C%22border%22%3A%7B%7D%2C%22_meta%22%3A%7B%22htmlID%22%3A%22u_column_1%22%2C%22htmlClassNames%22%3A%22u_column%22%7D%7D%7D%5D%2C%22values%22%3A%7B%22displayCondition%22%3Anull%2C%22columns%22%3Afalse%2C%22backgroundColor%22%3A%22%22%2C%22columnsBackgroundColor%22%3A%22%22%2C%22backgroundImage%22%3A%7B%22url%22%3A%22%22%2C%22fullWidth%22%3Atrue%2C%22repeat%22%3Afalse%2C%22center%22%3Atrue%2C%22cover%22%3Afalse%7D%2C%22padding%22%3A%220px%22%2C%22hideDesktop%22%3Afalse%2C%22_meta%22%3A%7B%22htmlID%22%3A%22u_row_1%22%2C%22htmlClassNames%22%3A%22u_row%22%7D%2C%22selectable%22%3Atrue%2C%22draggable%22%3Atrue%2C%22duplicatable%22%3Atrue%2C%22deletable%22%3Atrue%2C%22hideable%22%3Atrue%7D%7D%5D%2C%22values%22%3A%7B%22textColor%22%3A%22%23000000%22%2C%22backgroundColor%22%3A%22%23e7e7e7%22%2C%22backgroundImage%22%3A%7B%22url%22%3A%22%22%2C%22fullWidth%22%3Atrue%2C%22repeat%22%3Afalse%2C%22center%22%3Atrue%2C%22cover%22%3Afalse%7D%2C%22contentWidth%22%3A%22500px%22%2C%22contentAlign%22%3A%22center%22%2C%22fontFamily%22%3A%7B%22label%22%3A%22Arial%22%2C%22value%22%3A%22arial%2Chelvetica%2Csans-serif%22%7D%2C%22preheaderText%22%3A%22%22%2C%22linkStyle%22%3A%7B%22body%22%3Atrue%2C%22linkColor%22%3A%22%230000ee%22%2C%22linkHoverColor%22%3A%22%230000ee%22%2C%22linkUnderline%22%3Atrue%2C%22linkHoverUnderline%22%3Atrue%7D%2C%22_meta%22%3A%7B%22htmlID%22%3A%22u_body%22%2C%22htmlClassNames%22%3A%22u_body%22%7D%7D%7D%2C%22schemaVersion%22%3A7%7D")).forEach(key => {
describe(`should contain ${key}`, () => {
Expand All @@ -11,4 +13,13 @@ describe('from', function () {
});

});

it("design, should return error message ", () => {
try {
Unlayer2be.design({} as BeeDesign);
} catch (error: any) {
asset.strictEqual(error.message, "design must have page")
}
});

});
4 changes: 3 additions & 1 deletion src/util/UnlayerEmailJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class UnlayerEmailJson {

let design = {} as UnlayerDesign;

Object.entries(data["page"]).forEach(([key, value]) => {
if(!data["page"])throw new Error("design must have page");

Object.entries(data["page"])?.forEach(([key, value]) => {

switch (key) {
case "body":
Expand Down

0 comments on commit 2a1a0a2

Please sign in to comment.