@projectcaluma/ember-testing 10.1.0 → 11.0.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 (37) hide show
  1. package/CHANGELOG.md +1016 -0
  2. package/addon/mirage-graphql/filters/answer.js +6 -8
  3. package/addon/mirage-graphql/filters/base.js +12 -12
  4. package/addon/mirage-graphql/filters/question.js +1 -3
  5. package/addon/mirage-graphql/filters/work-item.js +9 -7
  6. package/addon/mirage-graphql/handler.js +1 -1
  7. package/addon/mirage-graphql/mocks/answer.js +6 -36
  8. package/addon/mirage-graphql/mocks/base.js +29 -25
  9. package/addon/mirage-graphql/mocks/form.js +25 -99
  10. package/addon/mirage-graphql/mocks/question.js +17 -47
  11. package/addon/mirage-graphql/mocks/work-item.js +105 -0
  12. package/addon/mirage-graphql/schema.graphql +0 -16
  13. package/addon/scenarios/distribution.js +163 -48
  14. package/addon-mirage-support/factories/answer.js +4 -10
  15. package/addon-mirage-support/factories/case.js +2 -2
  16. package/addon-mirage-support/factories/document.js +2 -2
  17. package/addon-mirage-support/factories/file.js +2 -2
  18. package/addon-mirage-support/factories/form.js +2 -2
  19. package/addon-mirage-support/factories/format-validator.js +2 -2
  20. package/addon-mirage-support/factories/option.js +1 -1
  21. package/addon-mirage-support/factories/question.js +2 -2
  22. package/addon-mirage-support/factories/task.js +2 -2
  23. package/addon-mirage-support/factories/work-item.js +2 -2
  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 +2 -1
  27. package/addon-mirage-support/models/document.js +1 -1
  28. package/addon-mirage-support/models/file.js +1 -1
  29. package/addon-mirage-support/models/form.js +2 -2
  30. package/addon-mirage-support/models/format-validator.js +1 -1
  31. package/addon-mirage-support/models/option.js +1 -1
  32. package/addon-mirage-support/models/question.js +5 -2
  33. package/addon-mirage-support/models/task.js +1 -1
  34. package/addon-mirage-support/models/work-item.js +1 -1
  35. package/addon-mirage-support/models/workflow.js +1 -1
  36. package/blueprints/@projectcaluma/ember-testing/index.js +1 -4
  37. package/package.json +12 -12
