@projectcaluma/ember-testing 9.0.0 → 10.2.0-beta.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.
Files changed (44) hide show
  1. package/addon/mirage-graphql/filters/answer.js +13 -0
  2. package/addon/mirage-graphql/filters/base.js +47 -20
  3. package/addon/mirage-graphql/filters/question.js +1 -3
  4. package/addon/mirage-graphql/filters/work-item.js +27 -0
  5. package/addon/mirage-graphql/handler.js +25 -7
  6. package/addon/mirage-graphql/index.js +24 -3
  7. package/addon/mirage-graphql/mocks/answer.js +8 -33
  8. package/addon/mirage-graphql/mocks/base.js +119 -47
  9. package/addon/mirage-graphql/mocks/form.js +25 -100
  10. package/addon/mirage-graphql/mocks/question.js +17 -119
  11. package/addon/mirage-graphql/mocks/work-item.js +72 -0
  12. package/addon/mirage-graphql/schema.graphql +121 -8
  13. package/addon/scenarios/distribution.js +287 -0
  14. package/addon-mirage-support/factories/answer.js +2 -0
  15. package/addon-mirage-support/factories/case.js +6 -5
  16. package/addon-mirage-support/factories/document.js +4 -1
  17. package/addon-mirage-support/factories/file.js +6 -5
  18. package/addon-mirage-support/factories/form.js +3 -0
  19. package/addon-mirage-support/factories/format-validator.js +3 -0
  20. package/addon-mirage-support/factories/option.js +3 -0
  21. package/addon-mirage-support/factories/question.js +19 -0
  22. package/addon-mirage-support/factories/task.js +6 -5
  23. package/addon-mirage-support/factories/work-item.js +7 -5
  24. package/addon-mirage-support/factories/workflow.js +9 -0
  25. package/addon-mirage-support/models/answer.js +3 -2
  26. package/addon-mirage-support/models/case.js +1 -0
  27. package/addon-mirage-support/models/document.js +1 -0
  28. package/addon-mirage-support/models/form.js +1 -1
  29. package/addon-mirage-support/models/question.js +4 -2
  30. package/addon-mirage-support/models/work-item.js +2 -0
  31. package/index.js +1 -1
  32. package/package.json +19 -15
  33. package/addon/mirage-graphql/mocks/case.js +0 -9
  34. package/addon/mirage-graphql/mocks/task.js +0 -55
  35. package/addon/mirage-graphql/resolvers/index.js +0 -16
  36. package/addon/mirage-graphql/serializers/answer.js +0 -14
  37. package/addon/mirage-graphql/serializers/base.js +0 -13
  38. package/addon/mirage-graphql/serializers/case.js +0 -11
  39. package/addon/mirage-graphql/serializers/document.js +0 -11
  40. package/addon/mirage-graphql/serializers/file.js +0 -12
  41. package/addon/mirage-graphql/serializers/form.js +0 -11
  42. package/addon/mirage-graphql/serializers/question.js +0 -14
  43. package/addon/mirage-graphql/serializers/task.js +0 -16
  44. package/addon/mirage-graphql/serializers/work-item.js +0 -11
@@ -1,115 +1,40 @@
1
- import { MockList } from "graphql-tools";
2
-
3
- import {
4
- Serializer,
5
- Filter,
6
- register,
7
- } from "@projectcaluma/ember-testing/mirage-graphql";
1
+ import { register } from "@projectcaluma/ember-testing/mirage-graphql";
8
2
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
9
3
 
