@projectcaluma/ember-testing 11.0.0-beta.4 → 11.0.0-beta.40

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.
@@ -0,0 +1,14 @@
1
+ import { classify } from "@ember/string";
2
+
3
+ export default function serialize(deserialized = {}, type) {
4
+ const __typename = [deserialized.type?.toLowerCase(), type]
5
+ .filter(Boolean)
6
+ .map(classify)
7
+ .join("");
8
+
9
+ return {
10
+ ...deserialized,
11
+ id: btoa(`${__typename}:${deserialized.id}`),
12
+ __typename,
13
+ };
14
+ }
@@ -60,13 +60,27 @@ export function createBlueprint(server) {
60
60
  type: "TEXTAREA",
61
61
  formIds: [inquiryAnswerForm.id],
62
62
  });
63
+ server.create("question", {
64
+ slug: "inquiry-answer-hint",
65
+ isRequired: "false",
66
+ maxLength: 9999,
67
+ minLength: 0,
68
+ label: "Hint",
69
+ type: "TEXTAREA",
70
+ formIds: [inquiryAnswerForm.id],
71
+ });
63
72
 
64
73
  server.create("workflow", { slug: "distribution" });
65
74
  server.create("workflow", { slug: "inquiry" });
66
75
 
76
+ server.create("task", { slug: "distribution" });
67
77
  server.create("task", { slug: "create-inquiry" });
68
78
  server.create("task", { slug: "complete-distribution" });
69
- server.create("task", { slug: "inquiry" });
79
+ server.create("task", {
80
+ slug: "inquiry",
81
+ formId: inquiryForm.id,
82
+ type: "COMPLETE_TASK_FORM",
83
+ });
70
84
  server.create("task", {
71
85
  slug: "compose-inquiry-answer",
72
86
  type: "COMPLETE_WORKFLOW_FORM",
@@ -77,6 +91,7 @@ export function createBlueprint(server) {
77
91
  slug: "adjust-inquiry-answer",
78
92
  type: "COMPLETE_WORKFLOW_FORM",
79
93
  });
94
+ server.create("task", { slug: "check-inquiries" });
80
95
  }
81
96
 
82
97
  export function createInquiry(
@@ -110,11 +125,20 @@ export function createInquiry(
110
125
  });
111
126
  }
112
127
 
