@dmptool/types 1.0.8 → 1.1.1
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.
- package/README.md +2 -0
- package/dist/answers/__tests__/answers.spec.js +18 -17
- package/dist/answers/index.d.ts +80 -55
- package/dist/answers/index.js +19 -17
- package/dist/answers/numberAnswers.d.ts +91 -0
- package/dist/answers/numberAnswers.js +21 -0
- package/dist/answers/optionBasedAnswers.d.ts +25 -0
- package/dist/answers/optionBasedAnswers.js +5 -1
- package/dist/answers/tableAnswers.d.ts +108 -108
- package/dist/answers/tableAnswers.js +9 -8
- package/dist/answers/textAnswers.d.ts +101 -0
- package/dist/answers/textAnswers.js +22 -0
- package/dist/questions/__tests__/dateQuestions.spec.js +20 -74
- package/dist/questions/__tests__/graphQLQuestions.spec.js +6 -0
- package/dist/questions/__tests__/numberQuestions.spec.js +108 -0
- package/dist/questions/__tests__/optionBasedQuestions.spec.js +91 -54
- package/dist/questions/__tests__/tableQuestion.spec.js +2 -0
- package/dist/questions/__tests__/textQuestions.spec.d.ts +1 -0
- package/dist/questions/__tests__/textQuestions.spec.js +120 -0
- package/dist/questions/dateQuestions.d.ts +159 -178
- package/dist/questions/dateQuestions.js +9 -15
- package/dist/questions/graphQLQuestions.d.ts +67 -38
- package/dist/questions/graphQLQuestions.js +3 -2
- package/dist/questions/index.d.ts +1800 -1379
- package/dist/questions/index.js +22 -19
- package/dist/questions/numberQuestions.d.ts +292 -0
- package/dist/questions/numberQuestions.js +28 -0
- package/dist/questions/optionBasedQuestions.d.ts +186 -157
- package/dist/questions/optionBasedQuestions.js +17 -20
- package/dist/questions/question.d.ts +29 -11
- package/dist/questions/question.js +10 -4
- package/dist/questions/tableQuestions.d.ts +2395 -2048
- package/dist/questions/tableQuestions.js +12 -10
- package/dist/questions/textQuestions.d.ts +261 -0
- package/dist/questions/textQuestions.js +42 -0
- package/dist/schemas/anyQuestion.schema.json +269 -238
- package/dist/schemas/anyTableColumnQuestion.schema.json +207 -216
- package/dist/schemas/booleanQuestion.schema.json +17 -11
- package/dist/schemas/checkboxesQuestion.schema.json +24 -27
- package/dist/schemas/currencyQuestion.schema.json +23 -18
- package/dist/schemas/dateQuestion.schema.json +21 -16
- package/dist/schemas/dateRangeQuestion.schema.json +31 -56
- package/dist/schemas/emailQuestion.schema.json +24 -19
- package/dist/schemas/filteredSearchQuestion.schema.json +18 -13
- package/dist/schemas/numberQuestion.schema.json +21 -16
- package/dist/schemas/numberRangeQuestion.schema.json +31 -56
- package/dist/schemas/radioButtonsQuestion.schema.json +24 -27
- package/dist/schemas/selectBoxQuestion.schema.json +27 -36
- package/dist/schemas/tableQuestion.schema.json +233 -234
- package/dist/schemas/textAreaQuestion.schema.json +22 -16
- package/dist/schemas/textQuestion.schema.json +21 -16
- package/dist/schemas/typeaheadSearchQuestion.schema.json +15 -4
- package/dist/schemas/urlQuestion.schema.json +21 -16
- package/package.json +1 -1
- package/dist/answers/primitiveAnswers.d.ts +0 -216
- package/dist/answers/primitiveAnswers.js +0 -41
- package/dist/questions/__tests__/primitiveQuestions.spec.js +0 -281
- package/dist/questions/primitiveQuestions.d.ts +0 -555
- package/dist/questions/primitiveQuestions.js +0 -86
- /package/dist/questions/__tests__/{primitiveQuestions.spec.d.ts → numberQuestions.spec.d.ts} +0 -0
|
@@ -6,6 +6,8 @@ describe("DateQuestion", () => {
|
|
|
6
6
|
const validDate = {
|
|
7
7
|
type: "date",
|
|
8
8
|
attributes: {
|
|
9
|
+
label: "Date",
|
|
10
|
+
help: "Enter a date",
|
|
9
11
|
max: "2023-12-31",
|
|
10
12
|
min: "2023-01-01",
|
|
11
13
|
step: 1,
|
|
@@ -47,28 +49,18 @@ describe("DateRangeQuestion", () => {
|
|
|
47
49
|
type: "dateRange",
|
|
48
50
|
columns: {
|
|
49
51
|
start: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
step: 1,
|
|
56
|
-
},
|
|
57
|
-
meta: {
|
|
58
|
-
schemaVersion: "1.0"
|
|
59
|
-
}
|
|
52
|
+
label: "Start Date",
|
|
53
|
+
help: "Enter a date",
|
|
54
|
+
max: "2023-12-31",
|
|
55
|
+
min: "2023-01-01",
|
|
56
|
+
step: 1,
|
|
60
57
|
},
|
|
61
58
|
end: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
step: 1,
|
|
68
|
-
},
|
|
69
|
-
meta: {
|
|
70
|
-
schemaVersion: "1.0"
|
|
71
|
-
}
|
|
59
|
+
label: "End Date",
|
|
60
|
+
help: "Enter a date",
|
|
61
|
+
max: "2023-12-31",
|
|
62
|
+
min: "2023-01-01",
|
|
63
|
+
step: 1,
|
|
72
64
|
},
|
|
73
65
|
},
|
|
74
66
|
meta: {
|
|
@@ -82,62 +74,16 @@ describe("DateRangeQuestion", () => {
|
|
|
82
74
|
type: "dateRange",
|
|
83
75
|
columns: {
|
|
84
76
|
start: {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
min: "2023-01-01",
|
|
90
|
-
step: 1,
|
|
91
|
-
},
|
|
92
|
-
meta: {
|
|
93
|
-
schemaVersion: "1.0"
|
|
94
|
-
}
|
|
77
|
+
label: "Start Date",
|
|
78
|
+
max: "2023-12-31",
|
|
79
|
+
min: "2023-01-01",
|
|
80
|
+
step: 1,
|
|
95
81
|
},
|
|
96
82
|
end: {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
min: "2023-01-01",
|
|
102
|
-
step: 1,
|
|
103
|
-
},
|
|
104
|
-
meta: {
|
|
105
|
-
schemaVersion: "1.0"
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
meta: {
|
|
110
|
-
schemaVersion: "1.0"
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
expect(() => dateQuestions_1.DateRangeQuestionSchema.parse(invalidDateRange)).toThrow();
|
|
114
|
-
});
|
|
115
|
-
it("should require labels for start and end dates", () => {
|
|
116
|
-
const invalidDateRange = {
|
|
117
|
-
type: "dateRange",
|
|
118
|
-
columns: {
|
|
119
|
-
start: {
|
|
120
|
-
type: "date",
|
|
121
|
-
attributes: {
|
|
122
|
-
max: "2023-12-31",
|
|
123
|
-
min: "2023-01-01",
|
|
124
|
-
step: 1,
|
|
125
|
-
},
|
|
126
|
-
meta: {
|
|
127
|
-
schemaVersion: "1.0"
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
end: {
|
|
131
|
-
type: "date",
|
|
132
|
-
attributes: {
|
|
133
|
-
label: "End Date",
|
|
134
|
-
max: "2023-12-31",
|
|
135
|
-
min: "2023-01-01",
|
|
136
|
-
step: 1,
|
|
137
|
-
},
|
|
138
|
-
meta: {
|
|
139
|
-
schemaVersion: "1.0"
|
|
140
|
-
}
|
|
83
|
+
label: 123, // Invalid type for label
|
|
84
|
+
max: "2023-12-31",
|
|
85
|
+
min: "2023-01-01",
|
|
86
|
+
step: 1,
|
|
141
87
|
},
|
|
142
88
|
},
|
|
143
89
|
meta: {
|
|
@@ -19,6 +19,8 @@ const graphQLQuestions_1 = require("../graphQLQuestions");
|
|
|
19
19
|
],
|
|
20
20
|
},
|
|
21
21
|
attributes: {
|
|
22
|
+
label: "Search",
|
|
23
|
+
help: "Search for a user",
|
|
22
24
|
multiple: true,
|
|
23
25
|
},
|
|
24
26
|
meta: {
|
|
@@ -53,6 +55,10 @@ const graphQLQuestions_1 = require("../graphQLQuestions");
|
|
|
53
55
|
(0, globals_1.it)("should validate a correct TypeaheadSearchQuestion object", () => {
|
|
54
56
|
const validData = {
|
|
55
57
|
type: "typeaheadSearch",
|
|
58
|
+
attributes: {
|
|
59
|
+
label: "Search",
|
|
60
|
+
help: "Search for a user",
|
|
61
|
+
},
|
|
56
62
|
graphQL: {
|
|
57
63
|
displayFields: [
|
|
58
64
|
{ propertyName: "title", label: "Title" },
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const numberQuestions_1 = require("../numberQuestions");
|
|
4
|
+
describe("Number Questions Zod Schemas", () => {
|
|
5
|
+
it("should validate a valid CurrencyQuestion", () => {
|
|
6
|
+
const validCurrencyQuestion = {
|
|
7
|
+
type: "currency",
|
|
8
|
+
meta: {
|
|
9
|
+
schemaVersion: "1.0",
|
|
10
|
+
denomination: "USD",
|
|
11
|
+
},
|
|
12
|
+
attributes: {
|
|
13
|
+
max: 100,
|
|
14
|
+
min: 1,
|
|
15
|
+
step: 0.01,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
expect(() => numberQuestions_1.CurrencyQuestionSchema.parse(validCurrencyQuestion)).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
it("should invalidate an invalid CurrencyQuestion", () => {
|
|
21
|
+
const invalidCurrencyQuestion = {
|
|
22
|
+
type: "currency",
|
|
23
|
+
meta: {
|
|
24
|
+
schemaVersion: "1.0",
|
|
25
|
+
},
|
|
26
|
+
attributes: {
|
|
27
|
+
max: "100", // Invalid type
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
expect(() => numberQuestions_1.CurrencyQuestionSchema.parse(invalidCurrencyQuestion)).toThrow();
|
|
31
|
+
});
|
|
32
|
+
it("should validate a valid NumberQuestion", () => {
|
|
33
|
+
const validNumberQuestion = {
|
|
34
|
+
type: "number",
|
|
35
|
+
meta: {
|
|
36
|
+
schemaVersion: "1.0",
|
|
37
|
+
},
|
|
38
|
+
attributes: {
|
|
39
|
+
max: 100,
|
|
40
|
+
min: 0,
|
|
41
|
+
step: 1,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
expect(() => numberQuestions_1.NumberQuestionSchema.parse(validNumberQuestion)).not.toThrow();
|
|
45
|
+
});
|
|
46
|
+
it("should invalidate an invalid NumberQuestion", () => {
|
|
47
|
+
const invalidNumberQuestion = {
|
|
48
|
+
type: "number",
|
|
49
|
+
meta: {
|
|
50
|
+
schemaVersion: "1.0",
|
|
51
|
+
},
|
|
52
|
+
attributes: {
|
|
53
|
+
step: "1", // Invalid type
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
expect(() => numberQuestions_1.NumberQuestionSchema.parse(invalidNumberQuestion)).toThrow();
|
|
57
|
+
});
|
|
58
|
+
it("should validate a valid NumberRangeQuestion", () => {
|
|
59
|
+
const validNumberRangeQuestion = {
|
|
60
|
+
type: "numberRange",
|
|
61
|
+
meta: {
|
|
62
|
+
schemaVersion: "1.0",
|
|
63
|
+
},
|
|
64
|
+
attributes: {
|
|
65
|
+
label: "Range",
|
|
66
|
+
help: "Enter a range"
|
|
67
|
+
},
|
|
68
|
+
columns: {
|
|
69
|
+
start: {
|
|
70
|
+
label: "Start",
|
|
71
|
+
help: "Enter a starting number",
|
|
72
|
+
min: 0,
|
|
73
|
+
max: 50,
|
|
74
|
+
step: 1,
|
|
75
|
+
},
|
|
76
|
+
end: {
|
|
77
|
+
label: "End",
|
|
78
|
+
help: "Enter an ending number",
|
|
79
|
+
min: 50,
|
|
80
|
+
max: 100,
|
|
81
|
+
step: 1,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
expect(() => numberQuestions_1.NumberRangeQuestionSchema.parse(validNumberRangeQuestion)).not.toThrow();
|
|
86
|
+
});
|
|
87
|
+
it("should invalidate an invalid NumberRangeQuestion", () => {
|
|
88
|
+
const invalidNumberRangeQuestion = {
|
|
89
|
+
type: "numberRange",
|
|
90
|
+
meta: {
|
|
91
|
+
schemaVersion: "1.0",
|
|
92
|
+
},
|
|
93
|
+
columns: {
|
|
94
|
+
start: {
|
|
95
|
+
min: 0,
|
|
96
|
+
max: 50,
|
|
97
|
+
},
|
|
98
|
+
end: {
|
|
99
|
+
label: "End",
|
|
100
|
+
min: 50,
|
|
101
|
+
max: "100",
|
|
102
|
+
step: 1,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
expect(() => numberQuestions_1.NumberRangeQuestionSchema.parse(invalidNumberRangeQuestion)).toThrow();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -2,25 +2,73 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const globals_1 = require("@jest/globals");
|
|
4
4
|
const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
5
|
+
(0, globals_1.describe)("BooleanQuestion", () => {
|
|
6
|
+
(0, globals_1.it)('optional fields should not throw an error if the value is undefined', () => {
|
|
7
|
+
const validBooleanQuestion = {
|
|
8
|
+
type: "boolean",
|
|
9
|
+
meta: {
|
|
10
|
+
schemaVersion: "1.0",
|
|
11
|
+
},
|
|
12
|
+
attributes: {
|
|
13
|
+
checked: undefined, // Valid value
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
(0, globals_1.expect)(() => optionBasedQuestions_1.BooleanQuestionSchema.parse(validBooleanQuestion)).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
(0, globals_1.it)('optional fields should throw an error if the value is null', () => {
|
|
19
|
+
const invalidBooleanQuestion = {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
meta: {
|
|
22
|
+
schemaVersion: "1.0",
|
|
23
|
+
},
|
|
24
|
+
attributes: {
|
|
25
|
+
checked: null, // Invalid value
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
(0, globals_1.expect)(() => optionBasedQuestions_1.BooleanQuestionSchema.parse(invalidBooleanQuestion)).toThrow();
|
|
29
|
+
});
|
|
30
|
+
(0, globals_1.it)("should validate a valid BooleanQuestion", () => {
|
|
31
|
+
const validBooleanQuestion = {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
meta: {
|
|
34
|
+
schemaVersion: "1.0",
|
|
35
|
+
},
|
|
36
|
+
attributes: {
|
|
37
|
+
checked: true,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
(0, globals_1.expect)(() => optionBasedQuestions_1.BooleanQuestionSchema.parse(validBooleanQuestion)).not.toThrow();
|
|
41
|
+
});
|
|
42
|
+
(0, globals_1.it)("should invalidate an invalid BooleanQuestion", () => {
|
|
43
|
+
const invalidBooleanQuestion = {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
meta: {
|
|
46
|
+
schemaVersion: "1.0",
|
|
47
|
+
},
|
|
48
|
+
attributes: {
|
|
49
|
+
checked: "true", // Invalid type
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
(0, globals_1.expect)(() => optionBasedQuestions_1.BooleanQuestionSchema.parse(invalidBooleanQuestion)).toThrow();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
5
55
|
(0, globals_1.describe)("CheckboxesQuestion", () => {
|
|
6
56
|
(0, globals_1.it)("should validate a valid CheckboxesQuestion object", () => {
|
|
7
57
|
const validCheckboxesQuestion = {
|
|
8
58
|
type: "checkBoxes",
|
|
59
|
+
attributes: {
|
|
60
|
+
label: "Fruits",
|
|
61
|
+
help: "Select all fruits you like",
|
|
62
|
+
},
|
|
9
63
|
options: [
|
|
10
64
|
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
value: "apple",
|
|
15
|
-
checked: true,
|
|
16
|
-
},
|
|
65
|
+
label: "Apple",
|
|
66
|
+
value: "apple",
|
|
67
|
+
checked: true,
|
|
17
68
|
},
|
|
18
69
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
label: "Banana",
|
|
22
|
-
value: "banana",
|
|
23
|
-
},
|
|
70
|
+
label: "Banana",
|
|
71
|
+
value: "banana",
|
|
24
72
|
},
|
|
25
73
|
],
|
|
26
74
|
meta: {
|
|
@@ -32,14 +80,15 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
32
80
|
(0, globals_1.it)("should throw an error for an invalid CheckboxesQuestion object", () => {
|
|
33
81
|
const invalidCheckboxesQuestion = {
|
|
34
82
|
type: "checkBoxes",
|
|
83
|
+
attributes: {
|
|
84
|
+
label: "Has an apple?",
|
|
85
|
+
help: "Whether or not you have an apple in your fridge.",
|
|
86
|
+
},
|
|
35
87
|
options: [
|
|
36
88
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value: "apple",
|
|
41
|
-
checked: "true", // Invalid type for checked
|
|
42
|
-
},
|
|
89
|
+
label: "Apple",
|
|
90
|
+
value: "apple",
|
|
91
|
+
checked: "true", // Invalid type for checked
|
|
43
92
|
},
|
|
44
93
|
],
|
|
45
94
|
meta: {
|
|
@@ -53,21 +102,19 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
53
102
|
(0, globals_1.it)("should validate a valid RadioButtonsQuestion object", () => {
|
|
54
103
|
const validRadioButtonsQuestion = {
|
|
55
104
|
type: "radioButtons",
|
|
105
|
+
attributes: {
|
|
106
|
+
label: "Fruits",
|
|
107
|
+
help: "Select all fruits you like",
|
|
108
|
+
},
|
|
56
109
|
options: [
|
|
57
110
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
value: "male",
|
|
62
|
-
selected: true,
|
|
63
|
-
},
|
|
111
|
+
label: "Male",
|
|
112
|
+
value: "male",
|
|
113
|
+
selected: true,
|
|
64
114
|
},
|
|
65
115
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
label: "Female",
|
|
69
|
-
value: "female",
|
|
70
|
-
},
|
|
116
|
+
label: "Female",
|
|
117
|
+
value: "female",
|
|
71
118
|
},
|
|
72
119
|
],
|
|
73
120
|
meta: {
|
|
@@ -81,12 +128,9 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
81
128
|
type: "radioButtons",
|
|
82
129
|
options: [
|
|
83
130
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
value: "male",
|
|
88
|
-
selected: "true", // Invalid type for selected
|
|
89
|
-
},
|
|
131
|
+
label: "Male",
|
|
132
|
+
value: "male",
|
|
133
|
+
selected: "true", // Invalid type for selected
|
|
90
134
|
},
|
|
91
135
|
],
|
|
92
136
|
meta: {
|
|
@@ -100,26 +144,22 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
100
144
|
(0, globals_1.it)("should validate a valid SelectBoxQuestion object", () => {
|
|
101
145
|
const validSelectBoxQuestion = {
|
|
102
146
|
type: "selectBox",
|
|
147
|
+
attributes: {
|
|
148
|
+
label: "Fruits",
|
|
149
|
+
help: "Select all fruits you like",
|
|
150
|
+
multiple: true,
|
|
151
|
+
},
|
|
103
152
|
options: [
|
|
104
153
|
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
value: "usa",
|
|
109
|
-
selected: true,
|
|
110
|
-
},
|
|
154
|
+
label: "USA",
|
|
155
|
+
value: "us",
|
|
156
|
+
selected: true,
|
|
111
157
|
},
|
|
112
158
|
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
label: "Canada",
|
|
116
|
-
value: "canada",
|
|
117
|
-
},
|
|
159
|
+
label: "Canada",
|
|
160
|
+
value: "ca",
|
|
118
161
|
},
|
|
119
162
|
],
|
|
120
|
-
attributes: {
|
|
121
|
-
multiple: true,
|
|
122
|
-
},
|
|
123
163
|
meta: {
|
|
124
164
|
schemaVersion: "1.0"
|
|
125
165
|
}
|
|
@@ -132,12 +172,9 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
132
172
|
questionText: "Select your country",
|
|
133
173
|
options: [
|
|
134
174
|
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
value: "usa",
|
|
139
|
-
selected: "true", // Invalid type for selected
|
|
140
|
-
},
|
|
175
|
+
label: "USA",
|
|
176
|
+
value: "us",
|
|
177
|
+
selected: "true", // Invalid type for selected
|
|
141
178
|
},
|
|
142
179
|
],
|
|
143
180
|
attributes: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const textQuestions_1 = require("../textQuestions");
|
|
4
|
+
describe("Primitive Questions Zod Schemas", () => {
|
|
5
|
+
it("should validate a valid EmailQuestion", () => {
|
|
6
|
+
const validEmailQuestion = {
|
|
7
|
+
type: "email",
|
|
8
|
+
meta: {
|
|
9
|
+
schemaVersion: "1.0",
|
|
10
|
+
},
|
|
11
|
+
attributes: {
|
|
12
|
+
label: "Email",
|
|
13
|
+
help: "Enter your email address",
|
|
14
|
+
maxLength: 50,
|
|
15
|
+
minLength: 5,
|
|
16
|
+
multiple: true,
|
|
17
|
+
pattern: "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
expect(() => textQuestions_1.EmailQuestionSchema.parse(validEmailQuestion)).not.toThrow();
|
|
21
|
+
});
|
|
22
|
+
it("should invalidate an invalid EmailQuestion", () => {
|
|
23
|
+
const invalidEmailQuestion = {
|
|
24
|
+
type: "email",
|
|
25
|
+
meta: {
|
|
26
|
+
schemaVersion: "1.0",
|
|
27
|
+
},
|
|
28
|
+
attributes: {
|
|
29
|
+
maxLength: "50", // Invalid type
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
expect(() => textQuestions_1.EmailQuestionSchema.parse(invalidEmailQuestion)).toThrow();
|
|
33
|
+
});
|
|
34
|
+
it("should validate a valid TextAreaQuestion", () => {
|
|
35
|
+
const validTextAreaQuestion = {
|
|
36
|
+
type: "textArea",
|
|
37
|
+
meta: {
|
|
38
|
+
schemaVersion: "1.0",
|
|
39
|
+
asRichText: true,
|
|
40
|
+
},
|
|
41
|
+
attributes: {
|
|
42
|
+
label: "Description",
|
|
43
|
+
help: "Enter a description of your project",
|
|
44
|
+
cols: 30,
|
|
45
|
+
rows: 5,
|
|
46
|
+
maxLength: 500,
|
|
47
|
+
minLength: 10,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
expect(() => textQuestions_1.TextAreaQuestionSchema.parse(validTextAreaQuestion)).not.toThrow();
|
|
51
|
+
});
|
|
52
|
+
it("should invalidate an invalid TextAreaQuestion", () => {
|
|
53
|
+
const invalidTextAreaQuestion = {
|
|
54
|
+
type: "textArea",
|
|
55
|
+
meta: {
|
|
56
|
+
schemaVersion: "1.0",
|
|
57
|
+
},
|
|
58
|
+
attributes: {
|
|
59
|
+
cols: "30", // Invalid type
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
expect(() => textQuestions_1.TextAreaQuestionSchema.parse(invalidTextAreaQuestion)).toThrow();
|
|
63
|
+
});
|
|
64
|
+
it("should validate a valid TextQuestion", () => {
|
|
65
|
+
const validTextQuestion = {
|
|
66
|
+
type: "text",
|
|
67
|
+
meta: {
|
|
68
|
+
schemaVersion: "1.0",
|
|
69
|
+
},
|
|
70
|
+
attributes: {
|
|
71
|
+
label: "Name",
|
|
72
|
+
help: "Enter your name",
|
|
73
|
+
maxLength: 100,
|
|
74
|
+
minLength: 1,
|
|
75
|
+
pattern: "^[a-zA-Z]+$",
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
expect(() => textQuestions_1.TextQuestionSchema.parse(validTextQuestion)).not.toThrow();
|
|
79
|
+
});
|
|
80
|
+
it("should invalidate an invalid TextQuestion", () => {
|
|
81
|
+
const invalidTextQuestion = {
|
|
82
|
+
type: "text",
|
|
83
|
+
meta: {
|
|
84
|
+
schemaVersion: "1.0",
|
|
85
|
+
},
|
|
86
|
+
attributes: {
|
|
87
|
+
maxLength: "100", // Invalid type
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
expect(() => textQuestions_1.TextQuestionSchema.parse(invalidTextQuestion)).toThrow();
|
|
91
|
+
});
|
|
92
|
+
it("should validate a valid URLQuestion", () => {
|
|
93
|
+
const validURLQuestion = {
|
|
94
|
+
type: "url",
|
|
95
|
+
meta: {
|
|
96
|
+
schemaVersion: "1.0",
|
|
97
|
+
},
|
|
98
|
+
attributes: {
|
|
99
|
+
label: "URL",
|
|
100
|
+
help: "Enter a URL",
|
|
101
|
+
maxLength: 200,
|
|
102
|
+
minLength: 10,
|
|
103
|
+
pattern: "https?://.+",
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
expect(() => textQuestions_1.URLQuestionSchema.parse(validURLQuestion)).not.toThrow();
|
|
107
|
+
});
|
|
108
|
+
it("should invalidate an invalid URLQuestion", () => {
|
|
109
|
+
const invalidURLQuestion = {
|
|
110
|
+
type: "url",
|
|
111
|
+
meta: {
|
|
112
|
+
schemaVersion: "1.0",
|
|
113
|
+
},
|
|
114
|
+
attributes: {
|
|
115
|
+
maxLength: "200", // Invalid type
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
expect(() => textQuestions_1.URLQuestionSchema.parse(invalidURLQuestion)).toThrow();
|
|
119
|
+
});
|
|
120
|
+
});
|