@openreachtech/hora-skills-ort-renchan 0.2.1 → 0.2.2
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.
|
@@ -9,7 +9,7 @@ These follow the **`hoc-jest` skill** — read it for the general rules; this fi
|
|
|
9
9
|
applies them to the agent-loop classes. In short: one file per class; nest
|
|
10
10
|
`describe(ClassName) > describe('#member()' / '.get:member') > describe('should …') > test.each(cases)`;
|
|
11
11
|
write each test as **Arrange / Act / Assert** separated by blank lines, taking the Act result into a
|
|
12
|
-
`received` variable; bind every
|
|
12
|
+
`received` variable; bind every spy to a `~Spy` variable; and keep `cases` data unique and
|
|
13
13
|
index-readable (`fake-keyword-0001`, `100001`, …).
|
|
14
14
|
|
|
15
15
|
## Grand principle: swap `context` for a stub and touch no real I/O
|
|
@@ -91,19 +91,18 @@ describe('SearchAction', () => {
|
|
|
91
91
|
]
|
|
92
92
|
|
|
93
93
|
test.each(cases)('keyword: $tally.keyword', async ({ tally }) => {
|
|
94
|
-
const searchSpy = jest.fn()
|
|
95
|
-
.mockResolvedValue({
|
|
96
|
-
items: [], // neutral; not under test
|
|
97
|
-
})
|
|
98
94
|
const args = {
|
|
99
95
|
argumentHash: tally,
|
|
100
96
|
context: {
|
|
101
97
|
searchClient: {
|
|
102
|
-
search:
|
|
98
|
+
search: async () => ({
|
|
99
|
+
items: [], // neutral; not under test
|
|
100
|
+
}),
|
|
103
101
|
},
|
|
104
102
|
},
|
|
105
|
-
onProgress:
|
|
103
|
+
onProgress: () => {},
|
|
106
104
|
}
|
|
105
|
+
const searchSpy = jest.spyOn(args.context.searchClient, 'search')
|
|
107
106
|
|
|
108
107
|
await SearchAction.create()
|
|
109
108
|
.run(args)
|
|
@@ -138,18 +137,16 @@ describe('SearchAction', () => {
|
|
|
138
137
|
]
|
|
139
138
|
|
|
140
139
|
test.each(cases)('keyword: $input.keyword', async ({ input, expected }) => {
|
|
141
|
-
const searchSpy = jest.fn()
|
|
142
|
-
.mockResolvedValue(expected)
|
|
143
140
|
const args = {
|
|
144
141
|
argumentHash: {
|
|
145
142
|
keyword: input.keyword,
|
|
146
143
|
},
|
|
147
144
|
context: {
|
|
148
145
|
searchClient: {
|
|
149
|
-
search:
|
|
146
|
+
search: async () => expected,
|
|
150
147
|
},
|
|
151
148
|
},
|
|
152
|
-
onProgress:
|
|
149
|
+
onProgress: () => {},
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
const received = await SearchAction.create()
|
|
@@ -281,7 +278,7 @@ describe('ResearchJobWorker', () => {
|
|
|
281
278
|
const worker = new ResearchJobWorker({
|
|
282
279
|
engine: {
|
|
283
280
|
subscriptionBroker: {
|
|
284
|
-
publish:
|
|
281
|
+
publish: async () => null,
|
|
285
282
|
},
|
|
286
283
|
},
|
|
287
284
|
config: {
|
|
@@ -295,7 +292,6 @@ describe('ResearchJobWorker', () => {
|
|
|
295
292
|
errorHash: {},
|
|
296
293
|
})
|
|
297
294
|
|
|
298
|
-
const updateProgressSpy = jest.fn()
|
|
299
295
|
const args = {
|
|
300
296
|
body: {
|
|
301
297
|
jobId: input.jobId,
|
|
@@ -304,11 +300,12 @@ describe('ResearchJobWorker', () => {
|
|
|
304
300
|
parcel: {
|
|
305
301
|
jobModel: {
|
|
306
302
|
job: {
|
|
307
|
-
updateProgress:
|
|
303
|
+
updateProgress: async () => null,
|
|
308
304
|
},
|
|
309
305
|
},
|
|
310
306
|
},
|
|
311
307
|
}
|
|
308
|
+
const updateProgressSpy = jest.spyOn(args.parcel.jobModel.job, 'updateProgress')
|
|
312
309
|
|
|
313
310
|
await worker.executeJob(args)
|
|
314
311
|
|
|
@@ -366,11 +363,6 @@ describe('RequestResearchMutationResolver', () => {
|
|
|
366
363
|
errorHash: {},
|
|
367
364
|
})
|
|
368
365
|
|
|
369
|
-
const dispatchJobSpy = jest.fn()
|
|
370
|
-
.mockResolvedValue({
|
|
371
|
-
hasResponse: () => true,
|
|
372
|
-
idKey: expected.jobId,
|
|
373
|
-
})
|
|
374
366
|
const args = {
|
|
375
367
|
variables: {
|
|
376
368
|
input: {
|
|
@@ -380,7 +372,10 @@ describe('RequestResearchMutationResolver', () => {
|
|
|
380
372
|
context: {
|
|
381
373
|
share: {
|
|
382
374
|
jobDispatcherProvider: {
|
|
383
|
-
dispatchJob:
|
|
375
|
+
dispatchJob: async () => ({
|
|
376
|
+
hasResponse: () => true,
|
|
377
|
+
idKey: expected.jobId,
|
|
378
|
+
}),
|
|
384
379
|
},
|
|
385
380
|
},
|
|
386
381
|
},
|
|
@@ -39,17 +39,19 @@ The unit-test conventions for an external API client. The files live under
|
|
|
39
39
|
- That the base launcher extends `BaseLauncher`, and that `clientConfig` returns the expected
|
|
40
40
|
connection settings.
|
|
41
41
|
- That the derived launcher's `Payload` / `Capsule` return the right classes.
|
|
42
|
-
- That `launchRequest()`, with **`fetch`
|
|
43
|
-
the correct `Request` (URL, method, headers, body) and returns a
|
|
42
|
+
- That `launchRequest()`, with **`fetch` spied** (`static get fetch ()` returns the native one, so the
|
|
43
|
+
spy goes there), is called with the correct `Request` (URL, method, headers, body) and returns a
|
|
44
|
+
`Capsule`.
|
|
44
45
|
- For an SDK wrapper ([sdk-wrapper.md](./sdk-wrapper.md)), inject a stub SDK through
|
|
45
46
|
`create({ sdkClient })` and assert that `launchRequest()` calls the SDK method with the right
|
|
46
47
|
arguments and returns the result carried in a `Capsule`.
|
|
47
48
|
|
|
48
|
-
##
|
|
49
|
+
## Spy the native `fetch` the getter returns
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
`static get fetch ()` returns the native `fetch`, so leave the getter alone and spy the real function
|
|
52
|
+
it hands back — the shape `hoc-jest` gives for a getter that returns a function. Have
|
|
53
|
+
`jest.spyOn(globalThis, 'fetch').mockResolvedValue(...)` return a `Response`, then assert that it was
|
|
54
|
+
called and what the `Capsule` extracted. No sub-class is needed.
|
|
53
55
|
|
|
54
56
|
```js
|
|
55
57
|
import CreateDocumentLauncher from '../../../../app/documentApiClient/CreateDocumentLauncher.js'
|
|
@@ -97,19 +99,12 @@ describe('CreateDocumentLauncher', () => {
|
|
|
97
99
|
status: 200,
|
|
98
100
|
}
|
|
99
101
|
)
|
|
100
|
-
const fetchSpy = jest.
|
|
102
|
+
const fetchSpy = jest.spyOn(globalThis, 'fetch')
|
|
101
103
|
.mockResolvedValue(responseTally)
|
|
102
104
|
|
|
103
|
-
const
|
|
104
|
-
/** @override */
|
|
105
|
-
static get fetch () {
|
|
106
|
-
return fetchSpy
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const launcher = SpyLauncher.create()
|
|
105
|
+
const launcher = CreateDocumentLauncher.create()
|
|
111
106
|
|
|
112
|
-
const payload =
|
|
107
|
+
const payload = CreateDocumentLauncher.createPayload(params)
|
|
113
108
|
|
|
114
109
|
const capsule = await launcher.launchRequest({
|
|
115
110
|
payload,
|
|
@@ -271,19 +271,20 @@ split files per class.
|
|
|
271
271
|
- **On success** (`error: null`, `output` present) → **dispatch is called** with the expected
|
|
272
272
|
`DispatcherCtor` and `body`.
|
|
273
273
|
- **On failure** (`error` present) → **dispatch is not called** (early return).
|
|
274
|
-
- Stub the dispatch entry point.
|
|
275
|
-
`jest.
|
|
274
|
+
- Stub the dispatch entry point. Give `context.share.jobDispatcherProvider.dispatchJob` a stub
|
|
275
|
+
function, spy that property with `jest.spyOn()`, and verify the arguments (`DispatcherCtor` /
|
|
276
|
+
`body`). **Don't actually enqueue a job.**
|
|
276
277
|
|
|
277
278
|
```js
|
|
278
279
|
// Success case: verify only that dispatch is called with the correct Dispatcher and body
|
|
279
|
-
const dispatchJobSpy = jest.fn()
|
|
280
280
|
const context = {
|
|
281
281
|
share: {
|
|
282
282
|
jobDispatcherProvider: {
|
|
283
|
-
dispatchJob:
|
|
283
|
+
dispatchJob: async () => null,
|
|
284
284
|
},
|
|
285
285
|
},
|
|
286
286
|
}
|
|
287
|
+
const dispatchJobSpy = jest.spyOn(context.share.jobDispatcherProvider, 'dispatchJob')
|
|
287
288
|
|
|
288
289
|
await SignUpPostWorker.create({ engine })
|
|
289
290
|
.onResolved({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openreachtech/hora-skills-ort-renchan",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Distributes the renchan backend skills used to develop with Hora Kit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -49,11 +49,12 @@
|
|
|
49
49
|
"@openreachtech/renchan-env": "^1.0.6",
|
|
50
50
|
"@types/jest": "^30.0.0",
|
|
51
51
|
"eslint": "^9.39.5",
|
|
52
|
-
"jest": "^30.5.
|
|
52
|
+
"jest": "^30.5.2"
|
|
53
53
|
},
|
|
54
54
|
"overrides": {
|
|
55
55
|
"@humanfs/node": "^0.16.8",
|
|
56
|
-
"brace-expansion@
|
|
56
|
+
"brace-expansion@1": "^1.1.21",
|
|
57
|
+
"brace-expansion@5": "^5.0.12",
|
|
57
58
|
"flatted": "^3.4.4"
|
|
58
59
|
},
|
|
59
60
|
"allowScripts": {
|