@projectcaluma/ember-testing 11.0.0-beta.1 → 11.0.0-beta.10

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
+ }
@@ -1,9 +1,17 @@
1
1
  import { faker } from "@faker-js/faker";
2
- import moment from "moment";
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,6 +60,15 @@ 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" });
@@ -77,7 +94,10 @@ export function createInquiry(
77
94
  { from, to, remark, deadline },
78
95
  workItemAttrs = {}
79
96
  ) {
80
- const document = server.create("document", { formId: "inquiry" });
97
+ const document = server.create("document", {
98
+ formId: "inquiry",
99
+ modifiedContentByUser: "1",
100
+ });
81
101
 
82
102
  server.create("answer", {
83
103
  document,
@@ -102,11 +122,20 @@ export function createInquiry(
102
122
  });
103
123
  }
104
124
 
125
+ export function withdrawInquiry(server, { inquiry }) {
126
+ inquiry.update({ status: "CANCELED" });
127
+
128
+ return inquiry;
129
+ }
130
+
105
131
  export function sendInquiry(server, { inquiry }) {
106
132
  const childCase = server.create("case", {
107
133
  status: "RUNNING",
108
134
  workflowId: "inquiry",
109
- document: server.create("document", { formId: "inquiry-answer" }),
135
+ document: server.create("document", {
136
+ formId: "inquiry-answer",
137
+ modifiedContentByUser: "1",
138
+ }),
110
139
  });
111
140
 
112
141
  server.create("work-item", {
@@ -121,7 +150,7 @@ export function sendInquiry(server, { inquiry }) {
121
150
  return inquiry;
122
151
  }
123
152
 
124
- export function answerInquiry(server, { inquiry, status, reason }) {
153
+ export function answerInquiry(server, { inquiry, status, reason, hint }) {
125
154
  if (inquiry.status !== "READY") {
126
155
  inquiry = sendInquiry(server, { inquiry });
127
156
  }
@@ -135,7 +164,12 @@ export function answerInquiry(server, { inquiry, status, reason }) {
135
164
  server.create("answer", {
136
165
  document: inquiry.childCase.document,
137
166
  questionId: "inquiry-answer-reason",
138
- value: reason ?? faker.lorem.paragraph(),
167
+ value: reason ?? faker.lorem.paragraphs(3, "\n\n"),
168
+ });
169
+ server.create("answer", {
170
+ document: inquiry.childCase.document,
171
+ questionId: "inquiry-answer-hint",
172
+ value: hint ?? faker.lorem.paragraph(),
139
173
  });
140
174
 
141
175
  inquiry.childCase.workItems
@@ -192,6 +226,7 @@ export function reviseInquiry(server, { inquiry }) {
192
226
 
193
227
  export function createCase(server, { group }) {
194
228
  const distributionCase = server.create("case", {
229
+ id: "4222ab21-9c89-47de-98be-d62a8ed0ebeb",
195
230
  status: "RUNNING",
196
231
  workflowId: "distribution",
197
232
  });
@@ -223,35 +258,42 @@ export default function (server, groups) {
223
258
  const g4 = groups[4];
224
259
 
225
260
  const create = (...args) => createInquiry(server, distributionCase, ...args);
261
+ const withdraw = (...args) => withdrawInquiry(server, ...args);
226
262
  const send = (...args) => sendInquiry(server, ...args);
227
263
  const answer = (...args) => answerInquiry(server, ...args);
228
264
  const confirm = (...args) => confirmInquiry(...args);
229
265
  const revise = (...args) => reviseInquiry(server, ...args);
230
266
 
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
- });
267
+ const distributionCase = createCase(server, { group: g });
238
268
 
239
269
  // controlling
240
- create({ from: g, to: g1 });
270
+ create({ from: g, to: g1 }, { id: "d570dfc3-0df7-4276-8735-892be011923c" });
271
+ withdraw({
272
+ inquiry: create(
273
+ { from: g, to: g2 },
274
+ { id: "4afed640-07a6-4eb9-82a7-b5e961391370" }
275
+ ),
276
+ });
241
277
  send({
242
- inquiry: create({
243
- from: g,
244
- to: g2,
245
- deadline: faker.date.past(),
246
- }),
278
+ inquiry: create(
279
+ {
280
+ from: g,
281
+ to: g2,
282
+ deadline: faker.date.past(),
283
+ },
284
+ { id: "6bbdc36a-3174-4578-93d4-0cb84d3dab97" }
285
+ ),
247
286
  });
248
287
  confirm({
249
288
  inquiry: answer({
250
- inquiry: create({
251
- from: g,
252
- to: g3,
253
- deadline: faker.date.past(),
254
- }),
289
+ inquiry: create(
290
+ {
291
+ from: g,
292
+ to: g3,
293
+ deadline: faker.date.past(),
294
+ },
295
+ { id: "88999388-daf2-4a18-b7e2-50373d082331" }
296
+ ),
255
297
  status: "inquiry-answer-status-needs-interaction",
256
298
  }),
257
299
  });
@@ -259,15 +301,32 @@ export default function (server, groups) {
259
301
  // "override" third controlling inquiry
260
302
  confirm({
261
303
  inquiry: answer({
262
- inquiry: create({ from: g, to: g3 }, { createdAt: faker.date.recent() }),
304
+ inquiry: create(
305
+ { from: g, to: g3 },
306
+ {
307
+ id: "75d56729-5518-469d-ae66-188a5c32d59d",
308
+ createdAt: faker.date.recent(),
309
+ }
310
+ ),
263
311
  status: "inquiry-answer-status-positive",
264
312
  }),
265
313
  });
266
314
 
315
+ // withdrawn inquiry, should not be visible anywhere
316
+ withdraw({
317
+ inquiry: create(
318
+ { from: g, to: g4 },
319
+ { id: "7360fa66-83d2-4f6a-b489-5db46f6fd670" }
320
+ ),
321
+ });
322
+
267
323
  // addressed
268
324
  confirm({
269
325
  inquiry: answer({
270
- inquiry: create({ from: g2, to: g }),
326
+ inquiry: create(
327
+ { from: g2, to: g },
328
+ { id: "e907584c-a38a-488e-80f7-bab6bb22f303" }
329
+ ),
271
330
  status: "inquiry-answer-status-needs-interaction",
272
331
  }),
273
332
  });
@@ -277,24 +336,36 @@ export default function (server, groups) {
277
336
  {
278
337
  from: g2,
279
338
  to: g,
280
- deadline: moment.utc().add(2, "days").toDate(),
339
+ deadline: DateTime.now().plus({ days: 2 }).toJSDate(),
281
340
  },
282
- { createdAt: faker.date.recent() }
341
+ {
342
+ id: "4889435d-f310-472f-808b-7b20936c40fc",
343
+ createdAt: faker.date.recent(),
344
+ }
283
345
  ),
284
346
  });
285
347
  confirm({
286
348
  inquiry: answer({
287
- inquiry: create({ from: g4, to: g }),
349
+ inquiry: create(
350
+ { from: g4, to: g },
351
+ { id: "4c5dbcc3-f42a-4c25-8d06-f85bd17edbf2" }
352
+ ),
288
353
  status: "inquiry-answer-status-negative",
289
354
  }),
290
355
  });
291
356
  answer({
292
- inquiry: create({ from: g3, to: g }),
357
+ inquiry: create(
358
+ { from: g3, to: g },
359
+ { id: "3f7eea45-251d-4934-81fd-27c78bbca88c" }
360
+ ),
293
361
  status: "inquiry-answer-status-positive",
294
362
  });
295
363
  revise({
296
364
  inquiry: answer({
297
- inquiry: create({ from: g1, to: g }),
365
+ inquiry: create(
366
+ { from: g1, to: g },
367
+ { id: "dd07b1a4-91e6-4411-a4ea-445637690577" }
368
+ ),
298
369
  status: "inquiry-answer-status-needs-interaction",
299
370
  }),
300
371
  });
@@ -302,13 +373,19 @@ export default function (server, groups) {
302
373
  // more
303
374
  confirm({
304
375
  inquiry: answer({
305
- inquiry: create({ from: g2, to: g3 }),
376
+ inquiry: create(
377
+ { from: g2, to: g3 },
378
+ { id: "4f374860-28b3-465b-be5f-5e501a39fe8b" }
379
+ ),
306
380
  status: "inquiry-answer-status-needs-interaction",
307
381
  }),
308
382
  });
309
383
  confirm({
310
384
  inquiry: answer({
311
- inquiry: create({ from: g3, to: g4 }),
385
+ inquiry: create(
386
+ { from: g3, to: g4 },
387
+ { id: "16eebfae-55c5-4d31-ad48-7ed5578a22a2" }
388
+ ),
312
389
  status: "inquiry-answer-status-positive",
313
390
  }),
314
391
  });
@@ -1,6 +1,6 @@
1
1
  import { faker } from "@faker-js/faker";
2
+ import { DateTime } from "luxon";
2
3
  import { Factory } from "miragejs";
3
- import moment from "moment";
4
4
 
5
5
  export default Factory.extend({
6
6
  id: () => faker.datatype.uuid(),
@@ -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") {
@@ -73,13 +78,7 @@ export default Factory.extend({
73
78
 
74
79
  if (answer.value === undefined) {
75
80
  const date = faker.date.future();
76
- answer.update({
77
- value: moment({
78
- day: date.getUTCDate(),
79
- month: date.getUTCMonth(),
80
- year: date.getUTCFullYear(),
81
- }).format(moment.HTML5_FMT.DATE),
82
- });
81
+ answer.update({ value: DateTime.fromJSDate(date).toISODate() });
83
82
  }
84
83
  } else if (answer.question.type === "TABLE") {
85
84
  answer.update({ type: "TABLE" });
@@ -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,6 @@ 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: () => ({}),
13
14
  });
@@ -9,7 +9,7 @@ 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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-testing",
3
- "version": "11.0.0-beta.1",
3
+ "version": "11.0.0-beta.10",
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.3.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",
24
+ "ember-cli-htmlbars": "^6.1.0",
25
+ "ember-cli-mirage": "^3.0.0-alpha.3",
25
26
  "ember-fetch": "^8.1.1",
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
- "miragejs": "^0.1.43",
31
- "moment": "^2.29.1"
31
+ "luxon": "^3.0.1",
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
- }