@projectcaluma/ember-testing 10.1.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.
@@ -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
1
  import moment from "moment";
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")
@@ -1,5 +1,6 @@
1
1
  import { camelize, dasherize, classify } from "@ember/string";
2
- import { singularize } from "ember-inflector";
2
+ import { singularize, pluralize } from "ember-inflector";
3
+ import faker from "faker";
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,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
+ }
@@ -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
  """
@@ -8,12 +8,16 @@ export function createBlueprint(server) {
8
8
  server.create("question", {
9
9
  slug: "inquiry-remark",
10
10
  label: "Remark",
11
+ isRequired: "true",
12
+ maxLength: 9999,
13
+ minLength: 0,
11
14
  formIds: [inquiryForm.id],
12
15
  type: "TEXTAREA",
13
16
  });
14
17
  server.create("question", {
15
18
  slug: "inquiry-deadline",
16
19
  label: "Deadline",
20
+ isRequired: "true",
17
21
  formIds: [inquiryForm.id],
18
22
  type: "DATE",
19
23
  });
@@ -22,6 +26,8 @@ export function createBlueprint(server) {
22
26
  slug: "inquiry-answer-status",
23
27
  type: "CHOICE",
24
28
  formIds: [inquiryAnswerForm.id],
29
+ isRequired: "true",
30
+ label: "Status",
25
31
  options: [
26
32
  server.create("option", {
27
33
  slug: "inquiry-answer-status-positive",
@@ -39,12 +45,28 @@ export function createBlueprint(server) {
39
45
  });
40
46
  server.create("question", {
41
47
  slug: "inquiry-answer-reason",
48
+ isRequired: "true",
49
+ maxLength: 9999,
50
+ minLength: 0,
42
51
  label: "Reason",
43
52
  type: "TEXTAREA",
44
53
  formIds: [inquiryAnswerForm.id],
45
54
  });
46
55
 
56
+ server.create("workflow", { slug: "distribution" });
57
+ server.create("workflow", { slug: "inquiry" });
58
+
47
59
  server.create("task", { slug: "inquiry" });
60
+ server.create("task", {
61
+ slug: "compose-inquiry-answer",
62
+ type: "COMPLETE_WORKFLOW_FORM",
63
+ });
64
+ server.create("task", { slug: "confirm-inquiry-answer" });
65
+ server.create("task", { slug: "revise-inquiry-answer" });
66
+ server.create("task", {
67
+ slug: "adjust-inquiry-answer",
68
+ type: "COMPLETE_WORKFLOW_FORM",
69
+ });
48
70
  }
49
71
 
50
72
  export function createInquiry(
@@ -53,27 +75,22 @@ export function createInquiry(
53
75
  { from, to, remark, deadline },
54
76
  workItemAttrs = {}
55
77
  ) {
56
- const form = server.schema.forms.findBy({ slug: "inquiry" });
57
- const document = server.create("document", { form });
78
+ const document = server.create("document", { formId: "inquiry" });
58
79
 
59
80
  server.create("answer", {
60
81
  document,
61
- question: server.schema.questions.findBy({
62
- slug: "inquiry-remark",
63
- }),
82
+ questionId: "inquiry-remark",
64
83
  value: remark ?? faker.lorem.paragraph(),
65
84
  });
66
85
 
67
86
  server.create("answer", {
68
87
  document,
69
- question: server.schema.questions.findBy({
70
- slug: "inquiry-deadline",
71
- }),
88
+ questionId: "inquiry-deadline",
72
89
  value: deadline ?? faker.date.future(),
73
90
  });
74
91
 
75
92
  return server.create("work-item", {
76
- task: server.schema.tasks.findBy({ slug: "inquiry" }),
93
+ taskId: "inquiry",
77
94
  document,
78
95
  status: "SUSPENDED",
79
96
  case: distributionCase,
@@ -84,16 +101,21 @@ export function createInquiry(
84
101
  }
85
102
 
86
103
  export function sendInquiry(server, { inquiry }) {
87
- inquiry.update({
104
+ const childCase = server.create("case", {
105
+ status: "RUNNING",
106
+ workflowId: "inquiry",
107
+ document: server.create("document", { formId: "inquiry-answer" }),
108
+ });
109
+
110
+ server.create("work-item", {
111
+ taskId: "compose-inquiry-answer",
88
112
  status: "READY",
89
- childCase: server.create("case", {
90
- status: "RUNNING",
91
- document: server.create("document", {
92
- form: server.schema.forms.findBy({ slug: "inquiry-answer" }),
93
- }),
94
- }),
113
+ case: childCase,
114
+ addressedGroups: inquiry.addressedGroups,
95
115
  });
96
116
 
117
+ inquiry.update({ status: "READY", childCase });
118
+
97
119
  return inquiry;
98
120
  }
99
121
 
@@ -104,32 +126,74 @@ export function answerInquiry(server, { inquiry, status, reason }) {
104
126
 
105
127
  server.create("answer", {
106
128
  document: inquiry.childCase.document,
107
- question: server.schema.questions.findBy({
108
- slug: "inquiry-answer-status",
109
- }),
129
+ questionId: "inquiry-answer-status",
110
130
  value: status,
111
131
  });
112
132
 
113
133
  server.create("answer", {
114
134
  document: inquiry.childCase.document,
115
- question: server.schema.questions.findBy({
116
- slug: "inquiry-answer-reason",
117
- }),
135
+ questionId: "inquiry-answer-reason",
118
136
  value: reason ?? faker.lorem.paragraph(),
119
137
  });
120
138
 
139
+ inquiry.childCase.workItems
140
+ .filter((workItem) => workItem.taskId === "compose-inquiry-answer")
141
+ .update({ status: "COMPLETED" });
142
+ server.create("work-item", {
143
+ taskId: "confirm-inquiry-answer",
144
+ status: "READY",
145
+ case: inquiry.childCase,
146
+ addressedGroups: inquiry.addressedGroups,
147
+ });
148
+ server.create("work-item", {
149
+ taskId: "revise-inquiry-answer",
150
+ status: "READY",
151
+ case: inquiry.childCase,
152
+ addressedGroups: inquiry.addressedGroups,
153
+ });
154
+
155
+ return inquiry;
156
+ }
157
+
158
+ export function confirmInquiry({ inquiry }) {
121
159
  inquiry.update({ status: "COMPLETED" });
122
160
  inquiry.childCase.update({
123
161
  status: "COMPLETED",
124
162
  closedAt: faker.date.recent(),
125
163
  });
164
+ inquiry.childCase.workItems
165
+ .filter((workItem) => workItem.taskId === "confirm-inquiry-answer")
166
+ .update({ status: "COMPLETED" });
167
+ inquiry.childCase.workItems
168
+ .filter((workItem) => workItem.taskId === "revise-inquiry-answer")
169
+ .update({ status: "CANCELED" });
170
+
171
+ return inquiry;
172
+ }
173
+
174
+ export function reviseInquiry(server, { inquiry }) {
175
+ server.create("work-item", {
176
+ taskId: "adjust-inquiry-answer",
177
+ status: "READY",
178
+ case: inquiry.childCase,
179
+ addressedGroups: inquiry.addressedGroups,
180
+ });
181
+ inquiry.childCase.workItems
182
+ .filter((workItem) => workItem.taskId === "confirm-inquiry-answer")
183
+ .update({ status: "CANCELED" });
184
+ inquiry.childCase.workItems
185
+ .filter((workItem) => workItem.taskId === "revise-inquiry-answer")
186
+ .update({ status: "COMPLETED" });
126
187
 
127
188
  return inquiry;
128
189
  }
129
190
 
130
191
  export default function (server, groups) {
192
+ createBlueprint(server);
193
+
131
194
  const distributionCase = server.create("case", {
132
- workflow: server.create("workflow", { slug: "distribution" }),
195
+ status: "RUNNING",
196
+ workflowId: "distribution",
133
197
  });
134
198
 
135
199
  const g = groups[0];
@@ -141,8 +205,8 @@ export default function (server, groups) {
141
205
  const create = (...args) => createInquiry(server, distributionCase, ...args);
142
206
  const send = (...args) => sendInquiry(server, ...args);
143
207
  const answer = (...args) => answerInquiry(server, ...args);
144
-
145
- createBlueprint(server);
208
+ const confirm = (...args) => confirmInquiry(...args);
209
+ const revise = (...args) => reviseInquiry(server, ...args);
146
210
 
147
211
  // controlling
148
212
  create({ from: g, to: g1 });
@@ -153,24 +217,31 @@ export default function (server, groups) {
153
217
  deadline: faker.date.past(),
154
218
  }),
155
219
  });
156
- answer({
157
- inquiry: create({
158
- from: g,
159
- to: g3,
160
- deadline: faker.date.past(),
220
+ confirm({
221
+ inquiry: answer({
222
+ inquiry: create({
223
+ from: g,
224
+ to: g3,
225
+ deadline: faker.date.past(),
226
+ }),
227
+ status: "inquiry-answer-status-needs-interaction",
161
228
  }),
162
- status: "inquiry-answer-status-needs-interaction",
163
229
  });
230
+
164
231
  // "override" third controlling inquiry
165
- answer({
166
- inquiry: create({ from: g, to: g3 }, { createdAt: faker.date.recent() }),
167
- status: "inquiry-answer-status-positive",
232
+ confirm({
233
+ inquiry: answer({
234
+ inquiry: create({ from: g, to: g3 }, { createdAt: faker.date.recent() }),
235
+ status: "inquiry-answer-status-positive",
236
+ }),
168
237
  });
169
238
 
170
239
  // addressed
171
- answer({
172
- inquiry: create({ from: g2, to: g }),
173
- status: "inquiry-answer-status-needs-interaction",
240
+ confirm({
241
+ inquiry: answer({
242
+ inquiry: create({ from: g2, to: g }),
243
+ status: "inquiry-answer-status-needs-interaction",
244
+ }),
174
245
  });
175
246
  // "override" first addressed inquiry
176
247
  send({
@@ -183,18 +254,34 @@ export default function (server, groups) {
183
254
  { createdAt: faker.date.recent() }
184
255
  ),
185
256
  });
257
+ confirm({
258
+ inquiry: answer({
259
+ inquiry: create({ from: g4, to: g }),
260
+ status: "inquiry-answer-status-negative",
261
+ }),
262
+ });
186
263
  answer({
187
- inquiry: create({ from: g4, to: g }),
188
- status: "inquiry-answer-status-negative",
264
+ inquiry: create({ from: g3, to: g }),
265
+ status: "inquiry-answer-status-positive",
266
+ });
267
+ revise({
268
+ inquiry: answer({
269
+ inquiry: create({ from: g1, to: g }),
270
+ status: "inquiry-answer-status-needs-interaction",
271
+ }),
189
272
  });
190
273
 
191
274
  // more
192
- answer({
193
- inquiry: create({ from: g2, to: g3 }),
194
- status: "inquiry-answer-status-needs-interaction",
275
+ confirm({
276
+ inquiry: answer({
277
+ inquiry: create({ from: g2, to: g3 }),
278
+ status: "inquiry-answer-status-needs-interaction",
279
+ }),
195
280
  });
196
- answer({
197
- inquiry: create({ from: g3, to: g4 }),
198
- status: "inquiry-answer-status-positive",
281
+ confirm({
282
+ inquiry: answer({
283
+ inquiry: create({ from: g3, to: g4 }),
284
+ status: "inquiry-answer-status-positive",
285
+ }),
199
286
  });
200
287
  }
@@ -0,0 +1,9 @@
1
+ import { Factory } from "ember-cli-mirage";
2
+
3
+ export default Factory.extend({
4
+ id() {
5
+ return this.slug;
6
+ },
7
+ name: (i) => `Workflow #${i + 1}`,
8
+ slug: (i) => `workflow-${i + 1}`,
9
+ });
@@ -1,6 +1,7 @@
1
- import { Model, belongsTo } from "ember-cli-mirage";
1
+ import { Model, belongsTo, hasMany } from "ember-cli-mirage";
2
2
 
3
3
  export default Model.extend({
4
- document: belongsTo(),
4
+ document: belongsTo("document"),
5
5
  question: belongsTo(),
6
+ documents: hasMany("document", { inverse: null }),
6
7
  });
@@ -3,5 +3,6 @@ import { Model, belongsTo, hasMany } from "ember-cli-mirage";
3
3
  export default Model.extend({
4
4
  document: belongsTo(),
5
5
  workflow: belongsTo(),
6
+ parentWorkItem: belongsTo("workItem", { inverse: "childCase" }),
6
7
  workItems: hasMany(),
7
8
  });
@@ -1,5 +1,5 @@
1
1
  import { Model, hasMany } from "ember-cli-mirage";
2
2
 
3
3
  export default Model.extend({
4
- questions: hasMany(),
4
+ questions: hasMany({ inverse: "forms" }),
5
5
  });
@@ -1,7 +1,9 @@
1
1
  import { Model, hasMany, belongsTo } from "ember-cli-mirage";
2
2
 
3
3
  export default Model.extend({
4
- forms: hasMany(),
4
+ forms: hasMany({ inverse: "questions" }),
5
5
  options: hasMany(),
6
+ subForm: belongsTo("form", { inverse: null }),
7
+ rowForm: belongsTo("form", { inverse: null }),
6
8
  defaultAnswer: belongsTo("answer", { inverse: null }),
7
9
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-testing",
3
- "version": "10.1.0",
3
+ "version": "10.2.0-beta.1",
4
4
  "description": "Ember addon for testing with Caluma addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,13 +18,13 @@
18
18
  "broccoli-merge-trees": "^4.2.0",
19
19
  "ember-apollo-client": "^3.2.0",
20
20
  "ember-auto-import": "^2.2.3",
21
- "ember-cli-babel": "^7.26.6",
21
+ "ember-cli-babel": "^7.26.11",
22
22
  "ember-cli-htmlbars": "^6.0.1",
23
23
  "ember-cli-mirage": "^2.2.0",
24
24
  "ember-fetch": "^8.0.4",
25
25
  "ember-inflector": "^4.0.2",
26
26
  "faker": "^5.5.3",
27
- "graphql": "^15.6.1",
27
+ "graphql": "^15.8.0",
28
28
  "graphql-iso-date": "^3.6.1",
29
29
  "graphql-tools": "^4.0.8",
30
30
  "moment": "^2.29.1"
@@ -32,9 +32,9 @@
32
32
  "devDependencies": {
33
33
  "@ember/optional-features": "2.0.0",
34
34
  "@ember/test-helpers": "2.6.0",
35
- "@embroider/test-setup": "0.48.1",
35
+ "@embroider/test-setup": "0.49.0",
36
36
  "broccoli-asset-rev": "3.0.0",
37
- "ember-cli": "3.28.4",
37
+ "ember-cli": "3.28.5",
38
38
  "ember-cli-code-coverage": "1.0.3",
39
39
  "ember-cli-dependency-checker": "3.2.0",
40
40
  "ember-cli-inject-live-reload": "2.1.0",