@projectcaluma/ember-testing 9.1.0 → 10.2.0-beta.2

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 (50) hide show
  1. package/CHANGELOG.md +994 -0
  2. package/addon/mirage-graphql/filters/answer.js +13 -0
  3. package/addon/mirage-graphql/filters/base.js +47 -20
  4. package/addon/mirage-graphql/filters/question.js +1 -3
  5. package/addon/mirage-graphql/filters/work-item.js +22 -2
  6. package/addon/mirage-graphql/handler.js +25 -7
  7. package/addon/mirage-graphql/index.js +24 -3
  8. package/addon/mirage-graphql/mocks/answer.js +8 -33
  9. package/addon/mirage-graphql/mocks/base.js +105 -42
  10. package/addon/mirage-graphql/mocks/form.js +25 -100
  11. package/addon/mirage-graphql/mocks/question.js +17 -119
  12. package/addon/mirage-graphql/mocks/work-item.js +105 -0
  13. package/addon/mirage-graphql/schema.graphql +0 -16
  14. package/addon/scenarios/distribution.js +315 -0
  15. package/addon-mirage-support/factories/answer.js +4 -2
  16. package/addon-mirage-support/factories/case.js +3 -2
  17. package/addon-mirage-support/factories/document.js +5 -2
  18. package/addon-mirage-support/factories/file.js +3 -2
  19. package/addon-mirage-support/factories/form.js +5 -2
  20. package/addon-mirage-support/factories/format-validator.js +5 -2
  21. package/addon-mirage-support/factories/option.js +4 -1
  22. package/addon-mirage-support/factories/question.js +6 -2
  23. package/addon-mirage-support/factories/task.js +6 -5
  24. package/addon-mirage-support/factories/work-item.js +3 -2
  25. package/addon-mirage-support/factories/workflow.js +9 -0
  26. package/addon-mirage-support/models/answer.js +3 -2
  27. package/addon-mirage-support/models/case.js +2 -1
  28. package/addon-mirage-support/models/document.js +1 -1
  29. package/addon-mirage-support/models/file.js +1 -1
  30. package/addon-mirage-support/models/form.js +2 -2
  31. package/addon-mirage-support/models/format-validator.js +1 -1
  32. package/addon-mirage-support/models/option.js +1 -1
  33. package/addon-mirage-support/models/question.js +5 -3
  34. package/addon-mirage-support/models/task.js +1 -1
  35. package/addon-mirage-support/models/work-item.js +3 -1
  36. package/addon-mirage-support/models/workflow.js +1 -1
  37. package/index.js +1 -1
  38. package/package.json +15 -13
  39. package/addon/mirage-graphql/mocks/case.js +0 -9
  40. package/addon/mirage-graphql/mocks/task.js +0 -55
  41. package/addon/mirage-graphql/resolvers/index.js +0 -16
  42. package/addon/mirage-graphql/serializers/answer.js +0 -14
  43. package/addon/mirage-graphql/serializers/base.js +0 -13
  44. package/addon/mirage-graphql/serializers/case.js +0 -11
  45. package/addon/mirage-graphql/serializers/document.js +0 -11
  46. package/addon/mirage-graphql/serializers/file.js +0 -12
  47. package/addon/mirage-graphql/serializers/form.js +0 -11
  48. package/addon/mirage-graphql/serializers/question.js +0 -14
  49. package/addon/mirage-graphql/serializers/task.js +0 -16
  50. 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,105 @@
