@legalplace/lplogic 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ import { Parser, References } from "../lib/index"
2
+ import fs from "fs"
3
+
4
+ // Getting & Parsing models
5
+ let ExpectedModelV3 = JSON.parse(fs.readFileSync("./tests/misc/expected-model-v3.json", "UTF-8"))
6
+ let UnparsedModelV3 = JSON.parse(fs.readFileSync("./tests/misc/unparsed-model-v3.json", "UTF-8"))
7
+
8
+ // Getting Conditions v1 & v3 by option ID
9
+ let ConditionsV1:Record<string, any> = {}
10
+ let ConditionsV3:Record<string, any> = {}
11
+
12
+ // Unparsed Conditions
13
+ Object.keys(UnparsedModelV3.options).forEach((id) => {
14
+
15
+ let meta = UnparsedModelV3.options[ id ].meta
16
+ if(Array.isArray(meta.compiledConditions) && meta.compiledConditions.length > 0)
17
+ ConditionsV1[ id ] = meta.compiledConditions
18
+ })
19
+
20
+ // Expected Conditions
21
+ Object.keys(ExpectedModelV3.options).forEach((id) => {
22
+ let meta = ExpectedModelV3.options[ id ].meta
23
+ if(typeof meta.compiledConditions === 'object' && Object.keys(meta.compiledConditions).length > 0)
24
+ ConditionsV3[ id ] = meta.compiledConditions
25
+ })
26
+
27
+ // Setting Refs
28
+ beforeAll(() => {
29
+ References.setRefs(UnparsedModelV3.documents.main.sections, UnparsedModelV3.options, UnparsedModelV3.variables);
30
+ })
31
+
32
+ // Starting tests
33
+ describe(`Parser: Testing Conditions Parsing from V1 to V3 (LpLogic)`, () => {
34
+ for(let id in ConditionsV1){
35
+ it(`Parsing conditions for option id ${id}`, async () => {
36
+ let parsedCondition = new Parser(ConditionsV1[id]).getLogic();
37
+ expect(parsedCondition).toStrictEqual( ConditionsV3[id] )
38
+ })
39
+ }
40
+ })
@@ -0,0 +1,26 @@
1
+ import { References } from "../lib/index"
2
+ import fs from "fs"
3
+
4
+ // Getting & Parsing model & expected refs
5
+ let ExpectedModelV3 = JSON.parse(fs.readFileSync("./tests/misc/expected-model-v3.json", "UTF-8"))
6
+ let RefsModelV3 = JSON.parse(fs.readFileSync("./tests/misc/refs-model-v3.json", "UTF-8"))
7
+
8
+ // Initiating refs
9
+ beforeAll(() => {
10
+ References.setRefs(ExpectedModelV3.documents.main.sections, ExpectedModelV3.options, ExpectedModelV3.variables);
11
+ })
12
+
13
+ // Running tests on parentsTree
14
+ test('Testing parentsTree', async () => {
15
+ expect(References.getParentsTree()).toStrictEqual(RefsModelV3.parentsTree)
16
+ })
17
+
18
+ // Running tests on conditionnedOptions
19
+ test('Testing conditionnedOptions', async () => {
20
+ expect(References.getConditionnedOptions()).toStrictEqual(RefsModelV3.conditionnedOptions)
21
+ })
22
+
23
+ // Running tests on multiplesDependencies
24
+ test('Testing multiplesDependencies', async () => {
25
+ expect(References.getMultiplesDependencies()).toStrictEqual(RefsModelV3.multiplesDependencies)
26
+ })