128
+ export function withdrawInquiry(server, { inquiry }) {
129
+ inquiry.update({ status: "CANCELED" });
130
+
131
+ return inquiry;
132
+ }
133
+
113
134
  export function sendInquiry(server, { inquiry }) {
114
135
  const childCase = server.create("case", {
115
136
  status: "RUNNING",
116
137
  workflowId: "inquiry",
117
- document: server.create("document", { formId: "inquiry-answer" }),
138
+ document: server.create("document", {
139
+ formId: "inquiry-answer",
140
+ modifiedContentAt: faker.date.recent(),
141
+ }),
118
142
  });
119
143
 
120
144
  server.create("work-item", {
@@ -129,7 +153,7 @@ export function sendInquiry(server, { inquiry }) {
129
153
  return inquiry;
130
154
  }
131
155
 
132
- export function answerInquiry(server, { inquiry, status, reason }) {
156
+ export function answerInquiry(server, { inquiry, status, reason, hint }) {
133
157
  if (inquiry.status !== "READY") {
134
158
  inquiry = sendInquiry(server, { inquiry });
135
159
  }
@@ -143,7 +167,12 @@ export function answerInquiry(server, { inquiry, status, reason }) {
143
167
  server.create("answer", {
144
168
  document: inquiry.childCase.document,
145
169
  questionId: "inquiry-answer-reason",
146
- value: reason ?? faker.lorem.paragraph(),
170
+ value: reason ?? faker.lorem.paragraphs(3, "\n\n"),
171
+ });
172
+ server.create("answer", {
173
+ document: inquiry.childCase.document,
174
+ questionId: "inquiry-answer-hint",
175
+ value: hint ?? faker.lorem.paragraph(),
147
176
  });
148
177
 
149
178
  inquiry.childCase.workItems
@@ -165,8 +194,8 @@ export function answerInquiry(server, { inquiry, status, reason }) {
165
194
  return inquiry;
166
195
  }
167
196
 
168
- export function confirmInquiry({ inquiry }) {
169
- inquiry.update({ status: "COMPLETED" });
197
+ export function confirmInquiry(server, { inquiry }) {
198
+ inquiry.update({ status: "COMPLETED", isRedoable: true });
170
199
  inquiry.childCase.update({
171
200
  status: "COMPLETED",
172
201
  closedAt: faker.date.recent(),
@@ -178,6 +207,21 @@ export function confirmInquiry({ inquiry }) {
178
207
  .filter((workItem) => workItem.taskId === "revise-inquiry-answer")
179
208
  .update({ status: "CANCELED" });
180
209
 
210
+ if (
211
+ !inquiry.case.workItems.filter(
212
+ (workItem) =>
213
+ workItem.taskId === "check-inquiries" &&
214
+ String(workItem.addressedGroups) === String(inquiry.addressedGroups)
215
+ ).length
216
+ ) {
217
+ server.create("work-item", {
218
+ taskId: "check-inquiries",
219
+ status: "READY",
220
+ case: inquiry.case,
221
+ addressedGroups: inquiry.addressedGroups,
222
+ });
223
+ }
224
+
181
225
  return inquiry;
182
226
  }
183
227
 
@@ -199,10 +243,17 @@ export function reviseInquiry(server, { inquiry }) {
199
243
  }
200
244
 
201
245
  export function createCase(server, { group }) {
246
+ const distributionWorkItem = server.create("work-item", {
247
+ taskId: "distribution",
248
+ status: "READY",
249
+ case: server.create("case"),
250
+ });
251
+
202
252
  const distributionCase = server.create("case", {
203
253
  id: "4222ab21-9c89-47de-98be-d62a8ed0ebeb",
204
254
  status: "RUNNING",
205
255
  workflowId: "distribution",
256
+ parentWorkItem: distributionWorkItem,
206
257
  });
207
258
 
208
259
  server.create("work-item", {
@@ -232,15 +283,22 @@ export default function (server, groups) {
232
283
  const g4 = groups[4];
233
284
 
234
285
  const create = (...args) => createInquiry(server, distributionCase, ...args);
286
+ const withdraw = (...args) => withdrawInquiry(server, ...args);
235
287
  const send = (...args) => sendInquiry(server, ...args);
236
288
  const answer = (...args) => answerInquiry(server, ...args);
237
- const confirm = (...args) => confirmInquiry(...args);
289
+ const confirm = (...args) => confirmInquiry(server, ...args);
238
290
  const revise = (...args) => reviseInquiry(server, ...args);
239
291
 
240
292
  const distributionCase = createCase(server, { group: g });
241
293
 
242
294
  // controlling
243
- create({ from: g, to: g1 });
295
+ create({ from: g, to: g1 }, { id: "d570dfc3-0df7-4276-8735-892be011923c" });
296
+ withdraw({
297
+ inquiry: create(
298
+ { from: g, to: g2 },
299
+ { id: "4afed640-07a6-4eb9-82a7-b5e961391370" }
300
+ ),
301
+ });
244
302
  send({
245
303
  inquiry: create(
246
304
  {
@@ -248,7 +306,7 @@ export default function (server, groups) {
248
306
  to: g2,
249
307
  deadline: faker.date.past(),
250
308
  },
251
- { id: "6bbdc36a-3174-4578-93d4-0cb84d3dab97" }
309
+ { id: "6bbdc36a-3174-4578-93d4-0cb84d3dab97", meta: {} }
252
310
  ),
253
311
  });
254
312
  confirm({
@@ -279,6 +337,14 @@ export default function (server, groups) {
279
337
  }),
280
338
  });
281
339
 
340
+ // withdrawn inquiry, should not be visible anywhere
341
+ withdraw({
342
+ inquiry: create(
343
+ { from: g, to: g4 },
344
+ { id: "7360fa66-83d2-4f6a-b489-5db46f6fd670" }
345
+ ),
346
+ });
347
+
282
348
  // addressed
283
349
  confirm({
284
350
  inquiry: answer({
@@ -348,4 +414,6 @@ export default function (server, groups) {
348
414
  status: "inquiry-answer-status-positive",
349
415
  }),
350
416
  });
417
+
418
+ return distributionCase;
351
419
  }
@@ -45,7 +45,7 @@ export default Factory.extend({
45
45
  if (answer.value === undefined) {
46
46
  answer.update({
47
47
  value: [
48
- faker.random.arrayElement(answer.question.options.models).slug,
48
+ faker.helpers.arrayElement(answer.question.options.models).slug,
49
49
  ],
50
50
  });
51
51
  }
@@ -54,18 +54,23 @@ export default Factory.extend({
54
54
 
55
55
  if (answer.value === undefined) {
56
56
  answer.update({
57
- value: faker.random.arrayElement(answer.question.options.models).slug,
57
+ value: faker.helpers.arrayElement(answer.question.options.models)
58
+ .slug,
58
59
  });
59
60
  }
60
- } else if (answer.question.type === "FILE") {
61
- answer.update({ type: "FILE" });
61
+ } else if (answer.question.type === "FILES") {
62
+ answer.update({ type: "FILES" });
62
63
 
63
64
  if (answer.value === undefined) {
64
65
  answer.update({
65
- value: {
66
- uploadUrl: faker.internet.url,
67
- downloadUrl: faker.internet.url,
68
- },
66
+ value: [
67
+ {
68
+ id: faker.datatype.uuid(),
69
+ name: faker.datatype.string(),
70
+ uploadUrl: faker.internet.url(),
71
+ downloadUrl: faker.internet.url(),
72
+ },
73
+ ],
69
74
  });
70
75
  }
71
76
  } else if (answer.question.type === "DATE") {
@@ -8,5 +8,5 @@ export default Factory.extend({
8
8
  createdByUser: () => faker.datatype.uuid(),
9
9
  createdAt: () => faker.date.past(),
10
10
  modifiedAt: () => faker.date.past(),
11
- status: () => faker.random.arrayElement(STATUS),
11
+ status: () => faker.helpers.arrayElement(STATUS),
12
12
  });
@@ -3,7 +3,7 @@ import { Factory } from "miragejs";
3
3
 
4
4
  export default Factory.extend({
5
5
  id: () => faker.datatype.uuid(),
6
- createdAt: () => faker.date.past(),
6
+ name: () => faker.datatype.string(),
7
7
  modifiedAt: () => faker.date.past(),
8
8
  createdByUser: () => faker.datatype.uuid(),
9
9
  uploadUrl: () => faker.internet.url(),
@@ -11,4 +11,8 @@ export default Factory.extend({
11
11
  isArchived: false,
12
12
  isPublished: true,
13
13
  meta: () => ({}),
14
+ createdByUser: () => faker.random.numeric(10),
15
+ createdByGroup: () => faker.random.numeric(10),
16
+ modifiedByUser: () => faker.random.numeric(10),
17
+ modifiedByGroup: () => faker.random.numeric(10),
14
18
  });
@@ -9,11 +9,13 @@ export default Factory.extend({
9
9
  createdByUser: () => faker.datatype.uuid(),
10
10
  createdAt: () => faker.date.past(),
11
11
  deadline: () => faker.date.future(),
12
- status: () => faker.random.arrayElement(STATUS),
12
+ status: () => faker.helpers.arrayElement(STATUS),
13
13
  addressedGroups: () => ["group1", "group2"],
14
+ assignedUsers: () => ["1"],
14
15
  closedAt() {
15
16
  return STATUS.filter((s) => s !== "READY").includes(this.status)
16
17
  ? faker.date.past()
17
18
  : null;
18
19
  },
20
+ isRedoable: () => false,
19
21
  });
@@ -1,6 +1,7 @@
1
1
  import { Model, belongsTo, hasMany } from "miragejs";
2
2
 
3
3
  export default Model.extend({
4
+ form: belongsTo(),
4
5
  workflow: belongsTo(),
5
6
  workItems: hasMany(),
6
7
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-testing",
3
- "version": "11.0.0-beta.4",
3
+ "version": "11.0.0-beta.40",
4
4
  "description": "Ember addon for testing with Caluma addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -9,55 +9,57 @@
9
9
  "homepage": "https://docs.caluma.io/ember-caluma",
10
10
  "repository": "github:projectcaluma/ember-caluma",
11
11
  "scripts": {
12
- "test": "npm-run-all test:*",
12
+ "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
13
13
  "test:ember": "ember test",
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
- "@faker-js/faker": "^6.0.0-beta.0",
17
+ "@ember/string": "^3.0.0",
18
+ "@faker-js/faker": "^7.6.0",
18
19
  "broccoli-funnel": "^3.0.8",
19
20
  "broccoli-merge-trees": "^4.2.0",
20
- "ember-apollo-client": "^3.2.0",
21
- "ember-auto-import": "^2.4.0",
21
+ "ember-apollo-client": "~4.0.2",
22
+ "ember-auto-import": "^2.5.0",
22
23
  "ember-cli-babel": "^7.26.11",
23
- "ember-cli-htmlbars": "^6.0.1",
24
- "ember-cli-mirage": "^3.0.0-alpha.2",
25
- "ember-fetch": "^8.1.1",
24
+ "ember-cli-htmlbars": "^6.1.1",
25
+ "ember-cli-mirage": "^3.0.0-alpha.3",
26
+ "ember-fetch": "^8.1.2",
26
27
  "ember-inflector": "^4.0.2",
27
28
  "graphql": "^15.8.0",
28
29
  "graphql-iso-date": "^3.6.1",
29
30
  "graphql-tools": "^4.0.8",
30
- "luxon": "^2.3.1",
31
- "miragejs": "^0.1.43"
31
+ "luxon": "^3.1.1",
32
+ "miragejs": "^0.1.46"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@ember/optional-features": "2.0.0",
35
- "@ember/test-helpers": "2.6.0",
36
- "@embroider/test-setup": "1.5.0",
36
+ "@ember/test-helpers": "2.7.0",
37
+ "@embroider/test-setup": "2.0.2",
37
38
  "broccoli-asset-rev": "3.0.0",
38
- "ember-cli": "3.28.5",
39
+ "concurrently": "7.6.0",
40
+ "ember-cli": "4.9.2",
39
41
  "ember-cli-code-coverage": "1.0.3",
40
- "ember-cli-dependency-checker": "3.2.0",
42
+ "ember-cli-dependency-checker": "3.3.1",
41
43
  "ember-cli-inject-live-reload": "2.1.0",
42
44
  "ember-cli-sri": "2.1.1",
43
45
  "ember-cli-terser": "4.0.2",
44
- "ember-disable-prototype-extensions": "1.1.3",
45
- "ember-export-application-global": "2.0.1",
46
46
  "ember-load-initializers": "2.1.2",
47
- "ember-maybe-import-regenerator": "1.0.0",
48
- "ember-qunit": "5.1.5",
47
+ "ember-qunit": "6.1.1",
49
48
  "ember-resolver": "8.0.3",
50
- "ember-source": "3.28.8",
49
+ "ember-source": "4.9.3",
51
50
  "ember-source-channel-url": "3.0.0",
52
51
  "ember-try": "2.0.0",
53
52
  "graphql-tag": "2.12.6",
54
53
  "loader.js": "4.7.0",
55
- "qunit": "2.18.0",
54
+ "qunit": "2.19.3",
56
55
  "qunit-dom": "2.0.0",
57
- "webpack": "5.70.0"
56
+ "webpack": "5.75.0"
57
+ },
58
+ "peerDependencies": {
59
+ "ember-source": "^3.28.0 || ^4.0.0"
58
60
  },
59
61
  "engines": {
60
- "node": "12.* || 14.* || >= 16"
62
+ "node": "14.* || 16.* || >= 18"
61
63
  },
62
64
  "ember": {
63
65
  "edition": "octane"
@@ -1,60 +0,0 @@
1
- import { classify } from "@ember/string";
2
- import { singularize } from "ember-inflector";
3
- import { graphql } from "graphql";
4
- import {
5
- GraphQLDate as Date,
6
- GraphQLDateTime as DateTime,
7
- } from "graphql-iso-date";
8
- import { addMockFunctionsToSchema, makeExecutableSchema } from "graphql-tools";
9
-
10
- import { Mock } from "@projectcaluma/ember-testing/mirage-graphql";
11
- import typeDefs from "@projectcaluma/ember-testing/mirage-graphql/schema.graphql";
12
-
13
- export default function (server) {
14
- return function ({ db }, request) {
15
- const mocks = db._collections.reduce((m, { name }) => {
16
- const cls = classify(singularize(name));
17
- const mock = new Mock(cls, server);
18
-
19
- return { ...m, ...mock.getHandlers() };
20
- }, {});
21
-
22
- const schema = makeExecutableSchema({
23
- typeDefs,
24
- resolvers: {
25
- Date,
26
- DateTime,
27
- GenericScalar: {
28
- serialize(value) {
29
- return typeof value === "string" ? JSON.parse(value) : value;
30
- },
31
- },
32
- },
33
- resolverValidationOptions: { requireResolversForResolveType: false },
34
- });
35
-
36
- const { query, variables } = JSON.parse(request.requestBody);
37
-
38
- addMockFunctionsToSchema({
39
- schema,
40
- mocks: {
41
- ...mocks,
42
- JSONString: () => JSON.stringify({}),
43
- GenericScalar: () => ({}),
44
- Node: (_, { id }) => ({ __typename: atob(id).split(":")[0] }),
45
- SelectedOption: ({ value }) => {
46
- const option = server.schema.options.findBy({ slug: value });
47
-
48
- return {
49
- slug: value,
50
- label: option.label,
51
- __typename: "SelectedOption",
52
- };
53
- },
54
- },
55
- preserveResolvers: false,
56
- });
57
-
58
- return graphql(schema, query, null, null, variables);
59
- };
60
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (/* environment, appConfig */) {
4
- return {};
5
- };