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

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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@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)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **embroider:** add missing dependency on @ember/string ([3a6e6bb](https://github.com/projectcaluma/ember-caluma/commit/3a6e6bb39a8c1a40a2ae00b3d4ea00606a755e25))
7
+ * **embroider:** use factory function instead of dynamic importing ([91459e7](https://github.com/projectcaluma/ember-caluma/commit/91459e7add66139a1f268b6c74dbabd9fa486158))
8
+
9
+
10
+ ### Features
11
+
12
+ * **testing:** add handler for canceling work items ([51c8024](https://github.com/projectcaluma/ember-caluma/commit/51c80240234fffa36a44a68a695ee7dbf074f1a9))
13
+ * **testing:** extend distribution scenario with withdrawn inquiries ([a190f0f](https://github.com/projectcaluma/ember-caluma/commit/a190f0f7ccceeca2944b1647320c738d81d44733))
14
+
1
15
  # [@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)
2
16
 
3
17
 
@@ -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,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 AnswerFilter extends BaseFilter {
4
4
  questions(records, value, { invert = false }) {
5
5
  return records.filter(
6
6
  (record) => invert !== value.includes(record.questionId)
@@ -1,6 +1,6 @@
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
  }
@@ -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 FormFilter extends BaseFilter {
4
4
  isArchived(records, value) {
5
5
  return records.filter(({ isArchived }) => isArchived === value);
6
6
  }
@@ -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,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 WorkItemFilter extends BaseFilter {
4
4
  status(records, value, { invert = false }) {
5
5
  return records.filter(({ status }) => invert !== (status === value));
6
6
  }
@@ -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
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 }
@@ -3,12 +3,10 @@ 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",
@@ -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, _, {
@@ -1,13 +1,11 @@
1
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);
@@ -0,0 +1,20 @@
1
+ export default function register(tpl) {
2
+ return function decorate(target, name, descriptor) {
3
+ if (descriptor.value.__isHandler) {
4
+ descriptor.value.__handlerFor.push(tpl);
5
+ return descriptor;
6
+ }
7
+
8
+ descriptor.writable = false;
9
+ descriptor.enumerable = true;
10
+
11
+ descriptor.value = {
12
+ __isHandler: true,
13
+ // Mocks can have multiple handlers per type.
14
+ __handlerFor: [tpl],
15
+ fn: descriptor.value,
16
+ };
17
+
18
+ return descriptor;
19
+ };
20
+ }
@@ -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
+ }
@@ -110,6 +110,12 @@ export function createInquiry(
110
110
  });
111
111
  }
112
112
 
113
+ export function withdrawInquiry(server, { inquiry }) {
114
+ inquiry.update({ status: "CANCELED" });
115
+
116
+ return inquiry;
117
+ }
118
+
113
119
  export function sendInquiry(server, { inquiry }) {
114
120
  const childCase = server.create("case", {
115
121
  status: "RUNNING",
@@ -232,6 +238,7 @@ export default function (server, groups) {
232
238
  const g4 = groups[4];
233
239
 
234
240
  const create = (...args) => createInquiry(server, distributionCase, ...args);
241
+ const withdraw = (...args) => withdrawInquiry(server, ...args);
235
242
  const send = (...args) => sendInquiry(server, ...args);
236
243
  const answer = (...args) => answerInquiry(server, ...args);
237
244
  const confirm = (...args) => confirmInquiry(...args);
@@ -241,6 +248,12 @@ export default function (server, groups) {
241
248
 
242
249
  // controlling
243
250
  create({ from: g, to: g1 });
251
+ withdraw({
252
+ inquiry: create(
253
+ { from: g, to: g2 },
254
+ { id: "4afed640-07a6-4eb9-82a7-b5e961391370" }
255
+ ),
256
+ });
244
257
  send({
245
258
  inquiry: create(
246
259
  {
@@ -279,6 +292,14 @@ export default function (server, groups) {
279
292
  }),
280
293
  });
281
294
 
295
+ // withdrawn inquiry, should not be visible anywhere
296
+ withdraw({
297
+ inquiry: create(
298
+ { from: g, to: g4 },
299
+ { id: "7360fa66-83d2-4f6a-b489-5db46f6fd670" }
300
+ ),
301
+ });
302
+
282
303
  // addressed
283
304
  confirm({
284
305
  inquiry: answer({
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.5",
4
4
  "description": "Ember addon for testing with Caluma addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,10 +14,11 @@
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": "^6.0.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-apollo-client": "^4.0.2",
21
22
  "ember-auto-import": "^2.4.0",
22
23
  "ember-cli-babel": "^7.26.11",
23
24
  "ember-cli-htmlbars": "^6.0.1",
@@ -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
- }