@projectcaluma/ember-testing 10.2.0-beta.2 → 11.0.0-beta.11

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 (32) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/addon/mirage-graphql/deserialize.js +13 -0
  3. package/addon/mirage-graphql/filters/answer.js +5 -7
  4. package/addon/mirage-graphql/filters/base.js +42 -24
  5. package/addon/mirage-graphql/filters/form.js +5 -1
  6. package/addon/mirage-graphql/filters/index.js +17 -0
  7. package/addon/mirage-graphql/filters/question.js +1 -1
  8. package/addon/mirage-graphql/filters/work-item.js +11 -11
  9. package/addon/mirage-graphql/index.js +59 -63
  10. package/addon/mirage-graphql/mocks/answer.js +8 -14
  11. package/addon/mirage-graphql/mocks/base.js +9 -11
  12. package/addon/mirage-graphql/mocks/form.js +2 -2
  13. package/addon/mirage-graphql/mocks/index.js +17 -0
  14. package/addon/mirage-graphql/mocks/question.js +5 -5
  15. package/addon/mirage-graphql/mocks/work-item.js +24 -7
  16. package/addon/mirage-graphql/register.js +20 -0
  17. package/addon/mirage-graphql/schema.graphql +764 -1879
  18. package/addon/mirage-graphql/serialize.js +14 -0
  19. package/addon/scenarios/distribution.js +112 -35
  20. package/addon-mirage-support/factories/answer.js +16 -17
  21. package/addon-mirage-support/factories/case.js +2 -2
  22. package/addon-mirage-support/factories/document.js +3 -1
  23. package/addon-mirage-support/factories/file.js +2 -2
  24. package/addon-mirage-support/factories/form.js +6 -1
  25. package/addon-mirage-support/factories/format-validator.js +1 -1
  26. package/addon-mirage-support/factories/question.js +1 -1
  27. package/addon-mirage-support/factories/task.js +1 -1
  28. package/addon-mirage-support/factories/work-item.js +2 -2
  29. package/addon-mirage-support/models/question.js +1 -0
  30. package/blueprints/@projectcaluma/ember-testing/index.js +1 -4
  31. package/package.json +15 -15
  32. package/addon/mirage-graphql/handler.js +0 -60
