@legalplace/tagextractor 2.0.0 → 2.2.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,278 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Extractor_1 = __importDefault(require("./Extractor"));
7
+ const ovc_json_1 = __importDefault(require("./fixtures/ovc.json"));
8
+ const inputs_json_1 = __importDefault(require("./fixtures/inputs.json"));
9
+ const references_json_1 = __importDefault(require("./fixtures/references.json"));
10
+ const model_json_1 = __importDefault(require("./fixtures/model.json"));
11
+ const simpleReferences = references_json_1.default;
12
+ const simpleModel = model_json_1.default;
13
+ const simpleOvc = ovc_json_1.default;
14
+ const simpleInputs = inputs_json_1.default;
15
+ describe("TagsExtractor", () => {
16
+ const tagExtractor = new Extractor_1.default(simpleReferences, simpleInputs);
17
+ afterEach(() => {
18
+ jest.clearAllMocks();
19
+ jest.restoreAllMocks();
20
+ });
21
+ describe("IsVariableDisplayed", () => {
22
+ it("should return false when variable condition is false", () => {
23
+ const getVariableCondition = jest.spyOn(Extractor_1.default.prototype, "getVariableCondition");
24
+ getVariableCondition.mockImplementation(() => false);
25
+ expect(tagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
26
+ expect(getVariableCondition).toHaveBeenCalledWith(1, 0);
27
+ });
28
+ it("should return false when parent Option is not displayed", () => {
29
+ const isOptionDisplayed = jest.spyOn(Extractor_1.default.prototype, "isOptionDisplayed");
30
+ isOptionDisplayed.mockImplementation(() => false);
31
+ expect(tagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
32
+ expect(isOptionDisplayed).toHaveBeenCalledWith(6, 0);
33
+ });
34
+ it("should return false when parent Option is not truthful", () => {
35
+ const inputsWithParentsFalse = {
36
+ ...simpleInputs,
37
+ options: { ...simpleInputs.options, "6": [false] }
38
+ };
39
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsFalse);
40
+ expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
41
+ });
42
+ it("should return true when all checks are okay", () => {
43
+ const inputsWithAllChecks = {
44
+ ...simpleInputs,
45
+ options: { ...simpleInputs.options, "8": [true] }
46
+ };
47
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithAllChecks);
48
+ expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeTruthy();
49
+ });
50
+ });
51
+ describe("IsOptionDisplayed", () => {
52
+ it("should return false when option condition is false", () => {
53
+ const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
54
+ getOptionCondition.mockImplementation((id, index) => {
55
+ return !(id === 24 && index === 0);
56
+ });
57
+ expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
58
+ expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
59
+ });
60
+ it("should return false when parentSectionCondition is false", () => {
61
+ const getSectionCondition = jest.spyOn(Extractor_1.default.prototype, "getSectionCondition");
62
+ getSectionCondition.mockImplementation(() => false);
63
+ expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
64
+ expect(getSectionCondition).toHaveBeenCalledWith(1);
65
+ });
66
+ it("should return false when parentCondition contains false value", () => {
67
+ const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
68
+ getOptionCondition.mockImplementation((id, index) => {
69
+ return !(id === 6 && index === 0);
70
+ });
71
+ expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
72
+ expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
73
+ });
74
+ it("should return false when parentsInputs list contains false value", () => {
75
+ const inputsWithParentsInputsFalse = {
76
+ ...simpleInputs,
77
+ options: { ...simpleInputs.options, "6": [false] }
78
+ };
79
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsFalse);
80
+ expect(customTagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
81
+ });
82
+ it("should not return errors when parentsInputs is undefined", () => {
83
+ const inputsWithParentsInputsUndefined = {
84
+ ...simpleInputs,
85
+ options: { ...simpleInputs.options }
86
+ };
87
+ delete inputsWithParentsInputsUndefined.options["6"];
88
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsUndefined);
89
+ expect(customTagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
90
+ });
91
+ it("should return true when all checks are okay", () => {
92
+ expect(tagExtractor.isOptionDisplayed(24, 0)).toBeTruthy();
93
+ });
94
+ });
95
+ describe("convertToOptionVariables", () => {
96
+ it("should tag extraction match when instanciating TagExtractor with ovc or inputs", () => {
97
+ const customTagExtractor = new Extractor_1.default(simpleReferences, simpleOvc);
98
+ const expectedTags = new Extractor_1.default(simpleReferences, simpleInputs)
99
+ .getTags;
100
+ expect(customTagExtractor.getTags).toMatchObject(expectedTags);
101
+ });
102
+ });
103
+ describe("ReferenceParser", () => {
104
+ it("should tag extraction match when instanciating TagExtractor with model or references", () => {
105
+ const customTagExtractor = new Extractor_1.default(simpleModel, simpleInputs);
106
+ const expectedTags = new Extractor_1.default(simpleReferences, simpleInputs)
107
+ .getTags;
108
+ expect(customTagExtractor.getTags).toMatchObject(expectedTags);
109
+ });
110
+ });
111
+ describe("extractFromOptions", () => {
112
+ it("should return empty tag object when tags are undefined", () => {
113
+ const referencesWithoutOptionTagArray = {
114
+ ...simpleReferences,
115
+ options: {
116
+ ...simpleReferences.options,
117
+ "7": {
118
+ ...simpleReferences.options["7"],
119
+ meta: { ...simpleReferences.options["7"].meta, tags: undefined }
120
+ }
121
+ }
122
+ };
123
+ const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTagArray, simpleInputs);
124
+ expect(customTagExtractor.getTags.options).toMatchObject({});
125
+ });
126
+ it("should return empty tag object when options tags are empty", () => {
127
+ const referencesWithoutOptionTags = {
128
+ ...simpleReferences,
129
+ options: {
130
+ ...simpleReferences.options,
131
+ "7": {
132
+ ...simpleReferences.options["7"],
133
+ meta: { ...simpleReferences.options["7"].meta, tags: [] }
134
+ }
135
+ }
136
+ };
137
+ const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTags, simpleInputs);
138
+ expect(customTagExtractor.getTags.options).toMatchObject({});
139
+ });
140
+ it("should return empty tags when input's option is undefined", () => {
141
+ const inputsWithoutOptionTaggedAnswer = {
142
+ ...simpleInputs,
143
+ options: { ...simpleInputs.options }
144
+ };
145
+ delete inputsWithoutOptionTaggedAnswer.options["7"];
146
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutOptionTaggedAnswer);
147
+ expect(customTagExtractor.getTags.options).toMatchObject({});
148
+ });
149
+ it("should return option tag when champ multiples", () => {
150
+ const inputWithChampMultiple = {
151
+ ...simpleInputs,
152
+ options: { ...simpleInputs.options, "7": [true, false] }
153
+ };
154
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputWithChampMultiple);
155
+ const expectedOptionTags = {
156
+ LP_fan: [
157
+ {
158
+ id: 7,
159
+ index: 0,
160
+ label: "Connaissiez-vous déjà LegalPlace ?",
161
+ condition: true,
162
+ visible: true,
163
+ value: true
164
+ },
165
+ {
166
+ id: 7,
167
+ index: 1,
168
+ label: "Connaissiez-vous déjà LegalPlace ?",
169
+ condition: true,
170
+ visible: true,
171
+ value: false
172
+ }
173
+ ]
174
+ };
175
+ expect(customTagExtractor.getTags.options).toMatchObject(expectedOptionTags);
176
+ });
177
+ it("should return option tags", () => {
178
+ const expectedOptionTags = {
179
+ LP_fan: [
180
+ {
181
+ id: 7,
182
+ index: 0,
183
+ label: "Connaissiez-vous déjà LegalPlace ?",
184
+ condition: true,
185
+ visible: true,
186
+ value: true
187
+ }
188
+ ]
189
+ };
190
+ expect(tagExtractor.getTags.options).toMatchObject(expectedOptionTags);
191
+ });
192
+ });
193
+ describe("extractFromVariables", () => {
194
+ it("should return empty tag object when tags are undefined", () => {
195
+ const referenceWithoutVariableTagArray = {
196
+ ...simpleReferences,
197
+ variables: {
198
+ ...simpleReferences.variables,
199
+ "1": { ...simpleReferences.variables["1"], tags: undefined }
200
+ }
201
+ };
202
+ const customTagExtractor = new Extractor_1.default(referenceWithoutVariableTagArray, simpleInputs);
203
+ expect(customTagExtractor.getTags.variables).toMatchObject({});
204
+ });
205
+ it("should return empty tag object when variables tags are empty", () => {
206
+ const referenceWithoutTags = {
207
+ ...simpleReferences,
208
+ variables: {
209
+ ...simpleReferences.variables,
210
+ "1": { ...simpleReferences.variables["1"], tags: [] }
211
+ }
212
+ };
213
+ const customTagExtractor = new Extractor_1.default(referenceWithoutTags, simpleInputs);
214
+ expect(customTagExtractor.getTags.variables).toMatchObject({});
215
+ });
216
+ it("should return empty tags when input's variable is undefined", () => {
217
+ const inputsWithoutVariableTaggedAnswer = {
218
+ ...simpleInputs,
219
+ variables: { ...simpleInputs.variables }
220
+ };
221
+ delete inputsWithoutVariableTaggedAnswer.variables[1];
222
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutVariableTaggedAnswer);
223
+ expect(customTagExtractor.getTags.variables).toMatchObject({});
224
+ });
225
+ it("should not throw error when input's variable does not match any references variable", () => {
226
+ const referenceWithoutMatchingVariable = {
227
+ ...simpleReferences,
228
+ variables: { ...simpleReferences.variables }
229
+ };
230
+ delete referenceWithoutMatchingVariable.variables["2"];
231
+ const customTagExtractor = new Extractor_1.default(referenceWithoutMatchingVariable, simpleInputs);
232
+ const expectedVariableTags = {
233
+ Company_name: [
234
+ {
235
+ id: 1,
236
+ index: 0,
237
+ label: "Nom de l'entreprise",
238
+ condition: false,
239
+ visible: false,
240
+ value: "Company"
241
+ }
242
+ ]
243
+ };
244
+ expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
245
+ });
246
+ it("should return variable tag when champ multiples", () => {
247
+ const inputVariableWithChampMultiple = {
248
+ ...simpleInputs,
249
+ variables: {
250
+ ...simpleInputs.variables,
251
+ "1": ["Nom de la companie", "Testing Company"]
252
+ }
253
+ };
254
+ const customTagExtractor = new Extractor_1.default(simpleReferences, inputVariableWithChampMultiple);
255
+ const expectedVariableTags = {
256
+ Company_name: [
257
+ {
258
+ id: 1,
259
+ index: 0,
260
+ label: "Nom de l'entreprise",
261
+ condition: false,
262
+ visible: false,
263
+ value: "Nom de la companie"
264
+ },
265
+ {
266
+ id: 1,
267
+ index: 1,
268
+ label: "Nom de l'entreprise",
269
+ condition: false,
270
+ visible: false,
271
+ value: "Testing Company"
272
+ }
273
+ ]
274
+ };
275
+ expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
276
+ });
277
+ });
278
+ });
@@ -0,0 +1,60 @@
1
+ {
2
+ "options": {
3
+ "1": [
4
+ true
5
+ ],
6
+ "2": [
7
+ true
8
+ ],
9
+ "5": [
10
+ true
11
+ ],
12
+ "6": [
13
+ true
14
+ ],
15
+ "7": [
16
+ true
17
+ ],
18
+ "8": [
19
+ false
20
+ ],
21
+ "10": [
22
+ false
23
+ ],
24
+ "11": [
25
+ true
26
+ ],
27
+ "12": [
28
+ true
29
+ ],
30
+ "13": [
31
+ false
32
+ ],
33
+ "14": [
34
+ false
35
+ ],
36
+ "15": [
37
+ false
38
+ ],
39
+ "16": [
40
+ true
41
+ ],
42
+ "18": [
43
+ false
44
+ ],
45
+ "24": [
46
+ true
47
+ ]
48
+ },
49
+ "variables": {
50
+ "1": [
51
+ "Company"
52
+ ],
53
+ "2": [
54
+ ""
55
+ ],
56
+ "5": [
57
+ "Non merci"
58
+ ]
59
+ }
60
+ }
@@ -0,0 +1,291 @@
1
+ {
2
+ "documents": {
3
+ "main": {
4
+ "name": "main",
5
+ "sections": [
6
+ {
7
+ "id": 1,
8
+ "label": "Première section",
9
+ "options": [
10
+ 1,
11
+ 2,
12
+ 5,
13
+ 6,
14
+ 7,
15
+ 11
16
+ ]
17
+ },
18
+ {
19
+ "id": 2,
20
+ "label": "Deuxième section ",
21
+ "options": [
22
+ 15,
23
+ 16
24
+ ],
25
+ "grantLevel": "ADMIN"
26
+ }
27
+ ]
28
+ }
29
+ },
30
+ "options": {
31
+ "1": {
32
+ "meta": {
33
+ "type": "hidden",
34
+ "label": "Text de la question",
35
+ "output": "<p></p>",
36
+ "step": "*",
37
+ "id": 1
38
+ },
39
+ "variables": [],
40
+ "options": []
41
+ },
42
+ "2": {
43
+ "meta": {
44
+ "type": "box",
45
+ "id": 2,
46
+ "step": "*",
47
+ "box": {
48
+ "type": "light",
49
+ "content": "<p>Ceci est du texte de présentation de la première section</p>"
50
+ },
51
+ "label": ""
52
+ },
53
+ "options": [],
54
+ "variables": []
55
+ },
56
+ "5": {
57
+ "meta": {
58
+ "type": "checkbox",
59
+ "id": 5,
60
+ "step": "*",
61
+ "label": "J'ai déjà choisi le nom de mon entreprise (conditionne la question sur le nom de l'entreprise)",
62
+ "conditions": {
63
+ "and": [
64
+ {
65
+ "selected": [
66
+ {
67
+ "var": "o.12"
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ }
73
+ },
74
+ "options": [],
75
+ "variables": []
76
+ },
77
+ "6": {
78
+ "meta": {
79
+ "type": "static",
80
+ "id": 6,
81
+ "label": "Quel est le nom de votre entreprise ?",
82
+ "step": "*",
83
+ "conditions": {
84
+ "and": [
85
+ {
86
+ "selected": [
87
+ {
88
+ "var": "o.5"
89
+ }
90
+ ]
91
+ }
92
+ ]
93
+ },
94
+ "multiple": {
95
+ "enabled": false
96
+ },
97
+ "style": "full"
98
+ },
99
+ "options": [
100
+ 18,
101
+ 24
102
+ ],
103
+ "variables": [
104
+ 1
105
+ ]
106
+ },
107
+ "7": {
108
+ "meta": {
109
+ "type": "static",
110
+ "id": 7,
111
+ "label": "Connaissiez-vous déjà LegalPlace ?",
112
+ "step": "*",
113
+ "hidden": false,
114
+ "tags": [
115
+ "LP_fan"
116
+ ]
117
+ },
118
+ "options": [
119
+ 8,
120
+ 10
121
+ ],
122
+ "variables": []
123
+ },
124
+ "8": {
125
+ "meta": {
126
+ "type": "radio",
127
+ "id": 8,
128
+ "step": "*",
129
+ "label": "Oui j'adore"
130
+ },
131
+ "options": [],
132
+ "variables": []
133
+ },
134
+ "10": {
135
+ "meta": {
136
+ "type": "radio",
137
+ "id": 10,
138
+ "step": "*",
139
+ "label": "Non"
140
+ },
141
+ "options": [],
142
+ "variables": []
143
+ },
144
+ "11": {
145
+ "meta": {
146
+ "type": "static",
147
+ "id": 11,
148
+ "label": "Quel type d'entreprise ? ",
149
+ "step": "*"
150
+ },
151
+ "options": [
152
+ 12,
153
+ 13,
154
+ 14
155
+ ],
156
+ "variables": []
157
+ },
158
+ "12": {
159
+ "meta": {
160
+ "type": "radio",
161
+ "id": 12,
162
+ "step": "*",
163
+ "label": "SAS"
164
+ },
165
+ "options": [],
166
+ "variables": []
167
+ },
168
+ "13": {
169
+ "meta": {
170
+ "type": "radio",
171
+ "id": 13,
172
+ "step": "*",
173
+ "label": "SASU"
174
+ },
175
+ "options": [],
176
+ "variables": []
177
+ },
178
+ "14": {
179
+ "meta": {
180
+ "type": "radio",
181
+ "id": 14,
182
+ "step": "*",
183
+ "label": "Autre"
184
+ },
185
+ "options": [],
186
+ "variables": []
187
+ },
188
+ "15": {
189
+ "meta": {
190
+ "type": "checkbox",
191
+ "id": 15,
192
+ "step": "*",
193
+ "label": "Je souhaite avoir des questions supplémentaires"
194
+ },
195
+ "options": [],
196
+ "variables": []
197
+ },
198
+ "16": {
199
+ "meta": {
200
+ "type": "static",
201
+ "id": 16,
202
+ "label": "Choisissez le jour de la semaine",
203
+ "step": "*",
204
+ "conditions": {
205
+ "and": [
206
+ {
207
+ "selected": [
208
+ {
209
+ "var": "o.15"
210
+ }
211
+ ]
212
+ }
213
+ ]
214
+ }
215
+ },
216
+ "options": [],
217
+ "variables": [
218
+ 2
219
+ ]
220
+ },
221
+ "18": {
222
+ "meta": {
223
+ "type": "checkbox",
224
+ "id": 18,
225
+ "step": "*",
226
+ "label": "Orange"
227
+ },
228
+ "options": [],
229
+ "variables": []
230
+ },
231
+ "24": {
232
+ "meta": {
233
+ "type": "static",
234
+ "id": 24,
235
+ "label": "Voulez-vous changer de nom ? ",
236
+ "step": "*"
237
+ },
238
+ "options": [],
239
+ "variables": [
240
+ 5
241
+ ]
242
+ }
243
+ },
244
+ "variables": {
245
+ "1": {
246
+ "type": "text",
247
+ "id": 1,
248
+ "label": "Nom de l'entreprise",
249
+ "step": "*",
250
+ "mandatory": false,
251
+ "placeholder": "",
252
+ "conditions": {
253
+ "and": [
254
+ {
255
+ "selected": [
256
+ {
257
+ "var": "o.8"
258
+ }
259
+ ]
260
+ }
261
+ ]
262
+ },
263
+ "tags": [
264
+ "Company_name"
265
+ ],
266
+ "hidden": false
267
+ },
268
+ "2": {
269
+ "type": "list",
270
+ "id": 2,
271
+ "label": "Dropdown",
272
+ "step": "*",
273
+ "selectValues": [
274
+ "Lundi",
275
+ "Mardi",
276
+ "Mercredi",
277
+ "Jeudi",
278
+ "Vendredi"
279
+ ]
280
+ },
281
+ "5": {
282
+ "type": "text",
283
+ "id": 5,
284
+ "label": "Field",
285
+ "step": "*",
286
+ "mandatory": false,
287
+ "placeholder": ""
288
+ }
289
+ },
290
+ "customization": {}
291
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "o": {
3
+ "11": 12
4
+ },
5
+ "v": {
6
+ "1": "Company",
7
+ "2": "",
8
+ "5": "Non merci"
9
+ },
10
+ "c": {
11
+ "5": true,
12
+ "15": false,
13
+ "18": false
14
+ }
15
+ }