@@ -1,15 +1,13 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
3
  export default class extends BaseFilter {
4
- questions(records, value) {
5
- const questionIds = this.db.questions
6
- .filter(({ slug }) => value.includes(slug))
7
- .map(({ id }) => id);
8
-
9
- return records.filter(({ questionId }) => questionIds.includes(questionId));
4
+ questions(records, value, { invert = false }) {
5
+ return records.filter(
6
+ (record) => invert !== value.includes(record.questionId)
7
+ );
10
8
  }
11
9
 
12
- question(records, value) {
13
- return this.questions(records, [value]);
10
+ question(records, value, { invert = false }) {
11
+ return this.questions(records, [value], { invert });
14
12
  }
15
13
  }
@@ -1,25 +1,25 @@
1
1
  import { camelize } from "@ember/string";
2
2
 
3
3
  export default class {
4
- constructor(type, collection, db) {
4
+ constructor(type) {
5
5
  this.type = type;
6
- this.collection = collection;
7
- this.db = db;
8
6
  }
9
7
 
10
8
  _getFilterFns(rawFilters) {
11
9
  const filters = Array.isArray(rawFilters)
12
10
  ? // new format
13
- rawFilters.map((filter) => {
14
- const entries = Object.entries(filter);
15
- const key = entries[0][0];
16
- const value = entries[0][1];
17
- const options = entries
18
- .slice(1)
19
- .reduce((opts, [k, v]) => ({ ...opts, [k]: v }), {});
11
+ rawFilters
12
+ .filter((filter) => Object.keys(filter).length !== 0) // filter out empty filters
13
+ .map((filter) => {
14
+ const entries = Object.entries(filter);
15
+ const key = entries[0][0];
16
+ const value = entries[0][1];
17
+ const options = entries
18
+ .slice(1)
19
+ .reduce((opts, [k, v]) => ({ ...opts, [k]: v }), {});
20
20
 
21
- return { key, value, options };
22
- })
21
+ return { key, value, options };
22
+ })
23
23
  : // old format
24
24
  Object.entries(rawFilters).map(([key, value]) => ({
25
25
  key,
@@ -12,10 +12,8 @@ export default class extends BaseFilter {
12
12
  }
13
13
 
14
14
  excludeForms(records, value) {
15
- const forms = this.db.forms.filter(({ slug }) => value.includes(slug));
16
-
17
15
  return records.filter(
18
- ({ formIds }) => !forms.some(({ id }) => (formIds || []).includes(id))
16
+ ({ formIds }) => !value.some((id) => (formIds || []).includes(id))
19
17
  );
20
18
  }
21
19
  }
@@ -1,25 +1,27 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
3
  export default class extends BaseFilter {
4
- status(records, value) {
5
- return records.filter(({ status }) => status === value);
4
+ status(records, value, { invert = false }) {
5
+ return records.filter(({ status }) => invert !== (status === value));
6
6
  }
7
7
 
8
- task(records, value) {
9
- const task = this.db.tasks.findBy({ slug: value });
8
+ tasks(records, value, { invert = false }) {
9
+ return records.filter((record) => invert !== value.includes(record.taskId));
10
+ }
10
11
 
11
- return records.filter((record) => record.taskId === task?.id);
12
+ task(records, value, { invert = false }) {
13
+ return this.tasks(records, [value], { invert });
12
14
  }
13
15
 
14
16
  controllingGroups(records, value, { invert = false }) {
15
17
  return records.filter((record) =>
16
- value.every((g) => invert !== record.controllingGroups.includes(g))
18
+ value.every((g) => invert !== record.controllingGroups?.includes(g))
17
19
  );
18
20
  }
19
21
 
20
22
  addressedGroups(records, value, { invert = false }) {
21
23
  return records.filter((record) =>
22
- value.every((g) => invert !== record.addressedGroups.includes(g))
24
+ value.every((g) => invert !== record.addressedGroups?.includes(g))
23
25
  );
24
26
  }
25
27
  }
@@ -14,7 +14,7 @@ export default function (server) {
14
14
  return function ({ db }, request) {
15
15
  const mocks = db._collections.reduce((m, { name }) => {
16
16
  const cls = classify(singularize(name));
17
- const mock = new Mock(cls, db[name], db, server);
17
+ const mock = new Mock(cls, server);
18
18
 
19
19
  return { ...m, ...mock.getHandlers() };
20
20
  }, {});
@@ -1,48 +1,24 @@
1
- import moment from "moment";
1
+ import { DateTime } from "luxon";
2
2
 
3
- import {
4
- register,
5
- deserialize,
6
- } from "@projectcaluma/ember-testing/mirage-graphql";
3
+ import { register } from "@projectcaluma/ember-testing/mirage-graphql";
7
4
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
8
5
 
9
6
  export default class extends BaseMock {
10
7
  _handleSaveDocumentAnswer(
11
8
  _,
12
- {
13
- question: questionSlug,
14
- document: documentId,
15
- clientMutationId,
16
- value,
17
- type,
18
- }
9
+ { question: questionId, document: documentId, value, type }
19
10
  ) {
20
- const questionId = this.db.questions.findBy({ slug: questionSlug }).id;
21
-
22
11
  const answer = this.collection.findBy({ questionId, documentId });
23
12
 
24
- const res = this.handleSavePayload.fn.call(this, _, {
13
+ return this.handleSavePayload.fn.call(this, _, {
25
14
  input: {
26
- id: answer && answer.id,
15
+ id: answer?.id,
27
16
  type,
28
17
  value,
29
18
  documentId,
30
19
  questionId,
31
- clientMutationId,
32
20
  },
33
21
  });
34
-
35
- // Default answers don't have a document.
36
- if (res.answer.documentId) {
37
- const doc = this.db.documents.findBy({ id: res.answer.documentId });
38
-
39
- const { id } = deserialize(res.answer);
40
- this.db.documents.update(doc.id, {
41
- answerIds: [...new Set([...(doc.answerIds || []), id])],
42
- });
43
- }
44
-
45
- return res;
46
22
  }
47
23
 
48
24
  @register("SaveDocumentStringAnswerPayload")
@@ -98,13 +74,7 @@ export default class extends BaseMock {
98
74
  @register("SaveDefaultDateAnswerPayload")
99
75
  handleSaveDateAnswer(_, { input }) {
100
76
  const date = input.value;
101
- const value = date
102
- ? moment({
103
- day: date.getUTCDate(),
104
- month: date.getUTCMonth(),
105
- year: date.getUTCFullYear(),
106
- }).format(moment.HTML5_FMT.DATE)
107
- : null;
77
+ const value = date ? DateTime.fromJSDate(date).toISODate() : null;
108
78
 
109
79
  return this._handleSaveDocumentAnswer(_, {
110
80
  ...input,
@@ -1,5 +1,6 @@
1
1
  import { camelize, dasherize, classify } from "@ember/string";
2
- import { singularize } from "ember-inflector";
2
+ import { faker } from "@faker-js/faker";
3
+ import { singularize, pluralize } from "ember-inflector";
3
4
  import { MockList } from "graphql-tools";
4
5
 
5
6
  import {
@@ -50,13 +51,16 @@ export const TYPE_MAPPING = {
50
51
  };
51
52
 
52
53
  export default class {
53
- constructor(type, collection, db, server, ...args) {
54
+ constructor(type, server) {
54
55
  this.type = type;
55
- this.collection = collection;
56
- this.db = db;
57
56
  this.server = server;
57
+ this.schema = server.schema;
58
58
 
59
- this.filter = new Filter(type, collection, db, server, ...args);
59
+ this.filter = new Filter(type);
60
+ }
61
+
62
+ get collection() {
63
+ return this.schema[pluralize(camelize(this.type))];
60
64
  }
61
65
 
62
66
  getHandlers() {
@@ -110,17 +114,22 @@ export default class {
110
114
 
111
115
  @register("{type}Connection")
112
116
  handleConnection(root, vars, _, { fieldName }) {
113
- let records = this.filter.filter(this.collection, deserialize(vars));
117
+ let records = this.filter.filter(
118
+ this.collection.all().models,
119
+ deserialize(vars)
120
+ );
114
121
 
115
122
  const relKey = `${singularize(fieldName)}Ids`;
116
123
  if (root && Object.prototype.hasOwnProperty.call(root, relKey)) {
117
124
  const ids = root[relKey];
118
- records = records.filter(({ id }) => ids && ids.includes(id));
125
+ records = records
126
+ .filter(({ id }) => ids && ids.includes(id))
127
+ .sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
119
128
  }
120
129
 
121
130
  // add base64 encoded index as cursor to records
122
131
  records = records.map((record, index) => ({
123
- ...record,
132
+ ...record.toJSON(),
124
133
  _cursor: btoa(index),
125
134
  }));
126
135
 
@@ -174,18 +183,19 @@ export default class {
174
183
  vars = { id: root[relKey] };
175
184
  }
176
185
 
177
- const record = this.filter.find(this.collection, deserialize(vars));
186
+ const record = this.collection.findBy(deserialize(vars));
178
187
 
179
- return record && serialize(record, this.type);
188
+ return record && serialize(record.toJSON(), this.type);
180
189
  }
181
190
 
182
191
  @register("Save{subtype}{type}Payload")
183
- handleSavePayload(_, { input: { clientMutationId, slug, id, ...args } }) {
192
+ handleSavePayload(
193
+ _,
194
+ { input: { clientMutationId = faker.datatype.uuid(), slug, id, ...args } }
195
+ ) {
184
196
  const identifier = slug ? { slug } : { id };
185
197
 
186
- const relKeys = this.server.schema.modelFor(
187
- this.type.toLowerCase()
188
- ).foreignKeys;
198
+ const relKeys = this.schema.modelFor(camelize(this.type)).foreignKeys;
189
199
 
190
200
  const parsedArgs = Object.entries(args).reduce((parsed, [key, value]) => {
191
201
  const re = new RegExp(`${camelize(key)}Id(s)?`);
@@ -193,14 +203,14 @@ export default class {
193
203
 
194
204
  return {
195
205
  ...parsed,
196
- [relKey ?? key]: value,
206
+ ...(value === undefined ? {} : { [relKey ?? key]: value }),
197
207
  };
198
208
  }, {});
199
209
 
200
- const obj = this.filter.find(this.collection, identifier);
210
+ const obj = this.collection.findBy(identifier);
201
211
  const res = obj
202
- ? this.collection.update(obj.id, parsedArgs)
203
- : this.collection.insert(
212
+ ? obj.update(deserialize(parsedArgs))
213
+ : this.collection.create(
204
214
  this.server.build(
205
215
  dasherize(this.type),
206
216
  deserialize({
@@ -211,13 +221,7 @@ export default class {
211
221
  );
212
222
 
213
223
  return {
214
- [camelize(this.type)]: serialize(
215
- {
216
- ...relKeys.reduce((rels, key) => ({ ...rels, [key]: null }), {}),
217
- ...res,
218
- },
219
- this.type
220
- ),
224
+ [camelize(this.type)]: serialize(res.toJSON(), this.type),
221
225
  clientMutationId,
222
226
  };
223
227
  }
@@ -1,114 +1,40 @@
1
- import { MockList } from "graphql-tools";
2
-
3
- import {
4
- Filter,
5
- register,
6
- serialize,
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 questionFilter = new Filter("Question");
11
-
12
4
  export default class extends BaseMock {
13
5
  @register("ReorderFormQuestionsPayload")
14
- handleReorderFormQuestions(
15
- root,
16
- { input: { form: slug, questions: questionSlugs, clientMutationId } }
17
- ) {
18
- const form = this.filter.find(this.collection, { slug });
19
-
20
- const questions = questionSlugs.map((slug) => {
21
- return questionFilter.find(this.db.questions, { slug });
22
- });
23
-
24
- const res = this.collection.update(form.id, {
25
- questionIds: questions.map(({ id }) => id),
26
- });
27
-
28
- return {
29
- form: {
30
- ...serialize(res, this.type),
31
- questions: {
32
- edges: () =>
33
- new MockList(questions.length, () => ({
34
- node: (r, v, _, meta) =>
35
- serialize(questions[meta.path.prev.key], "Question"),
36
- })),
37
- },
6
+ handleReorderFormQuestions(_, { input }) {
7
+ return this.handleSavePayload.fn.call(this, _, {
8
+ input: {
9
+ id: input.form,
10
+ questionIds: input.questions,
38
11
  },
39
- clientMutationId,
40
- };
12
+ });
41
13
  }
42
14
 
43
15
  @register("AddFormQuestionPayload")
44
- handleAddFormQuestion(
45
- root,
46
- { input: { form: slug, question: questionSlug, clientMutationId } }
47
- ) {
48
- const form = this.filter.find(this.collection, { slug });
49
-
50
- const question = questionFilter.find(this.db.questions, {
51
- slug: questionSlug,
52
- });
53
-
54
- this.db.questions.update(question.id, {
55
- formIds: [...(question.formIds || []), form.id],
56
- });
57
-
58
- const res = this.collection.update(form.id, {
59
- questionIds: [...(form.questionIds || []), question.id],
60
- });
61
-
62
- const questions = res.questionIds.map((id) => this.db.questions.find(id));
63
-
64
- return {
65
- form: {
66
- ...serialize(res, this.type),
67
- questions: {
68
- edges: () =>
69
- new MockList(questions.length, () => ({
70
- node: (r, v, _, meta) =>
71
- serialize(questions[meta.path.prev.key], "Question"),
72
- })),
73
- },
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,
74
24
  },
75
- clientMutationId,
76
- };
25
+ });
77
26
  }
78
27
 
79
28
  @register("RemoveFormQuestionPayload")
80
- handleRemoveFormQuestion(
81
- root,
82
- { input: { form: slug, question: questionSlug, clientMutationId } }
83
- ) {
84
- const form = this.filter.find(this.collection, { slug });
85
-
86
- const question = questionFilter.find(this.db.questions, {
87
- slug: questionSlug,
88
- });
89
-
90
- this.db.questions.update(question.id, {
91
- formIds: question.formIds.filter((id) => id !== form.id),
92
- });
93
-
94
- const res = this.collection.update(form.id, {
95
- questionIds: form.questionIds.filter((id) => id !== question.id),
96
- });
97
-
98
- const questions = res.questionIds.map((id) => this.db.questions.find(id));
99
-
100
- return {
101
- form: {
102
- ...serialize(res, this.type),
103
- questions: {
104
- edges: () =>
105
- new MockList(questions.length, () => ({
106
- node: (r, v, _, meta) =>
107
- serialize(questions[meta.path.prev.key], "Question"),
108
- })),
109
- },
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,
110
37
  },
111
- clientMutationId,
112
- };
38
+ });
113
39
  }
114
40
  }
@@ -1,14 +1,6 @@
1
- import { MockList } from "graphql-tools";
2
-
3
- import {
4
- Filter,
5
- register,
6
- serialize,
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 optionFilter = new Filter("Option");
11
-
12
4
  export default class extends BaseMock {
13
5
  @register("SaveTextQuestionPayload")
14
6
  handleSaveTextQuestion(_, { input }) {
@@ -47,50 +39,26 @@ export default class extends BaseMock {
47
39
 
48
40
  @register("SaveChoiceQuestionPayload")
49
41
  handleSaveChoiceQuestion(_, { input }) {
50
- const options = input.options.map((slug) =>
51
- optionFilter.find(this.db.options, { slug })
52
- );
53
- const optionIds = options.map(({ id }) => String(id));
54
-
55
- const res = this.handleSavePayload.fn.call(this, _, {
56
- input: { ...input, options, optionIds, type: "CHOICE" },
57
- });
58
-
59
- Object.assign(res.question, {
60
- options: {
61
- edges: () =>
62
- new MockList(options.length, () => ({
63
- node: (r, v, _, meta) =>
64
- serialize(options[meta.path.prev.key], "Option"),
65
- })),
42
+ return this.handleSavePayload.fn.call(this, _, {
43
+ input: {
44
+ ...input,
45
+ optionIds: input.options,
46
+ options: undefined,
47
+ type: "CHOICE",
66
48
  },
67
49
  });
68
-
69
- return res;
70
50
  }
71
51
 
72
52
  @register("SaveMultipleChoiceQuestionPayload")
73
53
  handleSaveMultipleChoiceQuestion(_, { input }) {
74
- const options = input.options.map((slug) =>
75
- optionFilter.find(this.db.options, { slug })
76
- );
77
- const optionIds = options.map(({ id }) => String(id));
78
-
79
- const res = this.handleSavePayload.fn.call(this, _, {
80
- input: { ...input, options, optionIds, type: "MULTIPLE_CHOICE" },
81
- });
82
-
83
- Object.assign(res.question, {
84
- options: {
85
- edges: () =>
86
- new MockList(options.length, () => ({
87
- node: (r, v, _, meta) =>
88
- serialize(options[meta.path.prev.key], "Option"),
89
- })),
54
+ return this.handleSavePayload.fn.call(this, _, {
55
+ input: {
56
+ ...input,
57
+ optionIds: input.options,
58
+ options: undefined,
59
+ type: "MULTIPLE_CHOICE",
90
60
  },
91
61
  });
92
-
93
- return res;
94
62
  }
95
63
 
96
64
  @register("SaveTableQuestionPayload")
@@ -98,7 +66,8 @@ export default class extends BaseMock {
98
66
  return this.handleSavePayload.fn.call(this, _, {
99
67
  input: {
100
68
  ...input,
101
- ...(input.rowForm ? { rowForm: { slug: input.rowForm } } : {}),
69
+ rowFormId: input.rowForm,
70
+ rowForm: undefined,
102
71
  type: "TABLE",
103
72
  },
104
73
  });
@@ -109,7 +78,8 @@ export default class extends BaseMock {
109
78
  return this.handleSavePayload.fn.call(this, _, {
110
79
  input: {
111
80
  ...input,
112
- ...(input.subForm ? { subForm: { slug: input.subForm } } : {}),
81
+ subFormId: input.subForm,
82
+ subForm: undefined,
113
83
  type: "FORM",
114
84
  },
115
85
  });
@@ -0,0 +1,105 @@
1
+ import { DateTime } from "luxon";
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: DateTime.now().plus({ days: 30 }).toJSDate(),
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
+ }