@projectcaluma/ember-testing 11.0.0-beta.3 → 11.0.0-beta.30
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.
- package/CHANGELOG.md +86 -0
- package/addon/mirage-graphql/deserialize.js +13 -0
- package/addon/mirage-graphql/filters/answer.js +5 -7
- package/addon/mirage-graphql/filters/base.js +42 -24
- package/addon/mirage-graphql/filters/form.js +5 -1
- package/addon/mirage-graphql/filters/index.js +17 -0
- package/addon/mirage-graphql/filters/question.js +1 -1
- package/addon/mirage-graphql/filters/work-item.js +11 -11
- package/addon/mirage-graphql/index.js +59 -63
- package/addon/mirage-graphql/mocks/answer.js +6 -6
- package/addon/mirage-graphql/mocks/base.js +14 -11
- package/addon/mirage-graphql/mocks/form.js +2 -2
- package/addon/mirage-graphql/mocks/index.js +17 -0
- package/addon/mirage-graphql/mocks/question.js +5 -5
- package/addon/mirage-graphql/mocks/work-item.js +57 -12
- package/addon/mirage-graphql/register.js +20 -0
- package/addon/mirage-graphql/schema.graphql +763 -1889
- package/addon/mirage-graphql/serialize.js +14 -0
- package/addon/scenarios/distribution.js +91 -12
- package/addon-mirage-support/factories/answer.js +13 -8
- package/addon-mirage-support/factories/case.js +1 -1
- package/addon-mirage-support/factories/document.js +2 -0
- package/addon-mirage-support/factories/file.js +1 -1
- package/addon-mirage-support/factories/form.js +5 -0
- package/addon-mirage-support/factories/work-item.js +2 -1
- package/addon-mirage-support/models/task.js +1 -0
- package/package.json +19 -20
- package/addon/mirage-graphql/handler.js +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
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
|
+
|
|
1
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)
|
|
2
88
|
|
|
3
89
|
|
|
@@ -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
|
|
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
|
|
11
|
-
return this.questions(records, [value]
|
|
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 =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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) =>
|
|
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
|
|
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
|
|
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
|
|
5
|
-
return records.filter(({ status }) =>
|
|
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
|
|
9
|
-
return records.filter((record) =>
|
|
8
|
+
tasks(records, value) {
|
|
9
|
+
return records.filter((record) => value.includes(record.taskId));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
task(records, value
|
|
13
|
-
return this.tasks(records, [value]
|
|
12
|
+
task(records, value) {
|
|
13
|
+
return this.tasks(records, [value]);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
controllingGroups(records, value
|
|
16
|
+
controllingGroups(records, value) {
|
|
17
17
|
return records.filter((record) =>
|
|
18
|
-
value.every((g) =>
|
|
18
|
+
value.every((g) => record.controllingGroups?.includes(g))
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
addressedGroups(records, value
|
|
22
|
+
addressedGroups(records, value) {
|
|
23
23
|
return records.filter((record) =>
|
|
24
|
-
value.every((g) =>
|
|
24
|
+
value.every((g) => record.addressedGroups?.includes(g))
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,64 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
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("
|
|
65
|
-
|
|
64
|
+
@register("SaveDocumentFilesAnswerPayload")
|
|
65
|
+
handleSaveFilesAnswer(_, { input }) {
|
|
66
66
|
return this._handleSaveDocumentAnswer(_, {
|
|
67
67
|
...input,
|
|
68
|
-
value: input.value ?
|
|
69
|
-
type: "
|
|
68
|
+
value: input.value ? [...input.value] : [],
|
|
69
|
+
type: "FILES",
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -3,16 +3,14 @@ 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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 =
|
|
57
|
+
this.filter = createFilter(type);
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
get collection() {
|
|
@@ -193,7 +191,12 @@ export default class {
|
|
|
193
191
|
_,
|
|
194
192
|
{ input: { clientMutationId = faker.datatype.uuid(), slug, id, ...args } }
|
|
195
193
|
) {
|
|
196
|
-
|
|
194
|
+
// Sometimes we pass the identifier as property `slug` (e.g in `saveForm`),
|
|
195
|
+
// sometimes as `id` (e.g. in `saveDocument`) and sometimes as the camelized
|
|
196
|
+
// name of the type (e.g in `saveWorkItem`).
|
|
197
|
+
const identifier = slug
|
|
198
|
+
? { slug }
|
|
199
|
+
: { id: id ?? args[camelize(this.type)] };
|
|
197
200
|
|
|
198
201
|
const relKeys = this.schema.modelFor(camelize(this.type)).foreignKeys;
|
|
199
202
|
|
|
@@ -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("
|
|
96
|
-
|
|
95
|
+
@register("SaveFilesQuestionPayload")
|
|
96
|
+
handleSaveFilesQuestion(_, { input }) {
|
|
97
97
|
return this.handleSavePayload.fn.call(this, _, {
|
|
98
|
-
input: { ...input, type: "
|
|
98
|
+
input: { ...input, type: "FILES" },
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
}
|