package/CHANGELOG.md CHANGED
@@ -1,3 +1,118 @@
1
+ # [@projectcaluma/ember-testing-v11.0.0-beta.11](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.10...@projectcaluma/ember-testing-v11.0.0-beta.11) (2022-08-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * **testing:** add createdBy and modifiedBy filters ([c6ace21](https://github.com/projectcaluma/ember-caluma/commit/c6ace21c573d45da6f99c0bc2de076c507f4f056))
7
+ * **testing:** allow inverting of filters ([88ab05d](https://github.com/projectcaluma/ember-caluma/commit/88ab05d4c01275e835d79c22451592666cec4db2))
8
+
9
+ # [@projectcaluma/ember-testing-v11.0.0-beta.10](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.9...@projectcaluma/ember-testing-v11.0.0-beta.10) (2022-08-05)
10
+
11
+
12
+ * feat!: add multi file upload (#2040) ([c4fd004](https://github.com/projectcaluma/ember-caluma/commit/c4fd0049654b2d2e5ea62e5909a45d89cb888b40)), closes [#2040](https://github.com/projectcaluma/ember-caluma/issues/2040)
13
+
14
+
15
+ ### BREAKING CHANGES
16
+
17
+ * This requires the caluma backend version v8.0.0-beta.12
18
+ or later.
19
+
20
+ # [@projectcaluma/ember-testing-v11.0.0-beta.9](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.8...@projectcaluma/ember-testing-v11.0.0-beta.9) (2022-06-09)
21
+
22
+
23
+ ### Features
24
+
25
+ * **caluma:** use new filter syntax of caluma ([7a00c03](https://github.com/projectcaluma/ember-caluma/commit/7a00c03a103933d9e48dd88adb7382441a298742))
26
+
27
+
28
+ ### BREAKING CHANGES
29
+
30
+ * **caluma:** `ember-caluma` now requires Caluma version >=
31
+ 8.0.0-beta.6
32
+
33
+ # [@projectcaluma/ember-testing-v11.0.0-beta.8](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.7...@projectcaluma/ember-testing-v11.0.0-beta.8) (2022-05-13)
34
+
35
+
36
+ ### Features
37
+
38
+ * **distribution:** add status for skipped inquiries ([1f93c92](https://github.com/projectcaluma/ember-caluma/commit/1f93c92d76b697954ec54aefa12348c84cd0abf9))
39
+
40
+ # [@projectcaluma/ember-testing-v11.0.0-beta.7](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.6...@projectcaluma/ember-testing-v11.0.0-beta.7) (2022-05-09)
41
+
42
+
43
+ ### Features
44
+
45
+ * **distribution:** allow displaying more information in the answer ([9de7f01](https://github.com/projectcaluma/ember-caluma/commit/9de7f0149406a0a326ba59ca0abe27860a64f2a1))
46
+ * **distribution:** improve edit and answer inquiry UI and UX ([6cd2dee](https://github.com/projectcaluma/ember-caluma/commit/6cd2dee45dde245064a0ac013160093bc783789c))
47
+
48
+ # [@projectcaluma/ember-testing-v11.0.0-beta.6](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.5...@projectcaluma/ember-testing-v11.0.0-beta.6) (2022-04-07)
49
+
50
+
51
+ ### Features
52
+
53
+ * **cf-field:** add optional hints for form fields ([d847fbf](https://github.com/projectcaluma/ember-caluma/commit/d847fbffa376ea60971fb9e91aff8bf54ce77d50))
54
+ * **distribution:** enable completing the distribution ([beabe61](https://github.com/projectcaluma/ember-caluma/commit/beabe61bd34025c4785c1e1ba60c59babb3eb6ab))
55
+
56
+
57
+ ### BREAKING CHANGES
58
+
59
+ * **cf-field:** Question hints requires Caluma >= v7.15.0
60
+
61
+ Add option to create hints for certain question types. These
62
+ are displayed below the input field and can be used to provide
63
+ short, informative messages. Hints are available for all question
64
+ types except for form, static and action button questions.
65
+
66
+ # [@projectcaluma/ember-testing-v11.0.0-beta.5](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.4...@projectcaluma/ember-testing-v11.0.0-beta.5) (2022-03-23)
67
+
68
+
69
+ ### Bug Fixes
70
+
71
+ * **embroider:** add missing dependency on @ember/string ([3a6e6bb](https://github.com/projectcaluma/ember-caluma/commit/3a6e6bb39a8c1a40a2ae00b3d4ea00606a755e25))
72
+ * **embroider:** use factory function instead of dynamic importing ([91459e7](https://github.com/projectcaluma/ember-caluma/commit/91459e7add66139a1f268b6c74dbabd9fa486158))
73
+
74
+
75
+ ### Features
76
+
77
+ * **testing:** add handler for canceling work items ([51c8024](https://github.com/projectcaluma/ember-caluma/commit/51c80240234fffa36a44a68a695ee7dbf074f1a9))
78
+ * **testing:** extend distribution scenario with withdrawn inquiries ([a190f0f](https://github.com/projectcaluma/ember-caluma/commit/a190f0f7ccceeca2944b1647320c738d81d44733))
79
+
80
+ # [@projectcaluma/ember-testing-v11.0.0-beta.4](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.3...@projectcaluma/ember-testing-v11.0.0-beta.4) (2022-03-11)
81
+
82
+
83
+ ### Features
84
+
85
+ * **form-builder:** add new categories published and unpublished ([52c1c1d](https://github.com/projectcaluma/ember-caluma/commit/52c1c1deaf15991e595e042f643889be64b425a0))
86
+
87
+ # [@projectcaluma/ember-testing-v11.0.0-beta.3](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.2...@projectcaluma/ember-testing-v11.0.0-beta.3) (2022-02-16)
88
+
89
+
90
+ ### Features
91
+
92
+ * **distribution:** add index page when no inquiries exist ([689089c](https://github.com/projectcaluma/ember-caluma/commit/689089c8f28146a33346f382fe69e7ca1b588d97))
93
+
94
+ # [@projectcaluma/ember-testing-v11.0.0-beta.2](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.1...@projectcaluma/ember-testing-v11.0.0-beta.2) (2022-02-07)
95
+
96
+
97
+ ### Bug Fixes
98
+
99
+ * **testing:** replace moment with luxon ([893c6f4](https://github.com/projectcaluma/ember-caluma/commit/893c6f4a907a65f5e55eab72c09b7703c780a3a5))
100
+
101
+ # [@projectcaluma/ember-testing-v11.0.0-beta.1](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v10.2.0-beta.2...@projectcaluma/ember-testing-v11.0.0-beta.1) (2022-02-03)
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * **validation:** sync format validator validation with backend ([ee66968](https://github.com/projectcaluma/ember-caluma/commit/ee66968230b9f0e4c5a4df8bdb3f8e58b44b5b82))
107
+
108
+
109
+ ### BREAKING CHANGES
110
+
111
+ * **validation:** Use the `formatValidators` property of the backend to store and read
112
+ format validators instead of the `meta.formatValidators` so the backend
113
+ validates as well. For more information on how to migrate check the
114
+ migration guide to v11.
115
+
1
116
  # [@projectcaluma/ember-testing-v10.2.0-beta.2](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v10.2.0-beta.1...@projectcaluma/ember-testing-v10.2.0-beta.2) (2022-01-18)
2
117
 
3
118
 
@@ -0,0 +1,13 @@
1
+ export default function deserialize(serialized) {
2
+ let decodedId = serialized.id;
3
+
4
+ try {
5
+ decodedId = atob(serialized.id).split(":")[1] || serialized.id;
6
+ } catch (e) {
7
+ // This will happen if the ID is not a relay ID (Type plus ID base64
8
+ // encoded) but just the raw ID. The deserialize function needs to be able
9
+ // to handle both
10
+ }
11
+
12
+ return { ...serialized, ...(decodedId ? { id: decodedId } : {}) };
13
+ }
@@ -1,13 +1,11 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
- export default class extends BaseFilter {
4
- questions(records, value, { invert = false }) {
5
- return records.filter(
6
- (record) => invert !== value.includes(record.questionId)
7
- );
3
+ export default class AnswerFilter extends BaseFilter {
4
+ questions(records, value) {
5
+ return records.filter((record) => value.includes(record.questionId));
8
6
  }
9
7
 
10
- question(records, value, { invert = false }) {
11
- return this.questions(records, [value], { invert });
8
+ question(records, value) {
9
+ return this.questions(records, [value]);
12
10
  }
13
11
  }
@@ -1,36 +1,34 @@
1
1
  import { camelize } from "@ember/string";
2
2
 
3
- export default class {
3
+ export default class BaseFilter {
4
4
  constructor(type) {
5
5
  this.type = type;
6
6
  }
7
7
 
8
8
  _getFilterFns(rawFilters) {
9
- const filters = Array.isArray(rawFilters)
10
- ? // new format
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
-
21
- return { key, value, options };
22
- })
23
- : // old format
24
- Object.entries(rawFilters).map(([key, value]) => ({
25
- key,
26
- value,
27
- }));
9
+ const filters = rawFilters
10
+ .filter((filter) => Object.keys(filter).length !== 0) // filter out empty filters
11
+ .map((filter) => {
12
+ const entries = Object.entries(filter);
13
+ const key = entries[0][0];
14
+ const value = entries[0][1];
15
+ const options = entries
16
+ .slice(1)
17
+ .reduce((opts, [k, v]) => ({ ...opts, [k]: v }), {});
18
+
19
+ return { key, value, options };
20
+ });
28
21
 
29
22
  return filters.map(({ key, value, options = {} }) => {
30
23
  const fn = this[key];
31
24
 
32
- return typeof fn === "function"
33
- ? (records) => fn.call(this, records, value, options)
25
+ return typeof fn === "function" && ![null, undefined].includes(value)
26
+ ? (records) => {
27
+ const filteredRecords = fn.call(this, records, value, options);
28
+ return options?.invert
29
+ ? records.filter((record) => !filteredRecords.includes(record))
30
+ : filteredRecords;
31
+ }
34
32
  : (records) => records;
35
33
  });
36
34
  }
@@ -53,7 +51,7 @@ export default class {
53
51
  }
54
52
 
55
53
  filter(records, filters) {
56
- return this._getFilterFns(filters.filter ?? filters).reduce(
54
+ return this._getFilterFns(filters?.filter ?? []).reduce(
57
55
  (recs, fn) => fn(recs),
58
56
  this.sort(records, filters?.order)
59
57
  );
@@ -64,7 +62,27 @@ export default class {
64
62
  }
65
63
 
66
64
  slug(records, value) {
67
- return records.filter(({ slug }) => slug === value);
65
+ return this.slugs(records, [value]);
66
+ }
67
+
68
+ slugs(records, values) {
69
+ return records.filter(({ slug }) => values.includes(slug));
70
+ }
71
+
72
+ createdByUser(records, value) {
73
+ return records.filter(({ createdByUser }) => createdByUser === value);
74
+ }
75
+
76
+ createdByGroup(records, value) {
77
+ return records.filter(({ createdByGroup }) => createdByGroup === value);
78
+ }
79
+
80
+ modifiedByUser(records, value) {
81
+ return records.filter(({ modifiedByUser }) => modifiedByUser === value);
82
+ }
83
+
84
+ modifiedByGroup(records, value) {
85
+ return records.filter(({ modifiedByGroup }) => modifiedByGroup === value);
68
86
  }
69
87
 
70
88
  id(records, value) {
@@ -1,10 +1,14 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
- export default class extends BaseFilter {
3
+ export default class FormFilter extends BaseFilter {
4
4
  isArchived(records, value) {
5
5
  return records.filter(({ isArchived }) => isArchived === value);
6
6
  }
7
7
 
8
+ isPublished(records, value) {
9
+ return records.filter(({ isPublished }) => isPublished === value);
10
+ }
11
+
8
12
  search(records, value) {
9
13
  const re = new RegExp(`.*${value}.*`, "i");
10
14
 
@@ -0,0 +1,17 @@
1
+ import AnswerFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/answer";
2
+ import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
3
+ import FormFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/form";
4
+ import QuestionFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/question";
5
+ import WorkItemFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/work-item";
6
+
7
+ const FILTER_MAPPING = {
8
+ Answer: AnswerFilter,
9
+ Form: FormFilter,
10
+ Question: QuestionFilter,
11
+ WorkItem: WorkItemFilter,
12
+ };
13
+
14
+ export default function createFilter(type, ...args) {
15
+ const FilterClass = FILTER_MAPPING[type] ?? BaseFilter;
16
+ return new FilterClass(type, ...args);
17
+ }
@@ -1,6 +1,6 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
- export default class extends BaseFilter {
3
+ export default class QuestionFilter extends BaseFilter {
4
4
  isArchived(records, value) {
5
5
  return records.filter(({ isArchived }) => isArchived === value);
6
6
  }
@@ -1,27 +1,27 @@
1
1
  import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
2
2
 
3
- export default class extends BaseFilter {
4
- status(records, value, { invert = false }) {
5
- return records.filter(({ status }) => invert !== (status === value));
3
+ export default class WorkItemFilter extends BaseFilter {
4
+ status(records, value) {
5
+ return records.filter(({ status }) => status === value);
6
6
  }
7
7
 
8
- tasks(records, value, { invert = false }) {
9
- return records.filter((record) => invert !== value.includes(record.taskId));
8
+ tasks(records, value) {
9
+ return records.filter((record) => value.includes(record.taskId));
10
10
  }
11
11
 
12
- task(records, value, { invert = false }) {
13
- return this.tasks(records, [value], { invert });
12
+ task(records, value) {
13
+ return this.tasks(records, [value]);
14
14
  }
15
15
 
16
- controllingGroups(records, value, { invert = false }) {
16
+ controllingGroups(records, value) {
17
17
  return records.filter((record) =>
18
- value.every((g) => invert !== record.controllingGroups?.includes(g))
18
+ value.every((g) => record.controllingGroups?.includes(g))
19
19
  );
20
20
  }
21
21
 
22
- addressedGroups(records, value, { invert = false }) {
22
+ addressedGroups(records, value) {
23
23
  return records.filter((record) =>
24
- value.every((g) => invert !== record.addressedGroups?.includes(g))
24
+ value.every((g) => record.addressedGroups?.includes(g))
25
25
  );
26
26
  }
27
27
  }
@@ -1,64 +1,60 @@
1
- import { dasherize, classify } from "@ember/string";
2
- import require from "require";
3
-
4
- const importTypeOrBase = (path, type) => {
5
- try {
6
- return require(`${path}/${dasherize(type)}`).default;
7
- } catch (e) {
8
- return require(`${path}/base`).default;
9
- }
10
- };
11
-
12
- export const register = (tpl) => (target, name, descriptor) => {
13
- if (descriptor.value.__isHandler) {
14
- descriptor.value.__handlerFor.push(tpl);
15
- return descriptor;
16
- }
17
-
18
- descriptor.writable = false;
19
- descriptor.enumerable = true;
20
-
21
- descriptor.value = {
22
- __isHandler: true,
23
- // Mocks can have multiple handlers per type.
24
- __handlerFor: [tpl],
25
- fn: descriptor.value,
26
- };
27
-
28
- return descriptor;
29
- };
30
-
31
- export const serialize = (deserialized = {}, type) => {
32
- const __typename = [deserialized.type?.toLowerCase(), type]
33
- .filter(Boolean)
34
- .map(classify)
35
- .join("");
36
-
37
- return {
38
- ...deserialized,
39
- id: btoa(`${__typename}:${deserialized.id}`),
40
- __typename,
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 createMock from "@projectcaluma/ember-testing/mirage-graphql/mocks";
11
+ import typeDefs from "@projectcaluma/ember-testing/mirage-graphql/schema.graphql";
12
+
13
+ export default function createGraphqlHandler(server) {
14
+ return function graphqlHandler({ db }, request) {
15
+ const mocks = db._collections.reduce((m, { name }) => {
16
+ const cls = classify(singularize(name));
17
+ const mock = createMock(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);
41
59
  };
42
- };
43
-
44
- export const deserialize = (serialized) => {
45
- let decodedId = serialized.id;
46
-
47
- try {
48
- decodedId = atob(serialized.id).split(":")[1] || serialized.id;
49
- } catch (e) {
50
- // this is expected most times
51
- }
52
-
53
- return { ...serialized, ...(decodedId ? { id: decodedId } : {}) };
54
- };
55
-
56
- export const Filter = function (type, ...args) {
57
- return new (importTypeOrBase("./filters", type))(type, ...args);
58
- };
59
-
60
- export const Mock = function (type, ...args) {
61
- return new (importTypeOrBase("./mocks", type))(type, ...args);
62
- };
63
-
64
- export { default } from "./handler";
60
+ }
@@ -1,9 +1,9 @@
1
- import moment from "moment";
1
+ import { DateTime } from "luxon";
2
2
 
3
- import { register } from "@projectcaluma/ember-testing/mirage-graphql";
4
3
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
4
+ import register from "@projectcaluma/ember-testing/mirage-graphql/register";
5
5
 
6
- export default class extends BaseMock {
6
+ export default class AnswerMock extends BaseMock {
7
7
  _handleSaveDocumentAnswer(
8
8
  _,
9
9
  { question: questionId, document: documentId, value, type }
@@ -61,12 +61,12 @@ export default class extends BaseMock {
61
61
  });
62
62
  }
63
63
 
64
- @register("SaveDocumentFileAnswerPayload")
65
- handleSaveFileAnswer(_, { input }) {
64
+ @register("SaveDocumentFilesAnswerPayload")
65
+ handleSaveFilesAnswer(_, { input }) {
66
66
  return this._handleSaveDocumentAnswer(_, {
67
67
  ...input,
68
- value: input.value ? { metadata: { object_name: input.value } } : null,
69
- type: "FILE",
68
+ value: input.value ? [...input.value] : [],
69
+ type: "FILES",
70
70
  });
71
71
  }
72
72
 
@@ -74,13 +74,7 @@ export default class extends BaseMock {
74
74
  @register("SaveDefaultDateAnswerPayload")
75
75
  handleSaveDateAnswer(_, { input }) {
76
76
  const date = input.value;
77
- const value = date
78
- ? moment({
79
- day: date.getUTCDate(),
80
- month: date.getUTCMonth(),
81
- year: date.getUTCFullYear(),
82
- }).format(moment.HTML5_FMT.DATE)
83
- : null;
77
+ const value = date ? DateTime.fromJSDate(date).toISODate() : null;
84
78
 
85
79
  return this._handleSaveDocumentAnswer(_, {
86
80
  ...input,
@@ -1,18 +1,16 @@
1
1
  import { camelize, dasherize, classify } from "@ember/string";
2
- import faker from "@faker-js/faker";
2
+ import { faker } from "@faker-js/faker";
3
3
  import { singularize, pluralize } from "ember-inflector";
4
4
  import { MockList } from "graphql-tools";
5
5
 
6
- import {
7
- Filter,
8
- register,
9
- serialize,
10
- deserialize,
11
- } from "@projectcaluma/ember-testing/mirage-graphql";
6
+ import deserialize from "@projectcaluma/ember-testing/mirage-graphql/deserialize";
7
+ import createFilter from "@projectcaluma/ember-testing/mirage-graphql/filters";
8
+ import register from "@projectcaluma/ember-testing/mirage-graphql/register";
9
+ import serialize from "@projectcaluma/ember-testing/mirage-graphql/serialize";
12
10
 
13
11
  export const ANSWER_TYPES = [
14
12
  "DATE",
15
- "FILE",
13
+ "FILES",
16
14
  "FLOAT",
17
15
  "INTEGER",
18
16
  "LIST",
@@ -27,7 +25,7 @@ export const QUESTION_TYPES = [
27
25
  "DATE",
28
26
  "DYNAMIC_CHOICE",
29
27
  "DYNAMIC_MULTIPLE_CHOICE",
30
- "FILE",
28
+ "FILES",
31
29
  "FLOAT",
32
30
  "FORM",
33
31
  "INTEGER",
@@ -50,13 +48,13 @@ export const TYPE_MAPPING = {
50
48
  Task: TASK_TYPES,
51
49
  };
52
50
 
53
- export default class {
51
+ export default class BaseMock {
54
52
  constructor(type, server) {
55
53
  this.type = type;
56
54
  this.server = server;
57
55
  this.schema = server.schema;
58
56
 
59
- this.filter = new Filter(type);
57
+ this.filter = createFilter(type);
60
58
  }
61
59
 
62
60
  get collection() {
@@ -1,7 +1,7 @@
1
- import { register } from "@projectcaluma/ember-testing/mirage-graphql";
2
1
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
2
+ import register from "@projectcaluma/ember-testing/mirage-graphql/register";
3
3
 
4
- export default class extends BaseMock {
4
+ export default class FormMock extends BaseMock {
5
5
  @register("ReorderFormQuestionsPayload")
6
6
  handleReorderFormQuestions(_, { input }) {
7
7
  return this.handleSavePayload.fn.call(this, _, {
@@ -0,0 +1,17 @@
1
+ import AnswerMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/answer";
2
+ import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
3
+ import FormMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/form";
4
+ import QuestionMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/question";
5
+ import WorkItemMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/work-item";
6
+
7
+ const MOCK_MAPPING = {
8
+ Answer: AnswerMock,
9
+ Form: FormMock,
10
+ Question: QuestionMock,
11
+ WorkItem: WorkItemMock,
12
+ };
13
+
14
+ export default function createMock(type, ...args) {
15
+ const MockClass = MOCK_MAPPING[type] ?? BaseMock;
16
+ return new MockClass(type, ...args);
17
+ }
@@ -1,7 +1,7 @@
1
- import { register } from "@projectcaluma/ember-testing/mirage-graphql";
2
1
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
2
+ import register from "@projectcaluma/ember-testing/mirage-graphql/register";
3
3
 
4
- export default class extends BaseMock {
4
+ export default class QuestionMock extends BaseMock {
5
5
  @register("SaveTextQuestionPayload")
6
6
  handleSaveTextQuestion(_, { input }) {
7
7
  return this.handleSavePayload.fn.call(this, _, {
@@ -92,10 +92,10 @@ export default class extends BaseMock {
92
92
  });
93
93
  }
94
94
 
95
- @register("SaveFileQuestionPayload")
96
- handleSaveFileQuestion(_, { input }) {
95
+ @register("SaveFilesQuestionPayload")
96
+ handleSaveFilesQuestion(_, { input }) {
97
97
  return this.handleSavePayload.fn.call(this, _, {
98
- input: { ...input, type: "FILE" },
98
+ input: { ...input, type: "FILES" },
99
99
  });
100
100
  }
101
101
  }
@@ -1,13 +1,11 @@
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 deserialize from "@projectcaluma/ember-testing/mirage-graphql/deserialize";
7
4
  import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
5
+ import register from "@projectcaluma/ember-testing/mirage-graphql/register";
8
6
  import { createInquiry } from "@projectcaluma/ember-testing/scenarios/distribution";
9
7
 
10
- export default class extends BaseMock {
8
+ export default class WorkItemMock extends BaseMock {
11
9
  @register("ResumeWorkItemPayload")
12
10
  handleResumeWorkItem(_, { input }) {
13
11
  return this.handleSavePayload.fn.call(this, _, {
@@ -22,6 +20,13 @@ export default class extends BaseMock {
22
20
  });
23
21
  }
24
22
 
23
+ @register("CancelWorkItemPayload")
24
+ handleCancelWorkItem(_, { input }) {
25
+ return this.handleSavePayload.fn.call(this, _, {
26
+ input: { id: input.id, status: "CANCELED" },
27
+ });
28
+ }
29
+
25
30
  @register("CompleteWorkItemPayload")
26
31
  handleCompleteWorkItem(_, { input }) {
27
32
  const { id } = deserialize(input);
@@ -77,7 +82,7 @@ export default class extends BaseMock {
77
82
  to: { id: group },
78
83
  from: { id: workItem.addressedGroups[0] },
79
84
  remark: "",
80
- deadline: moment().add(30, "days").toDate(),
85
+ deadline: DateTime.now().plus({ days: 30 }).toJSDate(),
81
86
  },
82
87
  {
83
88
  createdAt: new Date(),
@@ -96,6 +101,18 @@ export default class extends BaseMock {
96
101
  status: "READY",
97
102
  addressedGroups: workItem.addressedGroups,
98
103
  });
104
+ } else if (taskId === "complete-distribution") {
105
+ this.collection
106
+ .where({ caseId, status: "READY", taskId: "inquiry" })
107
+ .update({ status: "SKIPPED" });
108
+
109
+ this.collection
110
+ .where({ caseId, status: "READY" })
111
+ .update({ status: "CANCELED" });
112
+
113
+ this.collection
114
+ .where({ caseId, status: "SUSPENDED" })
115
+ .update({ status: "CANCELED" });
99
116
  }
100
117
 
101
118
  return this.handleSavePayload.fn.call(this, _, {