1
+ import moment from "moment";
2
+
3
+ import {
4
+ register,
5
+ deserialize,
6
+ } from "@projectcaluma/ember-testing/mirage-graphql";
7
+ import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
8
+ import { createInquiry } from "@projectcaluma/ember-testing/scenarios/distribution";
9
+
10
+ export default class extends BaseMock {
11
+ @register("ResumeWorkItemPayload")
12
+ handleResumeWorkItem(_, { input }) {
13
+ return this.handleSavePayload.fn.call(this, _, {
14
+ input: { id: input.id, status: "READY" },
15
+ });
16
+ }
17
+
18
+ @register("SuspendWorkItemPayload")
19
+ handleSuspendWorkItem(_, { input }) {
20
+ return this.handleSavePayload.fn.call(this, _, {
21
+ input: { id: input.id, status: "SUSPENDED" },
22
+ });
23
+ }
24
+
25
+ @register("CompleteWorkItemPayload")
26
+ handleCompleteWorkItem(_, { input }) {
27
+ const { id } = deserialize(input);
28
+
29
+ const workItem = this.collection.find(id);
30
+
31
+ const taskId = workItem.taskId;
32
+ const caseId = workItem.caseId;
33
+
34
+ /**
35
+ * Disclaimer: this is a static configuration of a pre-configured workflow
36
+ * in the distribution scenario and should most likely be handled properly
37
+ * like the backend does. However, this small requirement does not justify a
38
+ * complex implementation of backend logic which is why we keep this static
39
+ * for now.
40
+ */
41
+ if (["adjust-inquiry-answer", "compose-inquiry-answer"].includes(taskId)) {
42
+ this.server.create("work-item", {
43
+ caseId,
44
+ status: "READY",
45
+ taskId: "confirm-inquiry-answer",
46
+ });
47
+ this.server.create("work-item", {
48
+ caseId,
49
+ status: "READY",
50
+ taskId: "revise-inquiry-answer",
51
+ });
52
+ } else if (taskId === "confirm-inquiry-answer") {
53
+ this.collection
54
+ .findBy({ caseId, taskId: "revise-inquiry-answer" })
55
+ .update({ status: "CANCELED" });
56
+ this.collection
57
+ .findBy({ childCaseId: caseId })
58
+ .update({ status: "COMPLETED" });
59
+ this.schema.cases.find(caseId).update({ status: "COMPLETED" });
60
+ } else if (taskId === "revise-inquiry-answer") {
61
+ this.collection
62
+ .findBy({ caseId, taskId: "confirm-inquiry-answer" })
63
+ .update({ status: "CANCELED" });
64
+ this.server.create("work-item", {
65
+ caseId,
66
+ status: "READY",
67
+ taskId: "adjust-inquiry-answer",
68
+ });
69
+ } else if (taskId === "create-inquiry") {
70
+ const { addressed_groups: groups } = JSON.parse(input.context);
71
+
72
+ groups.forEach((group) => {
73
+ createInquiry(
74
+ this.server,
75
+ workItem.case,
76
+ {
77
+ to: { id: group },
78
+ from: { id: workItem.addressedGroups[0] },
79
+ remark: "",
80
+ deadline: moment().add(30, "days").toDate(),
81
+ },
82
+ {
83
+ createdAt: new Date(),
84
+ }
85
+ );
86
+
87
+ this.server.create("work-item", {
88
+ taskId: "create-inquiry",
89
+ status: "READY",
90
+ addressedGroups: [group],
91
+ });
92
+ });
93
+
94
+ this.server.create("work-item", {
95
+ taskId: "create-inquiry",
96
+ status: "READY",
97
+ addressedGroups: workItem.addressedGroups,
98
+ });
99
+ }
100
+
101
+ return this.handleSavePayload.fn.call(this, _, {
102
+ input: { id: input.id, status: "COMPLETED" },
103
+ });
104
+ }
105
+ }
@@ -361,11 +361,6 @@ type Case implements Node {
361
361
  """
362
362
  id: ID!
363
363
 
364
- """
365
- Stores a path to the given object
366
- """
367
- path: [String]!
368
-
369
364
  """
370
365
  Time when case has either been canceled or completed
371
366
  """
@@ -1163,11 +1158,6 @@ type Document implements Node {
1163
1158
  The ID of the object.
1164
1159
  """
1165
1160
  id: ID!
1166
-
1167
- """
1168
- Stores a path to the given object
1169
- """
1170
- path: [String]!
1171
1161
  form: Form!
1172
1162
 
1173
1163
  """
@@ -4078,7 +4068,6 @@ enum SortableDocumentAttributes {
4078
4068
  CREATED_BY_GROUP
4079
4069
  MODIFIED_BY_USER
4080
4070
  MODIFIED_BY_GROUP
4081
- PATH
4082
4071
  FORM
4083
4072
  SOURCE
4084
4073
  }
@@ -4991,11 +4980,6 @@ type WorkItem implements Node {
4991
4980
  """
4992
4981
  id: ID!
4993
4982
 
4994
- """
4995
- Stores a path to the given object
4996
- """
4997
- path: [String]!
4998
-
4999
4983
  """
5000
4984
  Will be set from Task, if not provided.
5001
4985
  """