@squiz/dxp-cli-next 5.23.1-develop.1 → 5.23.1-develop.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.
- package/lib/job-runner/job/listJobs/listJobs.spec.js +1 -2
- package/lib/job-runner/jobContext/listJobContexts.js +3 -10
- package/lib/job-runner/jobContext/listJobContexts.spec.js +1 -8
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.js +1 -1
- package/lib/job-runner/utils.js +11 -10
- package/lib/job-runner/utils.spec.js +2 -2
- package/package.json +1 -1
|
@@ -14,12 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nock_1 = __importDefault(require("nock"));
|
|
16
16
|
const listJobs_1 = __importDefault(require("./listJobs"));
|
|
17
|
-
const logSpy = jest.spyOn(global.console, 'log');
|
|
18
17
|
describe('listJobs', () => {
|
|
19
18
|
it('correctly lists the job', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
19
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
20
|
(0, nock_1.default)('http://localhost:9999')
|
|
22
|
-
.get('/job/latest?&page
|
|
21
|
+
.get('/job/latest?&page%5Bsize%5D=5')
|
|
23
22
|
.reply(200, [{ name: 'simple-job', type: 'job', version: '1.0.0' }]);
|
|
24
23
|
const program = (0, listJobs_1.default)();
|
|
25
24
|
yield program.parseAsync([
|
|
@@ -44,16 +44,9 @@ const createListJobContextsCommand = () => {
|
|
|
44
44
|
size: options.size,
|
|
45
45
|
});
|
|
46
46
|
const res = yield apiService.client.get(listJobContextsUrl);
|
|
47
|
-
if (Array.isArray(res.data) && res.data.length > 0) {
|
|
48
|
-
spinner.succeed(
|
|
49
|
-
(0, utils_1.
|
|
50
|
-
res.data.forEach((context) => {
|
|
51
|
-
console.log(`${chalk_1.default.green(chalk_1.default.bold(context.contextName))}: ${chalk_1.default.green(context.description)}`);
|
|
52
|
-
for (const [key, value] of Object.entries(context.environment)) {
|
|
53
|
-
console.log(`${chalk_1.default.bold(key)}: ${JSON.stringify(value)}`);
|
|
54
|
-
}
|
|
55
|
-
(0, utils_1.writeLineSeparator)();
|
|
56
|
-
});
|
|
47
|
+
if (Array.isArray(res.data.data) && res.data.data.length > 0) {
|
|
48
|
+
spinner.succeed(`Retrieved ${res.data.data.length} job contexts`);
|
|
49
|
+
yield (0, utils_1.logArrayResults)(res.data.data, res.data.links);
|
|
57
50
|
}
|
|
58
51
|
else {
|
|
59
52
|
spinner.succeed('No job contexts found');
|
|
@@ -14,13 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nock_1 = __importDefault(require("nock"));
|
|
16
16
|
const listJobContexts_1 = __importDefault(require("./listJobContexts"));
|
|
17
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
17
|
describe('listJobContexts', () => {
|
|
20
18
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
19
|
it('correctly lists the job contexts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
20
|
(0, nock_1.default)('http://localhost:9999')
|
|
23
|
-
.get('/job-context?')
|
|
21
|
+
.get('/job-context?page%5Bsize%5D=20')
|
|
24
22
|
.reply(200, [
|
|
25
23
|
{
|
|
26
24
|
contextName: 'dev',
|
|
@@ -55,10 +53,5 @@ describe('listJobContexts', () => {
|
|
|
55
53
|
const opts = program.opts();
|
|
56
54
|
expect(opts.tenant).toEqual('myTenant');
|
|
57
55
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
58
|
-
expect(logSpy).toHaveBeenCalledTimes(9);
|
|
59
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.green(chalk_1.default.bold('dev'))}: ${chalk_1.default.green('dev context')}`);
|
|
60
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('something')}: ${JSON.stringify('cool')}`);
|
|
61
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: ${JSON.stringify('cooler')}`);
|
|
62
|
-
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
63
56
|
}));
|
|
64
57
|
});
|
|
@@ -19,7 +19,7 @@ describe('listJobExecutions', () => {
|
|
|
19
19
|
it('correctly lists the job executions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
21
|
(0, nock_1.default)('http://localhost:9999')
|
|
22
|
-
.get('/executions/jobName/job-runner?&page
|
|
22
|
+
.get('/executions/jobName/job-runner?&page%5Bsize%5D=5')
|
|
23
23
|
.reply(200, [
|
|
24
24
|
{
|
|
25
25
|
context: 'dev',
|
package/lib/job-runner/utils.js
CHANGED
|
@@ -96,19 +96,20 @@ function addPaginationToUrl(url, opts) {
|
|
|
96
96
|
if (opts.before && opts.after) {
|
|
97
97
|
throw new Error('Only one of before and after can be set');
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const parsedUrl = new URL(url);
|
|
100
|
+
const params = parsedUrl.searchParams;
|
|
101
|
+
// Set page size
|
|
102
|
+
params.set('page[size]', opts.size
|
|
103
|
+
? `${PaginationPageLimit[opts.size]}`
|
|
104
|
+
: `${PaginationPageLimit.small}`);
|
|
105
|
+
// Set pagination parameters
|
|
105
106
|
if (opts.before) {
|
|
106
|
-
|
|
107
|
+
params.set('page[before]', opts.before);
|
|
107
108
|
}
|
|
108
|
-
if (opts.after) {
|
|
109
|
-
|
|
109
|
+
else if (opts.after) {
|
|
110
|
+
params.set('page[after]', opts.after);
|
|
110
111
|
}
|
|
111
|
-
return
|
|
112
|
+
return parsedUrl.toString();
|
|
112
113
|
}
|
|
113
114
|
exports.addPaginationToUrl = addPaginationToUrl;
|
|
114
115
|
function logArrayResults(results, links) {
|
|
@@ -93,11 +93,11 @@ describe('readInputFile', () => {
|
|
|
93
93
|
describe('addPaginationToUrl', () => {
|
|
94
94
|
it('correctly adds the pagination size param to the url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
95
|
const url = (0, utils_1.addPaginationToUrl)('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?', { size: 'tiny', before: '', after: '' });
|
|
96
|
-
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest
|
|
96
|
+
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?page%5Bsize%5D=5');
|
|
97
97
|
}));
|
|
98
98
|
it('correctly adds the pagination params to the url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
99
|
const url = (0, utils_1.addPaginationToUrl)('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?', { size: 'tiny', before: '12345', after: '' });
|
|
100
|
-
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest
|
|
100
|
+
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?page%5Bsize%5D=5&page%5Bbefore%5D=12345');
|
|
101
101
|
}));
|
|
102
102
|
it('correctly throws error for before and after params', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
103
|
expect(() => {
|