10
- const questionSerializer = new Serializer("Question");
11
- const questionFilter = new Filter("Question");
12
-
13
4
  export default class extends BaseMock {
14
5
  @register("ReorderFormQuestionsPayload")
15
- handleReorderFormQuestions(
16
- root,
17
- { input: { form: slug, questions: questionSlugs, clientMutationId } }
18
- ) {
19
- const form = this.filter.find(this.collection, { slug });
20
-
21
- const questions = questionSlugs.map((slug) => {
22
- return questionFilter.find(this.db.questions, { slug });
23
- });
24
-
25
- const res = this.collection.update(form.id, {
26
- questionIds: questions.map(({ id }) => id),
27
- });
28
-
29
- return {
30
- form: {
31
- ...this.serializer.serialize(res),
32
- questions: {
33
- edges: () =>
34
- new MockList(questions.length, () => ({
35
- node: (r, v, _, meta) =>
36
- questionSerializer.serialize(questions[meta.path.prev.key]),
37
- })),
38
- },
6
+ handleReorderFormQuestions(_, { input }) {
7
+ return this.handleSavePayload.fn.call(this, _, {
8
+ input: {
9
+ id: input.form,
10
+ questionIds: input.questions,
39
11
  },
40
- clientMutationId,
41
- };
12
+ });
42
13
  }
43
14
 
44
15
  @register("AddFormQuestionPayload")
45
- handleAddFormQuestion(
46
- root,
47
- { input: { form: slug, question: questionSlug, clientMutationId } }
48
- ) {
49
- const form = this.filter.find(this.collection, { slug });
50
-
51
- const question = questionFilter.find(this.db.questions, {
52
- slug: questionSlug,
53
- });
54
-
55
- this.db.questions.update(question.id, {
56
- formIds: [...(question.formIds || []), form.id],
57
- });
58
-
59
- const res = this.collection.update(form.id, {
60
- questionIds: [...(form.questionIds || []), question.id],
61
- });
62
-
63
- const questions = res.questionIds.map((id) => this.db.questions.find(id));
64
-
65
- return {
66
- form: {
67
- ...this.serializer.serialize(res),
68
- questions: {
69
- edges: () =>
70
- new MockList(questions.length, () => ({
71
- node: (r, v, _, meta) =>
72
- questionSerializer.serialize(questions[meta.path.prev.key]),
73
- })),
74
- },
16
+ handleAddFormQuestion(_, { input }) {
17
+ const form = this.schema.forms.find(input.form);
18
+
19
+ return this.handleSavePayload.fn.call(this, _, {
20
+ input: {
21
+ id: form.id,
22
+ questionIds: [...(form.questionIds || []), input.question],
23
+ questions: undefined,
75
24
  },
76
- clientMutationId,
77
- };
25
+ });
78
26
  }
79
27
 
80
28
  @register("RemoveFormQuestionPayload")
81
- handleRemoveFormQuestion(
82
- root,
83
- { input: { form: slug, question: questionSlug, clientMutationId } }
84
- ) {
85
- const form = this.filter.find(this.collection, { slug });
86
-
87
- const question = questionFilter.find(this.db.questions, {
88
- slug: questionSlug,
89
- });
90
-
91
- this.db.questions.update(question.id, {
92
- formIds: question.formIds.filter((id) => id !== form.id),
93
- });
94
-
95
- const res = this.collection.update(form.id, {
96
- questionIds: form.questionIds.filter((id) => id !== question.id),
97
- });
98
-
99
- const questions = res.questionIds.map((id) => this.db.questions.find(id));
100
-
101
- return {
102
- form: {
103
- ...this.serializer.serialize(res),
104
- questions: {
105
- edges: () =>
106
- new MockList(questions.length, () => ({
107
- node: (r, v, _, meta) =>
108
- questionSerializer.serialize(questions[meta.path.prev.key]),
109
- })),
110
- },
29
+ handleRemoveFormQuestion(_, { input }) {
30
+ const form = this.schema.forms.find(input.form);
31
+
32
+ return this.handleSavePayload.fn.call(this, _, {
33
+ input: {
34
+ id: form.id,
35
+ questionIds: form.questionIds.filter((id) => id !== input.question),
36
+ questions: undefined,
111
37
  },
112
- clientMutationId,
113
- };
38
+ });
114
39
  }
115
40
  }
@@ -1,87 +1,7 @@
1
- import { classify } from "@ember/string";
2
- import { MockList } from "graphql-tools";
3
-
4
- import {
5
- Filter,
6
- Serializer,
7
- register,
8
- } from "@projectcaluma/ember-testing/mirage-graphql";
1
+ import { register } from "@projectcaluma/ember-testing/mirage-graphql";
9
2
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
10
3
 
11
- const optionFilter = new Filter("Option");
12
- const optionSerializer = new Serializer("Option");
13
-
14
4
  export default class extends BaseMock {
15
- @register("Question")
16
- handleQuestion(root, ...args) {
17
- const questionId =
18
- root.questionId || (root.node && root.node(root, ...args).id);
19
- let __typename = root.__typename;
20
-
21
- if (questionId) {
22
- __typename = `${classify(
23
- this.collection.findBy({ id: questionId }).type.toLowerCase()
24
- )}Question`;
25
- }
26
-
27
- return { __typename };
28
- }
29
-
30
- handleInterfaceType(root, vars, _, meta) {
31
- return this.handle.fn.call(
32
- this,
33
- root,
34
- { ...vars, id: root.questionId },
35
- _,
36
- meta
37
- );
38
- }
39
-
40
- @register("TextQuestion")
41
- handleTextQuestion(...args) {
42
- return this.handleInterfaceType(...args);
43
- }
44
-
45
- @register("TextareaQuestion")
46
- handleTextareaQuestion(...args) {
47
- return this.handleInterfaceType(...args);
48
- }
49
-
50
- @register("IntegerQuestion")
51
- handleIntegerQuestion(...args) {
52
- return this.handleInterfaceType(...args);
53
- }
54
-
55
- @register("FloatQuestion")
56
- handleFloatQuestion(...args) {
57
- return this.handleInterfaceType(...args);
58
- }
59
-
60
- @register("MultipleChoiceQuestion")
61
- handleMultipleChoiceQuestion(...args) {
62
- return this.handleInterfaceType(...args);
63
- }
64
-
65
- @register("ChoiceQuestion")
66
- handleChoiceQuestion(...args) {
67
- return this.handleInterfaceType(...args);
68
- }
69
-
70
- @register("FileQuestion")
71
- handleFileQuestion(...args) {
72
- return this.handleInterfaceType(...args);
73
- }
74
-
75
- @register("StaticQuestion")
76
- handleStaticQuestion(...args) {
77
- return this.handleInterfaceType(...args);
78
- }
79
-
80
- @register("DateQuestion")
81
- handleDateQuestion(...args) {
82
- return this.handleInterfaceType(...args);
83
- }
84
-
85
5
  @register("SaveTextQuestionPayload")
86
6
  handleSaveTextQuestion(_, { input }) {
87
7
  return this.handleSavePayload.fn.call(this, _, {
@@ -119,50 +39,26 @@ export default class extends BaseMock {
119
39
 
120
40
  @register("SaveChoiceQuestionPayload")
121
41
  handleSaveChoiceQuestion(_, { input }) {
122
- const options = input.options.map((slug) =>
123
- optionFilter.find(this.db.options, { slug })
124
- );
125
- const optionIds = options.map(({ id }) => String(id));
126
-
127
- const res = this.handleSavePayload.fn.call(this, _, {
128
- input: { ...input, options, optionIds, type: "CHOICE" },
129
- });
130
-
131
- Object.assign(res.question, {
132
- options: {
133
- edges: () =>
134
- new MockList(options.length, () => ({
135
- node: (r, v, _, meta) =>
136
- optionSerializer.serialize(options[meta.path.prev.key]),
137
- })),
42
+ return this.handleSavePayload.fn.call(this, _, {
43
+ input: {
44
+ ...input,
45
+ optionIds: input.options,
46
+ options: undefined,
47
+ type: "CHOICE",
138
48
  },
139
49
  });
140
-
141
- return res;
142
50
  }
143
51
 
144
52
  @register("SaveMultipleChoiceQuestionPayload")
145
53
  handleSaveMultipleChoiceQuestion(_, { input }) {
146
- const options = input.options.map((slug) =>
147
- optionFilter.find(this.db.options, { slug })
148
- );
149
- const optionIds = options.map(({ id }) => String(id));
150
-
151
- const res = this.handleSavePayload.fn.call(this, _, {
152
- input: { ...input, options, optionIds, type: "MULTIPLE_CHOICE" },
153
- });
154
-
155
- Object.assign(res.question, {
156
- options: {
157
- edges: () =>
158
- new MockList(options.length, () => ({
159
- node: (r, v, _, meta) =>
160
- optionSerializer.serialize(options[meta.path.prev.key]),
161
- })),
54
+ return this.handleSavePayload.fn.call(this, _, {
55
+ input: {
56
+ ...input,
57
+ optionIds: input.options,
58
+ options: undefined,
59
+ type: "MULTIPLE_CHOICE",
162
60
  },
163
61
  });
164
-
165
- return res;
166
62
  }
167
63
 
168
64
  @register("SaveTableQuestionPayload")
@@ -170,7 +66,8 @@ export default class extends BaseMock {
170
66
  return this.handleSavePayload.fn.call(this, _, {
171
67
  input: {
172
68
  ...input,
173
- ...(input.rowForm ? { rowForm: { slug: input.rowForm } } : {}),
69
+ rowFormId: input.rowForm,
70
+ rowForm: undefined,
174
71
  type: "TABLE",
175
72
  },
176
73
  });
@@ -181,7 +78,8 @@ export default class extends BaseMock {
181
78
  return this.handleSavePayload.fn.call(this, _, {
182
79
  input: {
183
80
  ...input,
184
- ...(input.subForm ? { subForm: { slug: input.subForm } } : {}),
81
+ subFormId: input.subForm,
82
+ subForm: undefined,
185
83
  type: "FORM",
186
84
  },
187
85
  });
@@ -0,0 +1,72 @@
1
+ import {
2
+ register,
3
+ deserialize,
4
+ } from "@projectcaluma/ember-testing/mirage-graphql";
5
+ import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
6
+
7
+ export default class extends BaseMock {
8
+ @register("ResumeWorkItemPayload")
9
+ handleResumeWorkItem(_, { input }) {
10
+ return this.handleSavePayload.fn.call(this, _, {
11
+ input: { id: input.id, status: "READY" },
12
+ });
13
+ }
14
+
15
+ @register("SuspendWorkItemPayload")
16
+ handleSuspendWorkItem(_, { input }) {
17
+ return this.handleSavePayload.fn.call(this, _, {
18
+ input: { id: input.id, status: "SUSPENDED" },
19
+ });
20
+ }
21
+
22
+ @register("CompleteWorkItemPayload")
23
+ handleCompleteWorkItem(_, { input }) {
24
+ const { id } = deserialize(input);
25
+
26
+ const workItem = this.collection.find(id);
27
+
28
+ const taskId = workItem.taskId;
29
+ const caseId = workItem.caseId;
30
+
31
+ /**
32
+ * Disclaimer: this is a static configuration of a pre-configured workflow
33
+ * in the distribution scenario and should most likely be handled properly
34
+ * like the backend does. However, this small requirement does not justify a
35
+ * complex implementation of backend logic which is why we keep this static
36
+ * for now.
37
+ */
38
+ if (["adjust-inquiry-answer", "compose-inquiry-answer"].includes(taskId)) {
39
+ this.server.create("work-item", {
40
+ caseId,
41
+ status: "READY",
42
+ taskId: "confirm-inquiry-answer",
43
+ });
44
+ this.server.create("work-item", {
45
+ caseId,
46
+ status: "READY",
47
+ taskId: "revise-inquiry-answer",
48
+ });
49
+ } else if (taskId === "confirm-inquiry-answer") {
50
+ this.collection
51
+ .findBy({ caseId, taskId: "revise-inquiry-answer" })
52
+ .update({ status: "CANCELED" });
53
+ this.collection
54
+ .findBy({ childCaseId: caseId })
55
+ .update({ status: "COMPLETED" });
56
+ this.schema.cases.find(caseId).update({ status: "COMPLETED" });
57
+ } else if (taskId === "revise-inquiry-answer") {
58
+ this.collection
59
+ .findBy({ caseId, taskId: "confirm-inquiry-answer" })
60
+ .update({ status: "CANCELED" });
61
+ this.server.create("work-item", {
62
+ caseId,
63
+ status: "READY",
64
+ taskId: "adjust-inquiry-answer",
65
+ });
66
+ }
67
+
68
+ return this.handleSavePayload.fn.call(this, _, {
69
+ input: { id: input.id, status: "COMPLETED" },
70
+ });
71
+ }
72
+ }
@@ -1,3 +1,67 @@
1
+ type ActionButtonQuestion implements Question & Node {
2
+ createdAt: DateTime!
3
+ modifiedAt: DateTime!
4
+ createdByUser: String
5
+ createdByGroup: String
6
+ modifiedByUser: String
7
+ modifiedByGroup: String
8
+ slug: String!
9
+ label: String!
10
+
11
+ """
12
+ Required expression is only evaluated when question is not hidden.
13
+ """
14
+ isRequired: QuestionJexl!
15
+ isHidden: QuestionJexl!
16
+ isArchived: Boolean!
17
+ infoText: String
18
+ meta: GenericScalar!
19
+ source: Question
20
+ forms(
21
+ before: String
22
+ after: String
23
+ first: Int
24
+ last: Int
25
+ metaValue: [JSONValueFilterType]
26
+
27
+ """
28
+ FormOrdering
29
+ """
30
+ orderBy: [FormOrdering]
31
+ slug: String
32
+ name: String
33
+ description: String
34
+ isPublished: Boolean
35
+ isArchived: Boolean
36
+ questions: [String]
37
+ createdByUser: String
38
+ createdByGroup: String
39
+ modifiedByUser: String
40
+ modifiedByGroup: String
41
+
42
+ """
43
+ Only return entries created after the given DateTime (Exclusive)
44
+ """
45
+ createdBefore: DateTime
46
+
47
+ """
48
+ Only return entries created at or before the given DateTime (Inclusive)
49
+ """
50
+ createdAfter: DateTime
51
+ metaHasKey: String
52
+ search: String
53
+ slugs: [String]
54
+ ): FormConnection
55
+
56
+ """
57
+ The ID of the object.
58
+ """
59
+ id: ID!
60
+ action: ButtonAction!
61
+ color: ButtonColor!
62
+ validateOnEnter: Boolean!
63
+ }
64
+
1
65
  input AddFormQuestionInput {
2
66
  form: ID!
3
67
  question: ID!
@@ -175,6 +239,23 @@ enum AscDesc {
175
239
  DESC
176
240
  }
177
241
 
242
+ """
243
+ An enumeration.
244
+ """
245
+ enum ButtonAction {
246
+ COMPLETE
247
+ SKIP
248
+ }
249
+
250
+ """
251
+ An enumeration.
252
+ """
253
+ enum ButtonColor {
254
+ PRIMARY
255
+ SECONDARY
256
+ DEFAULT
257
+ }
258
+
178
259
  type CalculatedFloatQuestion implements Question & Node {
179
260
  createdAt: DateTime!
180
261
  modifiedAt: DateTime!
@@ -1282,7 +1363,7 @@ type DocumentValidityEdge {
1282
1363
  cursor: String!
1283
1364
  }
1284
1365
 
1285
- type DynamicChoiceQuestion implements Question & Node {
1366
+ type DynamicChoiceQuestion implements Question & DynamicQuestion & Node {
1286
1367
  createdAt: DateTime!
1287
1368
  modifiedAt: DateTime!
1288
1369
  createdByUser: String
@@ -1350,7 +1431,7 @@ type DynamicChoiceQuestion implements Question & Node {
1350
1431
  id: ID!
1351
1432
  }
1352
1433
 
1353
- type DynamicMultipleChoiceQuestion implements Question & Node {
1434
+ type DynamicMultipleChoiceQuestion implements Question & DynamicQuestion & Node {
1354
1435
  createdAt: DateTime!
1355
1436
  modifiedAt: DateTime!
1356
1437
  createdByUser: String
@@ -1433,7 +1514,7 @@ type DynamicOption implements Node {
1433
1514
  slug: String!
1434
1515
  label: String!
1435
1516
  document: Document!
1436
- question: CalculatedFloatQuestion!
1517
+ question: DynamicQuestion!
1437
1518
  }
1438
1519
 
1439
1520
  type DynamicOptionConnection {
@@ -1470,6 +1551,16 @@ input DynamicOptionFilterSetType {
1470
1551
  invert: Boolean
1471
1552
  }
1472
1553
 
1554
+ interface DynamicQuestion {
1555
+ options(
1556
+ before: String
1557
+ after: String
1558
+ first: Int
1559
+ last: Int
1560
+ ): DataSourceDataConnection
1561
+ dataSource: String!
1562
+ }
1563
+
1473
1564
  type File implements Node {
1474
1565
  createdAt: DateTime!
1475
1566
  modifiedAt: DateTime!
@@ -2336,6 +2427,9 @@ type Mutation {
2336
2427
  saveCalculatedFloatQuestion(
2337
2428
  input: SaveCalculatedFloatQuestionInput!
2338
2429
  ): SaveCalculatedFloatQuestionPayload
2430
+ saveActionButtonQuestion(
2431
+ input: SaveActionButtonQuestionInput!
2432
+ ): SaveActionButtonQuestionPayload
2339
2433
  copyDocument(input: CopyDocumentInput!): CopyDocumentPayload
2340
2434
  saveDocument(input: SaveDocumentInput!): SaveDocumentPayload
2341
2435
  saveDocumentStringAnswer(
@@ -2872,11 +2966,12 @@ type Query {
2872
2966
  first: Int
2873
2967
  last: Int
2874
2968
  ): DocumentValidityConnection
2875
-
2876
- """
2877
- The ID of the object
2878
- """
2879
- node(id: ID!): Node
2969
+ node(
2970
+ """
2971
+ The ID of the object
2972
+ """
2973
+ id: ID!
2974
+ ): Node
2880
2975
  _debug: DjangoDebug
2881
2976
  }
2882
2977
 
@@ -3180,6 +3275,24 @@ type ResumeWorkItemPayload {
3180
3275
  clientMutationId: String
3181
3276
  }
3182
3277
 
3278
+ input SaveActionButtonQuestionInput {
3279
+ label: String!
3280
+ slug: String!
3281
+ infoText: String
3282
+ isHidden: QuestionJexl
3283
+ meta: JSONString
3284
+ isArchived: Boolean
3285
+ action: ButtonAction!
3286
+ color: ButtonColor!
3287
+ validateOnEnter: Boolean!
3288
+ clientMutationId: String
3289
+ }
3290
+
3291
+ type SaveActionButtonQuestionPayload {
3292
+ question: Question
3293
+ clientMutationId: String
3294
+ }
3295
+
3183
3296
  input SaveCalculatedFloatQuestionInput {
3184
3297
  slug: String!
3185
3298
  label: String!