|
| 1 | +import { ReferencesModelTest } from './models/reference-model-test'; |
1 | 2 | import { LambdaExpressionMetadata } from './../metadatas'; |
2 | 3 | import { ModelTest } from "./models/model-test"; |
3 | 4 | import { expect } from "chai"; |
@@ -53,6 +54,47 @@ describe("Expression method", () => { |
53 | 54 |
|
54 | 55 | }); |
55 | 56 |
|
| 57 | +describe("Expression get value", () => { |
| 58 | + let instance = <ModelTest>{ |
| 59 | + id: 1, |
| 60 | + name: "Test", |
| 61 | + description: "Descrição", |
| 62 | + date: new Date(), |
| 63 | + isValid: true, |
| 64 | + reference: <ReferencesModelTest>{ |
| 65 | + id: 2, |
| 66 | + name: "Reference" |
| 67 | + } |
| 68 | + }; |
| 69 | + |
| 70 | + it("get description", () => { |
| 71 | + const result = _expressionUtils.getValue(instance, "description") |
| 72 | + expect(result).to.equal("Descrição"); |
| 73 | + }); |
| 74 | + |
| 75 | + it("get reference.id", () => { |
| 76 | + const result = _expressionUtils.getValue(instance, "reference.id") |
| 77 | + expect(result).to.equal(2); |
| 78 | + }); |
| 79 | + |
| 80 | + it("get reference.name", () => { |
| 81 | + const result = _expressionUtils.getValue(instance, "reference.name") |
| 82 | + expect(result).to.equal("Reference"); |
| 83 | + }); |
| 84 | + |
| 85 | + it("get by expression reference.name", () => { |
| 86 | + const result = _expressionUtils.getValueByExpression(instance, x => x.reference.name) |
| 87 | + expect(result).to.equal("Reference"); |
| 88 | + }); |
| 89 | + |
| 90 | + it("get reference.abc not exist", () => { |
| 91 | + const result = _expressionUtils.getValue(instance, "reference.abc") |
| 92 | + expect(result).to.equal(void 0); |
| 93 | + }); |
| 94 | + |
| 95 | + |
| 96 | +}); |
| 97 | + |
56 | 98 | describe("Lambda Expression method", () => { |
57 | 99 |
|
58 | 100 | it("should return id == 0", () => { |
@@ -81,19 +123,4 @@ describe("Lambda Expression method", () => { |
81 | 123 | expect(result2.columnRight).to.equal(`'x.reference.id'`); |
82 | 124 | }); |
83 | 125 |
|
84 | | - |
85 | | - // it("should test", () => { |
86 | | - // const result = ExpressionUsage.lambda<ModelTest>((x) => x.id >= x.reference.id); |
87 | | - // expect(result.columnLeft).to.equal("x.id"); |
88 | | - // expect(result.operator).to.equal(">="); |
89 | | - // expect(result.columnRight).to.equal("x.reference.id"); |
90 | | - |
91 | | - // console.log(_expressionUtils.getColumnByLambdaExpression<ModelTest>((x) => x.id >= x.reference.id)); |
92 | | - // console.log(_expressionUtils.getColumnByLambdaExpression<ModelTest>((x) => x.id >= 0)); |
93 | | - |
94 | | - // const propertyRight = _expressionUtils.getPropertiesByExpressionString(result.expressionRight); |
95 | | - // console.log(propertyRight); |
96 | | - // console.log(_expressionUtils.getColumnByProperties(propertyRight)); |
97 | | - // }); |
98 | | - |
99 | 126 | }); |
0 commit comments