@projectcaluma/ember-testing 11.0.0-beta.2 → 11.0.0-beta.26

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
+ }
@@ -2,8 +2,16 @@ import { faker } from "@faker-js/faker";
2
2
  import { DateTime } from "luxon";
3
3
 
4
4
  export function createBlueprint(server) {
5
- const inquiryForm = server.create("form", { slug: "inquiry" });
6
- const inquiryAnswerForm = server.create("form", { slug: "inquiry-answer" });
5
+ const inquiryForm = server.create("form", {
6
+ name: "Inquiry",
7
+ slug: "inquiry",
8
+ isPublished: false,
9
+ });
10
+ const inquiryAnswerForm = server.create("form", {
11
+ name: "Inquiry answer",
12
+ slug: "inquiry-answer",
13
+ isPublished: false,
14
+ });
7
15
 
8
16
  server.create("question", {
9
17
  slug: "inquiry-remark",
@@ -52,10 +60,20 @@ export function createBlueprint(server) {
52
60
  type: "TEXTAREA",
53
61
  formIds: [inquiryAnswerForm.id],
54
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
+ });
55
72
 
56
73
  server.create("workflow", { slug: "distribution" });
57
74
  server.create("workflow", { slug: "inquiry" });
58
75
 
76
+ server.create("task", { slug: "distribution" });
59
77
  server.create("task", { slug: "create-inquiry" });
60
78
  server.create("task", { slug: "complete-distribution" });
61
79
  server.create("task", { slug: "inquiry" });
@@ -77,7 +95,10 @@ export function createInquiry(
77
95
  { from, to, remark, deadline },
78
96
  workItemAttrs = {}
79
97
  ) {
80
- const document = server.create("document", { formId: "inquiry" });
98
+ const document = server.create("document", {
99
+ formId: "inquiry",
100
+ modifiedContentByUser: "1",
101
+ });
81
102
 
82
103
  server.create("answer", {
83
104
  document,
@@ -102,11 +123,20 @@ export function createInquiry(
102
123
  });
103
124
  }
104
125
 
126
+ export function withdrawInquiry(server, { inquiry }) {
127
+ inquiry.update({ status: "CANCELED" });
128
+
129
+ return inquiry;
130
+ }
131
+
105
132
  export function sendInquiry(server, { inquiry }) {
106
133
  const childCase = server.create("case", {
107
134
  status: "RUNNING",
108
135
  workflowId: "inquiry",
109
- document: server.create("document", { formId: "inquiry-answer" }),
136
+ document: server.create("document", {
137
+ formId: "inquiry-answer",
138
+ modifiedContentByUser: "1",
139
+ }),
110
140
  });
111
141
 
112
142
  server.create("work-item", {
@@ -121,7 +151,7 @@ export function sendInquiry(server, { inquiry }) {
121
151
  return inquiry;
122
152
  }
123
153
 
124
- export function answerInquiry(server, { inquiry, status, reason }) {
154
+ export function answerInquiry(server, { inquiry, status, reason, hint }) {
125
155
  if (inquiry.status !== "READY") {
126
156
  inquiry = sendInquiry(server, { inquiry });
127
157
  }
@@ -135,7 +165,12 @@ export function answerInquiry(server, { inquiry, status, reason }) {
135
165
  server.create("answer", {
136
166
  document: inquiry.childCase.document,
137
167
  questionId: "inquiry-answer-reason",
138
- value: reason ?? faker.lorem.paragraph(),
168
+ value: reason ?? faker.lorem.paragraphs(3, "\n\n"),
169
+ });
170
+ server.create("answer", {
171
+ document: inquiry.childCase.document,
172
+ questionId: "inquiry-answer-hint",
173
+ value: hint ?? faker.lorem.paragraph(),
139
174
  });
140
175
 
141
176
  inquiry.childCase.workItems
@@ -191,9 +226,17 @@ export function reviseInquiry(server, { inquiry }) {
191
226
  }
192
227
 
193
228
  export function createCase(server, { group }) {
229
+ const distributionWorkItem = server.create("work-item", {
230
+ taskId: "distribution",
231
+ status: "READY",
232
+ case: server.create("case"),
233
+ });
234
+
194
235
  const distributionCase = server.create("case", {
236
+ id: "4222ab21-9c89-47de-98be-d62a8ed0ebeb",
195
237
  status: "RUNNING",
196
238
  workflowId: "distribution",
239
+ parentWorkItem: distributionWorkItem,
197
240
  });
198
241
 
199
242
  server.create("work-item", {
@@ -223,35 +266,42 @@ export default function (server, groups) {
223
266
  const g4 = groups[4];
224
267
 
225
268
  const create = (...args) => createInquiry(server, distributionCase, ...args);
269
+ const withdraw = (...args) => withdrawInquiry(server, ...args);
226
270
  const send = (...args) => sendInquiry(server, ...args);
227
271
  const answer = (...args) => answerInquiry(server, ...args);
228
272
  const confirm = (...args) => confirmInquiry(...args);
229
273
  const revise = (...args) => reviseInquiry(server, ...args);
230
274
 
231
- const distributionCase = createCase(server, { group: g1 });
232
-
233
- server.create("work-item", {
234
- taskId: "create-inquiry",
235
- status: "READY",
236
- addressedGroups: [g.id],
237
- });
275
+ const distributionCase = createCase(server, { group: g });
238
276
 
239
277
  // controlling
240
- create({ from: g, to: g1 });
278
+ create({ from: g, to: g1 }, { id: "d570dfc3-0df7-4276-8735-892be011923c" });
279
+ withdraw({
280
+ inquiry: create(
281
+ { from: g, to: g2 },
282
+ { id: "4afed640-07a6-4eb9-82a7-b5e961391370" }
283
+ ),
284
+ });
241
285
  send({
242
- inquiry: create({
243
- from: g,
244
- to: g2,
245
- deadline: faker.date.past(),
246
- }),
286
+ inquiry: create(
287
+ {
288
+ from: g,
289
+ to: g2,
290
+ deadline: faker.date.past(),
291
+ },
292
+ { id: "6bbdc36a-3174-4578-93d4-0cb84d3dab97" }
293
+ ),
247
294
  });
248
295
  confirm({
249
296
  inquiry: answer({
250
- inquiry: create({
251
- from: g,
252
- to: g3,
253
- deadline: faker.date.past(),
254
- }),
297
+ inquiry: create(
298
+ {
299
+ from: g,
300
+ to: g3,
301
+ deadline: faker.date.past(),
302
+ },
303
+ { id: "88999388-daf2-4a18-b7e2-50373d082331" }
304
+ ),
255
305
  status: "inquiry-answer-status-needs-interaction",
256
306
  }),
257
307
  });
@@ -259,15 +309,32 @@ export default function (server, groups) {
259
309
  // "override" third controlling inquiry
260
310
  confirm({
261
311
  inquiry: answer({
262
- inquiry: create({ from: g, to: g3 }, { createdAt: faker.date.recent() }),
312
+ inquiry: create(
313
+ { from: g, to: g3 },
314
+ {
315
+ id: "75d56729-5518-469d-ae66-188a5c32d59d",
316
+ createdAt: faker.date.recent(),
317
+ }
318
+ ),
263
319
  status: "inquiry-answer-status-positive",
264
320
  }),
265
321
  });
266
322
 
323
+ // withdrawn inquiry, should not be visible anywhere
324
+ withdraw({
325
+ inquiry: create(
326
+ { from: g, to: g4 },
327
+ { id: "7360fa66-83d2-4f6a-b489-5db46f6fd670" }
328
+ ),
329
+ });
330
+
267
331
  // addressed
268
332
  confirm({
269
333
  inquiry: answer({
270
- inquiry: create({ from: g2, to: g }),
334
+ inquiry: create(
335
+ { from: g2, to: g },
336
+ { id: "e907584c-a38a-488e-80f7-bab6bb22f303" }
337
+ ),
271
338
  status: "inquiry-answer-status-needs-interaction",
272
339
  }),
273
340
  });
@@ -279,22 +346,34 @@ export default function (server, groups) {
279
346
  to: g,
280
347
  deadline: DateTime.now().plus({ days: 2 }).toJSDate(),
281
348
  },
282
- { createdAt: faker.date.recent() }
349
+ {
350
+ id: "4889435d-f310-472f-808b-7b20936c40fc",
351
+ createdAt: faker.date.recent(),
352
+ }
283
353
  ),
284
354
  });
285
355
  confirm({
286
356
  inquiry: answer({
287
- inquiry: create({ from: g4, to: g }),
357
+ inquiry: create(
358
+ { from: g4, to: g },
359
+ { id: "4c5dbcc3-f42a-4c25-8d06-f85bd17edbf2" }
360
+ ),
288
361
  status: "inquiry-answer-status-negative",
289
362
  }),
290
363
  });
291
364
  answer({
292
- inquiry: create({ from: g3, to: g }),
365
+ inquiry: create(
366
+ { from: g3, to: g },
367
+ { id: "3f7eea45-251d-4934-81fd-27c78bbca88c" }
368
+ ),
293
369
  status: "inquiry-answer-status-positive",
294
370
  });
295
371
  revise({
296
372
  inquiry: answer({
297
- inquiry: create({ from: g1, to: g }),
373
+ inquiry: create(
374
+ { from: g1, to: g },
375
+ { id: "dd07b1a4-91e6-4411-a4ea-445637690577" }
376
+ ),
298
377
  status: "inquiry-answer-status-needs-interaction",
299
378
  }),
300
379
  });
@@ -302,14 +381,22 @@ export default function (server, groups) {
302
381
  // more
303
382
  confirm({
304
383
  inquiry: answer({
305
- inquiry: create({ from: g2, to: g3 }),
384
+ inquiry: create(
385
+ { from: g2, to: g3 },
386
+ { id: "4f374860-28b3-465b-be5f-5e501a39fe8b" }
387
+ ),
306
388
  status: "inquiry-answer-status-needs-interaction",
307
389
  }),
308
390
  });
309
391
  confirm({
310
392
  inquiry: answer({
311
- inquiry: create({ from: g3, to: g4 }),
393
+ inquiry: create(
394
+ { from: g3, to: g4 },
395
+ { id: "16eebfae-55c5-4d31-ad48-7ed5578a22a2" }
396
+ ),
312
397
  status: "inquiry-answer-status-positive",
313
398
  }),
314
399
  });
400
+
401
+ return distributionCase;
315
402
  }
@@ -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,4 +3,6 @@ import { Factory } from "miragejs";
3
3
 
4
4
  export default Factory.extend({
5
5
  id: () => faker.datatype.uuid(),
6
+ modifiedContentByUser: () => faker.datatype.uuid(),
7
+ modifiedContentAt: () => faker.date.past(),
6
8
  });
@@ -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(),
@@ -9,5 +9,10 @@ export default Factory.extend({
9
9
  slug: (i) => `form-${i + 1}`,
10
10
  description: () => faker.lorem.paragraph(),
11
11
  isArchived: false,
12
+ isPublished: true,
12
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),
13
18
  });
@@ -9,11 +9,12 @@ 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
14
  closedAt() {
15
15
  return STATUS.filter((s) => s !== "READY").includes(this.status)
16
16
  ? faker.date.past()
17
17
  : null;
18
18
  },
19
+ isRedoable: () => false,
19
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-testing",
3
- "version": "11.0.0-beta.2",
3
+ "version": "11.0.0-beta.26",
4
4
  "description": "Ember addon for testing with Caluma addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,30 +14,31 @@
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
- "@faker-js/faker": "^6.0.0-alpha.5",
17
+ "@ember/string": "^3.0.0",
18
+ "@faker-js/faker": "^7.5.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.4.2",
22
23
  "ember-cli-babel": "^7.26.11",
23
- "ember-cli-htmlbars": "^6.0.1",
24
- "ember-cli-mirage": "^2.4.0",
25
- "ember-fetch": "^8.1.1",
24
+ "ember-cli-htmlbars": "^6.1.0",
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.0",
31
- "miragejs": "^0.1.43"
31
+ "luxon": "^3.0.3",
32
+ "miragejs": "^0.1.45"
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.0.0",
36
+ "@ember/test-helpers": "2.8.1",
37
+ "@embroider/test-setup": "1.8.3",
37
38
  "broccoli-asset-rev": "3.0.0",
38
39
  "ember-cli": "3.28.5",
39
40
  "ember-cli-code-coverage": "1.0.3",
40
- "ember-cli-dependency-checker": "3.2.0",
41
+ "ember-cli-dependency-checker": "3.3.1",
41
42
  "ember-cli-inject-live-reload": "2.1.0",
42
43
  "ember-cli-sri": "2.1.1",
43
44
  "ember-cli-terser": "4.0.2",
@@ -47,14 +48,14 @@
47
48
  "ember-maybe-import-regenerator": "1.0.0",
48
49
  "ember-qunit": "5.1.5",
49
50
  "ember-resolver": "8.0.3",
50
- "ember-source": "3.28.8",
51
+ "ember-source": "3.28.9",
51
52
  "ember-source-channel-url": "3.0.0",
52
53
  "ember-try": "2.0.0",
53
54
  "graphql-tag": "2.12.6",
54
55
  "loader.js": "4.7.0",
55
- "qunit": "2.17.2",
56
+ "qunit": "2.19.1",
56
57
  "qunit-dom": "2.0.0",
57
- "webpack": "5.68.0"
58
+ "webpack": "5.74.0"
58
59
  },
59
60
  "engines": {
60
61
  "node": "12.* || 14.* || >= 16"
@@ -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
- }