@7365admin1/module-hygiene 4.29.0 → 4.29.1-staging.13

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/module-hygiene",
3
3
  "license": "MIT",
4
- "version": "4.29.0",
4
+ "version": "4.29.1-staging.13",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "build": "tsup src/index.ts --format cjs,esm --dts",
14
14
  "release": "yarn run build && changeset publish",
15
15
  "lint": "tsc",
16
- "test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
16
+ "test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts src/utils/completion-photo.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
17
17
  },
18
18
  "devDependencies": {
19
19
  "@changesets/cli": "^2.26.0",
@@ -0,0 +1,204 @@
1
+ /*
2
+ * A PHOTO IS REQUIRED TO COMPLETE A TASK — and only to COMPLETE one.
3
+ *
4
+ * Owner requirement, 2026-09-10: "once task was completed they required to take
5
+ * photo before completing the task ... all the services that has this module
6
+ * must be the same process."
7
+ *
8
+ * The first version of this rule sat in the Joi schema and demanded a photo on
9
+ * every approve. A task in this product is a SET, not a unit: both clients tick
10
+ * units one at a time and open the photographs dialog on the tick that finishes
11
+ * the set. So that version broke every intermediate tick on both platforms —
12
+ * the owner hit it on the web M&E checklist, and `meareaunits.tsx` makes the
13
+ * same call with `attachment: []`.
14
+ *
15
+ * This exercises the SHIPPED decision function, compiled from source by the
16
+ * test script — not a re-typed copy.
17
+ */
18
+ import test from "node:test";
19
+ import assert from "node:assert/strict";
20
+ import {
21
+ COMPLETION_PHOTO_MESSAGE,
22
+ readCompletion,
23
+ requiresCompletionPhoto,
24
+ } from "./.build/completion-photo.util.mjs";
25
+
26
+ /** Approving a unit that still has un-actioned siblings — the common tick. */
27
+ const midSet = {
28
+ decision: "approve",
29
+ completesSet: false,
30
+ hasEvidence: false,
31
+ };
32
+
33
+ /** Approving the unit that finishes the set — the act evidence is for. */
34
+ const completing = {
35
+ decision: "approve",
36
+ completesSet: true,
37
+ hasEvidence: false,
38
+ };
39
+
40
+ /* ── the regression the owner reported ─────────────────────────────────── */
41
+
42
+ test("ticking a unit mid-set needs NO photo", () => {
43
+ // This is what broke: the web posts it with nothing attached, and
44
+ // `meareaunits.tsx` posts it with `attachment: []`.
45
+ assert.equal(requiresCompletionPhoto(midSet), false);
46
+ assert.equal(requiresCompletionPhoto({ ...midSet, attachment: [] }), false);
47
+ assert.equal(
48
+ requiresCompletionPhoto({ ...midSet, attachment: undefined }),
49
+ false
50
+ );
51
+ });
52
+
53
+ /* ── completing still requires evidence ────────────────────────────────── */
54
+
55
+ test("completing the set WITHOUT a photo is refused", () => {
56
+ assert.equal(requiresCompletionPhoto(completing), true);
57
+ });
58
+
59
+ test("an EMPTY attachment array is not evidence", () => {
60
+ // The shape a client sends when its uploader failed.
61
+ assert.equal(
62
+ requiresCompletionPhoto({ ...completing, attachment: [] }),
63
+ true
64
+ );
65
+ });
66
+
67
+ test("a BLANK id is not a photo", () => {
68
+ assert.equal(
69
+ requiresCompletionPhoto({ ...completing, attachment: ["", " "] }),
70
+ true
71
+ );
72
+ });
73
+
74
+ test("completing WITH a photo is allowed", () => {
75
+ assert.equal(
76
+ requiresCompletionPhoto({
77
+ ...completing,
78
+ attachment: ["68f05fbe0c11062938dadad9"],
79
+ }),
80
+ false
81
+ );
82
+ });
83
+
84
+ test("MULTIPLE photos are allowed — that is the point", () => {
85
+ assert.equal(
86
+ requiresCompletionPhoto({ ...completing, attachment: ["a1", "b2", "c3"] }),
87
+ false
88
+ );
89
+ });
90
+
91
+ /* ── the web posts a set's approves in a loop ──────────────────────────── */
92
+
93
+ test("a set already carrying a photo on another unit is not blocked", () => {
94
+ /*
95
+ * `ManageChecklistMain` loops over the set's approved items and puts the ids
96
+ * on only ONE of them, so the approve that completes the set is not reliably
97
+ * the one holding the evidence. Asking only "does THIS request have a photo"
98
+ * would reject a set that is in fact fully documented.
99
+ */
100
+ assert.equal(
101
+ requiresCompletionPhoto({ ...completing, hasEvidence: true }),
102
+ false
103
+ );
104
+ assert.equal(
105
+ requiresCompletionPhoto({
106
+ ...completing,
107
+ hasEvidence: true,
108
+ attachment: [],
109
+ }),
110
+ false
111
+ );
112
+ });
113
+
114
+ /* ── rejecting must NOT be blocked ─────────────────────────────────────── */
115
+
116
+ test("REJECTING is never blocked, even completing the set", () => {
117
+ /*
118
+ * A reject is the technician reporting a problem. Demanding a photograph
119
+ * before somebody can report one would stop them reporting it.
120
+ */
121
+ assert.equal(
122
+ requiresCompletionPhoto({
123
+ decision: "reject",
124
+ completesSet: true,
125
+ hasEvidence: false,
126
+ }),
127
+ false
128
+ );
129
+ });
130
+
131
+ /* ── which approve finishes the set: ONE definition with the clients ───── */
132
+
133
+ test("an approve finishes the set when every other unit is approved or rejected", () => {
134
+ const units = [
135
+ { unit: "u1", approve: true, reject: false, status: "completed" },
136
+ { unit: "u2", approve: false, reject: true, status: "completed" },
137
+ { unit: "u3", approve: false, reject: false, status: "open" },
138
+ ];
139
+ assert.equal(readCompletion(units, "u3").completesSet, true);
140
+ // Intermediate: another unit is still untouched.
141
+ assert.equal(readCompletion(units, "u1").completesSet, false);
142
+ });
143
+
144
+ test("actioned means approve/reject, NOT status — status at rest is open/closed", () => {
145
+ /*
146
+ * Staging holds units that are `closed` while approved or rejected. The units
147
+ * list (`isFullyActioned`) and both clients count those as done, so the photo
148
+ * rule must too, or the server and the screen disagree about the last tick.
149
+ */
150
+ const units = [
151
+ { unit: "u1", approve: true, reject: false, status: "closed" },
152
+ { unit: "u2", approve: false, reject: false, status: "open" },
153
+ ];
154
+ assert.equal(readCompletion(units, "u2").completesSet, true);
155
+
156
+ // And a status alone, with neither flag, is not an action.
157
+ const statusOnly = [
158
+ { unit: "u1", approve: false, reject: false, status: "completed" },
159
+ { unit: "u2", approve: false, reject: false, status: "open" },
160
+ ];
161
+ assert.equal(readCompletion(statusOnly, "u2").completesSet, false);
162
+ });
163
+
164
+ test("a one-unit set: its only tick finishes it; an empty set finishes nothing", () => {
165
+ assert.equal(readCompletion([{ unit: "u1" }], "u1").completesSet, true);
166
+ assert.deepEqual(readCompletion([], "u1"), {
167
+ completesSet: false,
168
+ hasEvidence: false,
169
+ });
170
+ });
171
+
172
+ test("ids compare as strings (ObjectId vs the route param)", () => {
173
+ const oid = { toString: () => "68f05fbe0c11062938dadad9" };
174
+ const units = [
175
+ { unit: oid, approve: false, reject: false },
176
+ { unit: "u2", approve: true, reject: false },
177
+ ];
178
+ assert.equal(
179
+ readCompletion(units, "68f05fbe0c11062938dadad9").completesSet,
180
+ true
181
+ );
182
+ });
183
+
184
+ test("evidence counts only OTHER units' photos", () => {
185
+ const units = [
186
+ { unit: "u1", approve: false, reject: true, attachment: ["f1"] },
187
+ { unit: "u2", approve: false, reject: false, attachment: [] },
188
+ ];
189
+ assert.equal(readCompletion(units, "u2").hasEvidence, true);
190
+ assert.equal(readCompletion(units, "u1").hasEvidence, false);
191
+ });
192
+
193
+ /* ── controls ──────────────────────────────────────────────────────────── */
194
+
195
+ test("CONTROL: the rule can actually say yes", () => {
196
+ // Without this, every assertion above could be passing against a function
197
+ // that returns false unconditionally.
198
+ assert.equal(requiresCompletionPhoto(completing), true);
199
+ });
200
+
201
+ test("CONTROL: the message names the action a person must take", () => {
202
+ // "Invalid payload" tells a technician standing in a plant room nothing.
203
+ assert.match(COMPLETION_PHOTO_MESSAGE, /take or upload at least one photo/i);
204
+ });