@projectcaluma/ember-testing 11.0.0-beta.3 → 11.0.0-beta.31

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.
@@ -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,39 @@ 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
+
30
+ @register("RedoWorkItemPayload")
31
+ handleRedoWorkItem(_, { input }) {
32
+ const { id } = deserialize(input);
33
+ const workItem = this.collection.find(id);
34
+ const caseId = workItem?.childCaseId;
35
+
36
+ if (workItem.taskId === "distribution") {
37
+ this.collection
38
+ .where({ caseId, taskId: "complete-distribution" })
39
+ .update({ status: "READY" });
40
+ this.collection
41
+ .where({ caseId, taskId: "create-inquiry" })
42
+ .update({ status: "READY" });
43
+ } else if (workItem.taskId === "inquiry") {
44
+ this.server.create("work-item", {
45
+ caseId,
46
+ status: "READY",
47
+ taskId: "adjust-inquiry-answer",
48
+ });
49
+ }
50
+
51
+ return this.handleSavePayload.fn.call(this, _, {
52
+ input: { id, isRedoable: false, status: "READY" },
53
+ });
54
+ }
55
+
25
56
  @register("CompleteWorkItemPayload")
26
57
  handleCompleteWorkItem(_, { input }) {
27
58
  const { id } = deserialize(input);
@@ -55,7 +86,7 @@ export default class extends BaseMock {
55
86
  .update({ status: "CANCELED" });
56
87
  this.collection
57
88
  .findBy({ childCaseId: caseId })
58
- .update({ status: "COMPLETED" });
89
+ .update({ status: "COMPLETED", isRedoable: true });
59
90
  this.schema.cases.find(caseId).update({ status: "COMPLETED" });
60
91
  } else if (taskId === "revise-inquiry-answer") {
61
92
  this.collection
@@ -67,7 +98,12 @@ export default class extends BaseMock {
67
98
  taskId: "adjust-inquiry-answer",
68
99
  });
69
100
  } else if (taskId === "create-inquiry") {
70
- const { addressed_groups: groups } = JSON.parse(input.context);
101
+ const { addressed_groups: groups, answers } = JSON.parse(input.context);
102
+
103
+ const remark = answers?.["inquiry-remark"] ?? "";
104
+ const deadline =
105
+ answers?.["inquiry-deadline"] ??
106
+ DateTime.now().plus({ days: 30 }).toISODate();
71
107
 
72
108
  groups.forEach((group) => {
73
109
  createInquiry(
@@ -76,8 +112,8 @@ export default class extends BaseMock {
76
112
  {
77
113
  to: { id: group },
78
114
  from: { id: workItem.addressedGroups[0] },
79
- remark: "",
80
- deadline: DateTime.now().plus({ days: 30 }).toJSDate(),
115
+ remark,
116
+ deadline,
81
117
  },
82
118
  {
83
119
  createdAt: new Date(),
@@ -96,10 +132,26 @@ export default class extends BaseMock {
96
132
  status: "READY",
97
133
  addressedGroups: workItem.addressedGroups,
98
134
  });
135
+ } else if (taskId === "complete-distribution") {
136
+ this.collection
137
+ .where({ childCaseId: caseId, status: "READY", taskId: "distribution" })
138
+ .update({ status: "COMPLETED", isRedoable: true });
139
+
140
+ this.collection
141
+ .where({ caseId, status: "READY", taskId: "inquiry" })
142
+ .update({ status: "SKIPPED" });
143
+
144
+ this.collection
145
+ .where({ caseId, status: "READY" })
146
+ .update({ status: "CANCELED" });
147
+
148
+ this.collection
149
+ .where({ caseId, status: "SUSPENDED" })
150
+ .update({ status: "CANCELED" });
99
151
  }
100
152
 
101
153
  return this.handleSavePayload.fn.call(this, _, {
102
- input: { id: input.id, status: "COMPLETED" },
154
+ input: { id, status: "COMPLETED" },
103
155
  });
104
156
  }
105
157
  }
@@ -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
+ }