@magda/minion-framework 2.3.2 → 3.0.0-alpha.0
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/dist/Crawler.d.ts +8 -8
- package/dist/Crawler.js +62 -99
- package/dist/Crawler.js.map +1 -1
- package/dist/MinionOptions.d.ts +6 -5
- package/dist/MinionOptions.js +1 -2
- package/dist/buildWebhookConfig.d.ts +2 -2
- package/dist/buildWebhookConfig.js +4 -7
- package/dist/buildWebhookConfig.js.map +1 -1
- package/dist/commonYargs.d.ts +10 -10
- package/dist/commonYargs.js +31 -37
- package/dist/commonYargs.js.map +1 -1
- package/dist/getWebhookUrl.d.ts +1 -1
- package/dist/getWebhookUrl.js +2 -5
- package/dist/getWebhookUrl.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +111 -127
- package/dist/index.js.map +1 -1
- package/dist/isWebhookRegistered.d.ts +2 -2
- package/dist/isWebhookRegistered.js +14 -31
- package/dist/isWebhookRegistered.js.map +1 -1
- package/dist/registerWebhook.d.ts +5 -5
- package/dist/registerWebhook.js +33 -50
- package/dist/registerWebhook.js.map +1 -1
- package/dist/resumeWebhook.d.ts +3 -3
- package/dist/resumeWebhook.js +8 -22
- package/dist/resumeWebhook.js.map +1 -1
- package/dist/setupRecrawlEndpoint.d.ts +30 -30
- package/dist/setupRecrawlEndpoint.js +46 -45
- package/dist/setupRecrawlEndpoint.js.map +1 -1
- package/dist/setupWebhookEndpoint.d.ts +2 -2
- package/dist/setupWebhookEndpoint.js +22 -47
- package/dist/setupWebhookEndpoint.js.map +1 -1
- package/dist/startApiEndpoints.d.ts +1 -1
- package/dist/startApiEndpoints.js +4 -10
- package/dist/startApiEndpoints.js.map +1 -1
- package/dist/test/Crawler.spec.js +77 -93
- package/dist/test/Crawler.spec.js.map +1 -1
- package/dist/test/baseSpec.d.ts +10 -10
- package/dist/test/baseSpec.js +23 -25
- package/dist/test/baseSpec.js.map +1 -1
- package/dist/test/fakeArgv.d.ts +3 -3
- package/dist/test/fakeArgv.js +6 -6
- package/dist/test/fakeArgv.js.map +1 -1
- package/dist/test/makePromiseQueryable.d.ts +2 -2
- package/dist/test/makePromiseQueryable.js +2 -5
- package/dist/test/makePromiseQueryable.js.map +1 -1
- package/dist/test/registry.spec.js +27 -32
- package/dist/test/registry.spec.js.map +1 -1
- package/dist/test/setupRecrawlEndpoint.spec.js +29 -43
- package/dist/test/setupRecrawlEndpoint.spec.js.map +1 -1
- package/dist/test/startup.spec.js +33 -38
- package/dist/test/startup.spec.js.map +1 -1
- package/dist/test/webhooks.spec.js +43 -43
- package/dist/test/webhooks.spec.js.map +1 -1
- package/package.json +33 -21
package/dist/test/baseSpec.js
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
1
|
+
import sinon from "sinon";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import { require } from "@magda/esm-utils";
|
|
8
4
|
const portfinder = require("portfinder");
|
|
9
5
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function baseSpec(caption, fn) {
|
|
6
|
+
* This performs functions common to all the minion framework tests, like muting error logging
|
|
7
|
+
* (because we'll be deliberately causing errors in tests), finding free ports to listen on for
|
|
8
|
+
* testing the API, and setting up an express app to test against.
|
|
9
|
+
*
|
|
10
|
+
* @param caption The caption to put in the "describe" block that goes around this test
|
|
11
|
+
* @param fn A function in which to execute tests - this passes a number of arguments as no-arg functions
|
|
12
|
+
* that will return the latest value - these values change during test setup so they can't be
|
|
13
|
+
* passed directly during the test setup.
|
|
14
|
+
*/
|
|
15
|
+
export default function baseSpec(caption, fn) {
|
|
20
16
|
describe(caption, function () {
|
|
21
17
|
this.timeout(10000);
|
|
22
18
|
let expressApp;
|
|
23
19
|
let expressServer;
|
|
24
20
|
let listenPort;
|
|
25
21
|
before(() => {
|
|
26
|
-
|
|
22
|
+
sinon.stub(console, "info");
|
|
27
23
|
const originalConsoleError = console.error;
|
|
28
|
-
|
|
24
|
+
sinon.stub(console, "error").callsFake((...args) => {
|
|
29
25
|
if (!args[0] || !args[0].ignore) {
|
|
30
26
|
originalConsoleError(...args);
|
|
31
27
|
}
|
|
32
28
|
});
|
|
33
|
-
return portfinder.getPortPromise().then(port => {
|
|
29
|
+
return portfinder.getPortPromise().then((port) => {
|
|
34
30
|
listenPort = port;
|
|
35
31
|
});
|
|
36
32
|
});
|
|
37
33
|
after(() => {
|
|
38
|
-
|
|
34
|
+
sinon.restore(console);
|
|
35
|
+
if (expressServer) {
|
|
36
|
+
expressServer.close();
|
|
37
|
+
}
|
|
39
38
|
});
|
|
40
39
|
function beforeEachProperty() {
|
|
41
40
|
if (expressServer) {
|
|
42
41
|
expressServer.close();
|
|
43
42
|
}
|
|
44
|
-
expressApp =
|
|
43
|
+
expressApp = express();
|
|
45
44
|
const originalListen = expressApp.listen;
|
|
46
|
-
|
|
45
|
+
sinon.stub(expressApp, "listen").callsFake((port) => {
|
|
47
46
|
expressServer = originalListen.bind(expressApp)(port);
|
|
48
47
|
return expressServer;
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
50
|
fn(() => expressApp, () => expressServer, () => listenPort, beforeEachProperty);
|
|
52
51
|
});
|
|
53
|
-
}
|
|
54
|
-
exports.default = baseSpec;
|
|
52
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseSpec.js","sourceRoot":"","sources":["../../src/test/baseSpec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseSpec.js","sourceRoot":"","sources":["../../src/test/baseSpec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,O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GAAG,OAAO,EAAE,CAAC;YACvB,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;gBAChD,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;gBACtD,OAAO,aAAa,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,EAAE,CACE,GAAG,EAAE,CAAC,UAAU,EAChB,GAAG,EAAE,CAAC,aAAa,EACnB,GAAG,EAAE,CAAC,UAAU,EAChB,kBAAkB,CACrB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/test/fakeArgv.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MinionArguments } from "../commonYargs";
|
|
1
|
+
import { MinionArguments } from "../commonYargs.js";
|
|
2
2
|
export default function fakeArgv(options: {
|
|
3
3
|
internalUrl: string;
|
|
4
4
|
registryUrl: string;
|
|
@@ -7,5 +7,5 @@ export default function fakeArgv(options: {
|
|
|
7
7
|
jwtSecret: string;
|
|
8
8
|
userId: string;
|
|
9
9
|
listenPort: number;
|
|
10
|
-
crawlerRecordFetchNumber?: number;
|
|
11
|
-
: MinionArguments;
|
|
10
|
+
crawlerRecordFetchNumber?: number;
|
|
11
|
+
}): MinionArguments;
|
package/dist/test/fakeArgv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
1
|
+
export default function fakeArgv(options) {
|
|
2
|
+
return {
|
|
3
|
+
...options,
|
|
4
|
+
retries: 0
|
|
5
|
+
};
|
|
6
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fakeArgv.js","sourceRoot":"","sources":["../../src/test/fakeArgv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fakeArgv.js","sourceRoot":"","sources":["../../src/test/fakeArgv.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAShC;IACG,OAAO;QACH,GAAG,OAAO;QACV,OAAO,EAAE,CAAC;KACb,CAAC;AACN,CAAC"}
|
|
@@ -2,6 +2,6 @@ export interface QueryablePromise<W> extends Promise<W> {
|
|
|
2
2
|
isResolved: () => boolean;
|
|
3
3
|
isRejected: () => boolean;
|
|
4
4
|
isFulfilled: () => boolean;
|
|
5
|
-
isQueryable: boolean;
|
|
6
|
-
|
|
5
|
+
isQueryable: boolean;
|
|
6
|
+
}
|
|
7
7
|
export default function makePromiseQueryable<W>(promise: Promise<W> | QueryablePromise<W>): QueryablePromise<W>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function makePromiseQueryable(promise) {
|
|
1
|
+
export default function makePromiseQueryable(promise) {
|
|
4
2
|
// Don't create a wrapper for promises that can already be queried.
|
|
5
3
|
const castPromise = promise;
|
|
6
4
|
if (castPromise.isQueryable) {
|
|
@@ -27,5 +25,4 @@ function makePromiseQueryable(promise) {
|
|
|
27
25
|
return isRejected;
|
|
28
26
|
};
|
|
29
27
|
return result;
|
|
30
|
-
}
|
|
31
|
-
exports.default = makePromiseQueryable;
|
|
28
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makePromiseQueryable.js","sourceRoot":"","sources":["../../src/test/makePromiseQueryable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"makePromiseQueryable.js","sourceRoot":"","sources":["../../src/test/makePromiseQueryable.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,UAAU,oBAAoB,CACxC,OAAyC;IAEzC,mEAAmE;IACnE,MAAM,WAAW,GAAG,OAA8B,CAAC;IACnD,IAAI,WAAW,CAAC,WAAW,EAAE;QACzB,OAAO,WAAW,CAAC;KACtB;IAED,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,kEAAkE;IAClE,IAAI,MAAM,GAAQ,OAAO,CAAC,IAAI,CAC1B,UAAU,CAAC;QACP,UAAU,GAAG,IAAI,CAAC;QAClB,OAAO,CAAC,CAAC;IACb,CAAC,EACD,UAAU,CAAC;QACP,UAAU,GAAG,IAAI,CAAC;QAClB,MAAM,CAAC,CAAC;IACZ,CAAC,CACJ,CAAC;IACF,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,WAAW,GAAG;QACjB,OAAO,UAAU,IAAI,UAAU,CAAC;IACpC,CAAC,CAAC;IACF,MAAM,CAAC,UAAU,GAAG;QAChB,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IACF,MAAM,CAAC,UAAU,GAAG;QAChB,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IACF,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const aspectArb = jsverify_1.default.record({
|
|
16
|
-
id: jsverify_1.default.string,
|
|
17
|
-
name: jsverify_1.default.string,
|
|
18
|
-
jsonSchema: jsverify_1.default.json,
|
|
19
|
-
tenantId: jsverify_1.default.string
|
|
1
|
+
import jsc from "jsverify";
|
|
2
|
+
import nock from "nock";
|
|
3
|
+
import { encodeURIComponentWithApost } from "magda-typescript-common/src/test/util.js";
|
|
4
|
+
import buildJwt from "magda-typescript-common/src/session/buildJwt.js";
|
|
5
|
+
import { lcAlphaNumStringArbNe } from "magda-typescript-common/src/test/arbitraries.js";
|
|
6
|
+
import fakeArgv from "./fakeArgv.js";
|
|
7
|
+
import minion from "../index.js";
|
|
8
|
+
import baseSpec from "./baseSpec.js";
|
|
9
|
+
import { expect } from "chai";
|
|
10
|
+
const aspectArb = jsc.record({
|
|
11
|
+
id: jsc.string,
|
|
12
|
+
name: jsc.string,
|
|
13
|
+
jsonSchema: jsc.json,
|
|
14
|
+
tenantId: jsc.string
|
|
20
15
|
});
|
|
21
16
|
const userId = "b1fddd6f-e230-4068-bd2c-1a21844f1598";
|
|
22
|
-
|
|
17
|
+
baseSpec("registry interactions:", (expressApp, _expressServer, listenPort, beforeEachProperty) => {
|
|
23
18
|
doStartupTest("should register aspects", ({ aspectDefs, registryScope, tenantScope, jwtSecret, hook }) => {
|
|
24
19
|
aspectDefs.forEach((aspectDef) => {
|
|
25
20
|
registryScope
|
|
26
|
-
.put(`/aspects/${
|
|
21
|
+
.put(`/aspects/${encodeURIComponentWithApost(aspectDef.id)}`, aspectDef, {
|
|
27
22
|
reqheaders: reqHeaders(jwtSecret, userId)
|
|
28
23
|
})
|
|
29
24
|
.reply(201, aspectDef);
|
|
@@ -39,13 +34,13 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
39
34
|
.optionally()
|
|
40
35
|
.reply(201, aspectDefs);
|
|
41
36
|
registryScope
|
|
42
|
-
.get(`/hooks/${
|
|
37
|
+
.get(`/hooks/${encodeURIComponentWithApost(hook.id)}`, undefined, {
|
|
43
38
|
reqheaders: reqHeaders(jwtSecret, userId)
|
|
44
39
|
})
|
|
45
40
|
.reply(404, "");
|
|
46
41
|
registryScope
|
|
47
|
-
.put(`/hooks/${
|
|
48
|
-
|
|
42
|
+
.put(`/hooks/${encodeURIComponentWithApost(hook.id)}`, (body) => {
|
|
43
|
+
expect(hook).to.deep.include(body);
|
|
49
44
|
return true;
|
|
50
45
|
}, {
|
|
51
46
|
reqheaders: reqHeaders(jwtSecret, userId)
|
|
@@ -64,12 +59,12 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
64
59
|
.optionally()
|
|
65
60
|
.reply(201, aspectDefs);
|
|
66
61
|
registryScope
|
|
67
|
-
.get(`/hooks/${
|
|
62
|
+
.get(`/hooks/${encodeURIComponentWithApost(hook.id)}`, undefined, {
|
|
68
63
|
reqheaders: reqHeaders(jwtSecret, userId)
|
|
69
64
|
})
|
|
70
65
|
.reply(200, hook);
|
|
71
66
|
registryScope
|
|
72
|
-
.post(`/hooks/${
|
|
67
|
+
.post(`/hooks/${encodeURIComponentWithApost(hook.id)}/ack`, {
|
|
73
68
|
succeeded: false,
|
|
74
69
|
lastEventIdReceived: null,
|
|
75
70
|
active: true
|
|
@@ -82,12 +77,12 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
82
77
|
tenantScope.get("/tenants").reply(200, []);
|
|
83
78
|
});
|
|
84
79
|
function doStartupTest(caption, fn) {
|
|
85
|
-
|
|
80
|
+
jsc.property(caption, jsc.array(aspectArb), jsc.nestring, lcAlphaNumStringArbNe, lcAlphaNumStringArbNe, lcAlphaNumStringArbNe, jsc.array(jsc.nestring), jsc.array(jsc.nestring), lcAlphaNumStringArbNe, jsc.integer(0, 10), jsc.bool, (aspectDefs, id, registryHost, tenantHost, listenDomain, aspects, optionalAspects, jwtSecret, concurrency, enableMultiTenant) => {
|
|
86
81
|
beforeEachProperty();
|
|
87
82
|
const registryUrl = `http://${registryHost}.com`;
|
|
88
|
-
const registryScope =
|
|
83
|
+
const registryScope = nock(registryUrl); //.log(console.log);
|
|
89
84
|
const tenantUrl = `http://${tenantHost}.com`;
|
|
90
|
-
const tenantScope =
|
|
85
|
+
const tenantScope = nock(tenantUrl); //.log(console.log);
|
|
91
86
|
const internalUrl = `http://${listenDomain}.com:${listenPort()}`;
|
|
92
87
|
const hook = buildWebHook(id, internalUrl, aspects, optionalAspects);
|
|
93
88
|
const userId = "b1fddd6f-e230-4068-bd2c-1a21844f1598";
|
|
@@ -99,7 +94,7 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
99
94
|
hook
|
|
100
95
|
});
|
|
101
96
|
const options = {
|
|
102
|
-
argv:
|
|
97
|
+
argv: fakeArgv({
|
|
103
98
|
internalUrl,
|
|
104
99
|
registryUrl,
|
|
105
100
|
enableMultiTenant,
|
|
@@ -117,7 +112,7 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
117
112
|
maxRetries: 0,
|
|
118
113
|
concurrency: concurrency
|
|
119
114
|
};
|
|
120
|
-
return
|
|
115
|
+
return minion(options).then(() => {
|
|
121
116
|
registryScope.done();
|
|
122
117
|
return true;
|
|
123
118
|
});
|
|
@@ -126,7 +121,7 @@ baseSpec_1.default("registry interactions:", (expressApp, _expressServer, listen
|
|
|
126
121
|
});
|
|
127
122
|
function reqHeaders(jwtSecret, userId) {
|
|
128
123
|
return {
|
|
129
|
-
"X-Magda-Session":
|
|
124
|
+
"X-Magda-Session": buildJwt(jwtSecret, userId)
|
|
130
125
|
};
|
|
131
126
|
}
|
|
132
127
|
function buildWebHook(id, internalUrl, aspects, optionalAspects) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.spec.js","sourceRoot":"","sources":["../../src/test/registry.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.spec.js","sourceRoot":"","sources":["../../src/test/registry.spec.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAKvF,OAAO,QAAQ,MAAM,iDAAiD,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAExF,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MA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IACjD,OAAO;QACH,iBAAiB,EAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KACjD,CAAC;AACN,CAAC;AAED,SAAS,YAAY,CACjB,EAAU,EACV,WAAmB,EACnB,OAAiB,EACjB,eAAyB;IAEzB,OAAO;QACH,EAAE,EAAE,EAAE;QACN,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,GAAG,WAAW,OAAO;QAC1B,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE;YACR,cAAc;YACd,wBAAwB;YACxB,oBAAoB;YACpB,aAAa;YACb,uBAAuB;YACvB,mBAAmB;SACtB;QACD,MAAM,EAAE;YACJ,OAAO,EAAE,OAAO;YAChB,eAAe,EAAE,eAAe;YAChC,aAAa,EAAE,KAAK;YACpB,wBAAwB,EAAE,KAAK;YAC/B,WAAW,EAAE,IAAI;YACjB,cAAc,EAAE,IAAI;SACvB;QACD,SAAS,EAAE,IAAI;QACf,oBAAoB,EAAE,KAAK;QAC3B,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,SAAS;KACtB,CAAC;AACN,CAAC"}
|
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const supertest_1 = __importDefault(require("supertest"));
|
|
16
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
17
|
-
const chai_1 = require("chai");
|
|
18
|
-
const arbitraries_1 = require("magda-typescript-common/src/test/arbitraries");
|
|
19
|
-
const jsverify_1 = __importDefault(require("magda-typescript-common/src/test/jsverify"));
|
|
20
|
-
const fakeArgv_1 = __importDefault(require("./fakeArgv"));
|
|
21
|
-
const baseSpec_1 = __importDefault(require("./baseSpec"));
|
|
22
|
-
const Crawler_1 = __importDefault(require("../Crawler"));
|
|
23
|
-
const setupRecrawlEndpoint_1 = __importDefault(require("../setupRecrawlEndpoint"));
|
|
24
|
-
baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, beforeEachProperty) => {
|
|
1
|
+
import request from "supertest";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { expect } from "chai";
|
|
4
|
+
import { lcAlphaNumStringArbNe } from "magda-typescript-common/src/test/arbitraries.js";
|
|
5
|
+
import jsc from "jsverify";
|
|
6
|
+
import fakeArgv from "./fakeArgv.js";
|
|
7
|
+
import baseSpec from "./baseSpec.js";
|
|
8
|
+
import Crawler from "../Crawler.js";
|
|
9
|
+
import setupRecrawlEndpoint from "../setupRecrawlEndpoint.js";
|
|
10
|
+
baseSpec("Recrawl APIs", (expressApp, expressServer, listenPort, beforeEachProperty) => {
|
|
25
11
|
it("POST /recrawl: should invoke Crawler.start() and response correct response", () => {
|
|
26
12
|
beforeEachProperty();
|
|
27
|
-
const crawler =
|
|
13
|
+
const crawler = sinon.createStubInstance(Crawler);
|
|
28
14
|
const app = expressApp();
|
|
29
15
|
app.listen(listenPort());
|
|
30
16
|
const server = expressServer();
|
|
31
17
|
const options = {
|
|
32
|
-
argv:
|
|
18
|
+
argv: fakeArgv({
|
|
33
19
|
internalUrl: "example",
|
|
34
20
|
registryUrl: "example",
|
|
35
21
|
enableMultiTenant: true,
|
|
@@ -49,8 +35,8 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
49
35
|
return Promise.resolve();
|
|
50
36
|
}
|
|
51
37
|
};
|
|
52
|
-
|
|
53
|
-
return
|
|
38
|
+
setupRecrawlEndpoint(app, options, crawler);
|
|
39
|
+
return request(server)
|
|
54
40
|
.post("/recrawl")
|
|
55
41
|
.send()
|
|
56
42
|
.expect(200, {
|
|
@@ -58,17 +44,17 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
58
44
|
isNewCrawler: true
|
|
59
45
|
})
|
|
60
46
|
.then(() => {
|
|
61
|
-
|
|
47
|
+
expect(crawler.start.callCount).to.equal(1);
|
|
62
48
|
});
|
|
63
49
|
});
|
|
64
|
-
it("2nd POST /recrawl should invoke not Crawler.start() and response correct response", () =>
|
|
50
|
+
it("2nd POST /recrawl should invoke not Crawler.start() and response correct response", async () => {
|
|
65
51
|
beforeEachProperty();
|
|
66
|
-
const crawler =
|
|
52
|
+
const crawler = sinon.createStubInstance(Crawler);
|
|
67
53
|
const app = expressApp();
|
|
68
54
|
app.listen(listenPort());
|
|
69
55
|
const server = expressServer();
|
|
70
56
|
const options = {
|
|
71
|
-
argv:
|
|
57
|
+
argv: fakeArgv({
|
|
72
58
|
internalUrl: "example",
|
|
73
59
|
registryUrl: "example",
|
|
74
60
|
enableMultiTenant: true,
|
|
@@ -88,7 +74,7 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
88
74
|
return Promise.resolve();
|
|
89
75
|
}
|
|
90
76
|
};
|
|
91
|
-
|
|
77
|
+
setupRecrawlEndpoint(app, options, crawler);
|
|
92
78
|
let isCrawling = false;
|
|
93
79
|
crawler.start.callsFake(() => {
|
|
94
80
|
isCrawling = true;
|
|
@@ -97,7 +83,7 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
97
83
|
crawler.isInProgress.callsFake(() => {
|
|
98
84
|
return isCrawling;
|
|
99
85
|
});
|
|
100
|
-
|
|
86
|
+
await request(server)
|
|
101
87
|
.post("/recrawl")
|
|
102
88
|
.send()
|
|
103
89
|
.expect(200, {
|
|
@@ -105,9 +91,9 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
105
91
|
isNewCrawler: true
|
|
106
92
|
})
|
|
107
93
|
.then(() => {
|
|
108
|
-
|
|
94
|
+
expect(crawler.start.callCount).to.equal(1);
|
|
109
95
|
});
|
|
110
|
-
|
|
96
|
+
await request(server)
|
|
111
97
|
.post("/recrawl")
|
|
112
98
|
.send()
|
|
113
99
|
.expect(200, {
|
|
@@ -116,18 +102,18 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
116
102
|
})
|
|
117
103
|
.then(() => {
|
|
118
104
|
// --- should still be 1 i.e. no calling this time
|
|
119
|
-
|
|
105
|
+
expect(crawler.start.callCount).to.equal(1);
|
|
120
106
|
});
|
|
121
|
-
})
|
|
107
|
+
});
|
|
122
108
|
it("GET/crawlerProgress: should invoke Crawler.getProgress() and response its return value in JSON", () => {
|
|
123
|
-
return
|
|
109
|
+
return jsc.assert(jsc.forall(lcAlphaNumStringArbNe, jsc.bool, jsc.nat, (crawlingPageToken, isCrawling, crawledRecordNumber) => {
|
|
124
110
|
beforeEachProperty();
|
|
125
|
-
const crawler =
|
|
111
|
+
const crawler = sinon.createStubInstance(Crawler);
|
|
126
112
|
const app = expressApp();
|
|
127
113
|
app.listen(listenPort());
|
|
128
114
|
const server = expressServer();
|
|
129
115
|
const options = {
|
|
130
|
-
argv:
|
|
116
|
+
argv: fakeArgv({
|
|
131
117
|
internalUrl: "example",
|
|
132
118
|
registryUrl: "example",
|
|
133
119
|
enableMultiTenant: true,
|
|
@@ -147,7 +133,7 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
147
133
|
return Promise.resolve();
|
|
148
134
|
}
|
|
149
135
|
};
|
|
150
|
-
|
|
136
|
+
setupRecrawlEndpoint(app, options, crawler);
|
|
151
137
|
crawler.getProgress.callsFake(() => {
|
|
152
138
|
return {
|
|
153
139
|
crawlingPageToken,
|
|
@@ -155,7 +141,7 @@ baseSpec_1.default("Recrawl APIs", (expressApp, expressServer, listenPort, befor
|
|
|
155
141
|
crawledRecordNumber
|
|
156
142
|
};
|
|
157
143
|
});
|
|
158
|
-
return
|
|
144
|
+
return request(server)
|
|
159
145
|
.get("/crawlerProgress")
|
|
160
146
|
.send()
|
|
161
147
|
.expect(200, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupRecrawlEndpoint.spec.js","sourceRoot":"","sources":["../../src/test/setupRecrawlEndpoint.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setupRecrawlEndpoint.spec.js","sourceRoot":"","sources":["../../src/test/setupRecrawlEndpoint.spec.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAC;AAGhC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,GAAG,MAAM,UAAU,CAAC;AAG3B,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,OAAO,MAAM,eAAe,CAAC;AACpC,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D,QAAQ,CACJ,cAAc,EACd,CACI,UAAiC,EACjC,aAA2B,EAC3B,UAAwB,EACxB,kBAA8B,EAChC,EAAE;IACA,EAAE,CAAC,4EAA4E,EAAE,GAAG,EAAE;QAClF,kBAAkB,EAAE,CAAC;QAErB,MAAM,OAAO,GAAG,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACzB,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;QAE/B,MAAM,OAA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WAAmB,EAAE,EAAE;oBACnC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;gBAC7B,CAAC;aACJ,CAAC;YAEF,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAE5C,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE;gBAC/B,OAAO;oBACH,iBAAiB;oBACjB,UAAU;oBACV,mBAAmB;iBACtB,CAAC;YACN,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC,MAAM,CAAC;iBACjB,GAAG,CAAC,kBAAkB,CAAC;iBACvB,IAAI,EAAE;iBACN,MAAM,CAAC,GAAG,EAAE;gBACT,SAAS,EAAE,IAAI;gBACf,QAAQ,EAAE;oBACN,iBAAiB;oBACjB,UAAU;oBACV,mBAAmB;iBACtB;aACJ,CAAC;iBACD,IAAI,CAAC,GAAG,EAAE;gBACP,OAAO,IAAI,CAAC;YAChB,CAAC,CAAC,CAAC;QACX,CAAC,CACJ,EACD,EAAE,CACL,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CACJ,CAAC"}
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const arbitraries_1 = require("magda-typescript-common/src/test/arbitraries");
|
|
12
|
-
const index_1 = __importDefault(require("../index"));
|
|
13
|
-
const fakeArgv_1 = __importDefault(require("./fakeArgv"));
|
|
14
|
-
const makePromiseQueryable_1 = __importDefault(require("./makePromiseQueryable"));
|
|
15
|
-
const baseSpec_1 = __importDefault(require("./baseSpec"));
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import nock from "nock";
|
|
4
|
+
import jsc from "jsverify";
|
|
5
|
+
import _ from "lodash";
|
|
6
|
+
import { lcAlphaNumStringArbNe, lcAlphaNumStringArb, recordArb } from "magda-typescript-common/src/test/arbitraries.js";
|
|
7
|
+
import minion from "../index.js";
|
|
8
|
+
import fakeArgv from "./fakeArgv.js";
|
|
9
|
+
import makePromiseQueryable from "./makePromiseQueryable.js";
|
|
10
|
+
import baseSpec from "./baseSpec.js";
|
|
16
11
|
const userId = "b1fddd6f-e230-4068-bd2c-1a21844f1598";
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
baseSpec("on startup", (expressApp, expressServer, listenPort, beforeEachProperty) => {
|
|
13
|
+
jsc.property("should properly crawl existing records if no webhook was found", lcAlphaNumStringArbNe, lcAlphaNumStringArbNe, jsc.array(jsc.nestring), jsc.array(jsc.nestring), jsc.array(recordArb), jsc.suchthat(jsc.integer, (int) => int > 0), lcAlphaNumStringArbNe, jsc.bool, (registryHost, tenantHost, aspects, optionalAspects, records, pageSize, jwtSecret, enableMultiTenant) => {
|
|
19
14
|
beforeEachProperty();
|
|
20
15
|
const registryUrl = `http://${registryHost}.com`;
|
|
21
16
|
const tenantUrl = `http://${tenantHost}.com`;
|
|
22
|
-
const registryScope =
|
|
23
|
-
const tenantScope =
|
|
17
|
+
const registryScope = nock(registryUrl);
|
|
18
|
+
const tenantScope = nock(tenantUrl);
|
|
24
19
|
registryScope.get(/\/hooks\/.*/).reply(404);
|
|
25
20
|
registryScope.put(/\/hooks\/.*/).reply(201);
|
|
26
21
|
tenantScope.get("/tenants").reply(200, []);
|
|
27
22
|
let index = 0;
|
|
28
|
-
const pages =
|
|
23
|
+
const pages = _.groupBy(records, (element) => {
|
|
29
24
|
return Math.floor(index++ / pageSize);
|
|
30
25
|
});
|
|
31
26
|
pages[index + 1] = [];
|
|
32
|
-
|
|
27
|
+
_.forEach(pages, (pageRecords, index) => {
|
|
33
28
|
registryScope
|
|
34
29
|
.get("/records")
|
|
35
30
|
.query((actualQuery) => {
|
|
@@ -58,7 +53,7 @@ baseSpec_1.default("on startup", (expressApp, expressServer, listenPort, beforeE
|
|
|
58
53
|
});
|
|
59
54
|
});
|
|
60
55
|
const options = {
|
|
61
|
-
argv:
|
|
56
|
+
argv: fakeArgv({
|
|
62
57
|
internalUrl: `http://example.com`,
|
|
63
58
|
registryUrl,
|
|
64
59
|
enableMultiTenant,
|
|
@@ -73,29 +68,29 @@ baseSpec_1.default("on startup", (expressApp, expressServer, listenPort, beforeE
|
|
|
73
68
|
writeAspectDefs: [],
|
|
74
69
|
express: expressApp,
|
|
75
70
|
maxRetries: 0,
|
|
76
|
-
onRecordFound:
|
|
71
|
+
onRecordFound: sinon
|
|
77
72
|
.stub()
|
|
78
73
|
.callsFake(() => Promise.resolve())
|
|
79
74
|
};
|
|
80
|
-
const minionPromise =
|
|
75
|
+
const minionPromise = makePromiseQueryable(minion(options));
|
|
81
76
|
return minionPromise.then(() => {
|
|
82
77
|
records.forEach((record) => {
|
|
83
|
-
|
|
78
|
+
expect(options.onRecordFound.calledWith(record));
|
|
84
79
|
});
|
|
85
80
|
return true;
|
|
86
81
|
});
|
|
87
82
|
});
|
|
88
83
|
const containsBlanks = (strings) => strings.some((string) => string === "");
|
|
89
|
-
|
|
90
|
-
port:
|
|
91
|
-
internalUrl:
|
|
92
|
-
id:
|
|
93
|
-
aspects:
|
|
94
|
-
optionalAspects:
|
|
95
|
-
jwtSecret:
|
|
96
|
-
registryUrl:
|
|
97
|
-
concurrency:
|
|
98
|
-
enableMultiTenant:
|
|
84
|
+
jsc.property("should handle bad inputs", jsc.suchthat(jsc.record({
|
|
85
|
+
port: jsc.integer,
|
|
86
|
+
internalUrl: lcAlphaNumStringArb,
|
|
87
|
+
id: lcAlphaNumStringArb,
|
|
88
|
+
aspects: jsc.array(lcAlphaNumStringArb),
|
|
89
|
+
optionalAspects: jsc.array(lcAlphaNumStringArb),
|
|
90
|
+
jwtSecret: lcAlphaNumStringArb,
|
|
91
|
+
registryUrl: lcAlphaNumStringArb,
|
|
92
|
+
concurrency: jsc.integer(0, 10),
|
|
93
|
+
enableMultiTenant: jsc.bool
|
|
99
94
|
}), (record) => record.port <= 0 ||
|
|
100
95
|
record.port >= 65535 ||
|
|
101
96
|
record.internalUrl === "" ||
|
|
@@ -106,7 +101,7 @@ baseSpec_1.default("on startup", (expressApp, expressServer, listenPort, beforeE
|
|
|
106
101
|
record.registryUrl === ""), ({ port, internalUrl, id, aspects, optionalAspects, jwtSecret, concurrency, enableMultiTenant }) => {
|
|
107
102
|
beforeEachProperty();
|
|
108
103
|
const options = {
|
|
109
|
-
argv:
|
|
104
|
+
argv: fakeArgv({
|
|
110
105
|
internalUrl: internalUrl,
|
|
111
106
|
listenPort: port,
|
|
112
107
|
registryUrl: "",
|
|
@@ -121,11 +116,11 @@ baseSpec_1.default("on startup", (expressApp, expressServer, listenPort, beforeE
|
|
|
121
116
|
writeAspectDefs: [],
|
|
122
117
|
express: expressApp,
|
|
123
118
|
concurrency,
|
|
124
|
-
onRecordFound:
|
|
119
|
+
onRecordFound: sinon
|
|
125
120
|
.stub()
|
|
126
121
|
.callsFake((record) => Promise.resolve())
|
|
127
122
|
};
|
|
128
|
-
return
|
|
123
|
+
return minion(options)
|
|
129
124
|
.then(() => false)
|
|
130
125
|
.catch(() => true);
|
|
131
126
|
});
|