@squiz/dxp-cli-next 5.5.1 → 5.6.0-develop.10

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.
Files changed (37) hide show
  1. package/lib/ApiService.d.ts +1 -1
  2. package/lib/ApiService.js +15 -8
  3. package/lib/ApiService.spec.js +15 -0
  4. package/lib/__tests__/integration/main.spec.js +17 -0
  5. package/lib/cmp/init.js +40 -2
  6. package/lib/dxp.js +4 -0
  7. package/lib/job-runner/index.d.ts +3 -0
  8. package/lib/job-runner/index.js +22 -0
  9. package/lib/job-runner/job/listJobs/listJobs.d.ts +3 -0
  10. package/lib/job-runner/job/listJobs/listJobs.js +64 -0
  11. package/lib/job-runner/job/listJobs/listJobs.spec.d.ts +1 -0
  12. package/lib/job-runner/job/listJobs/listJobs.spec.js +42 -0
  13. package/lib/job-runner/job/uploadJob/uploadJob.d.ts +3 -0
  14. package/lib/job-runner/job/uploadJob/uploadJob.js +52 -0
  15. package/lib/job-runner/job/uploadJob/uploadJob.spec.d.ts +1 -0
  16. package/lib/job-runner/job/uploadJob/uploadJob.spec.js +41 -0
  17. package/lib/job-runner/jobContext/listJobContexts.d.ts +3 -0
  18. package/lib/job-runner/jobContext/listJobContexts.js +71 -0
  19. package/lib/job-runner/jobContext/listJobContexts.spec.d.ts +1 -0
  20. package/lib/job-runner/jobContext/listJobContexts.spec.js +64 -0
  21. package/lib/job-runner/jobExecution/beginJob/beginJob.d.ts +3 -0
  22. package/lib/job-runner/jobExecution/beginJob/beginJob.js +66 -0
  23. package/lib/job-runner/jobExecution/beginJob/beginJob.spec.d.ts +1 -0
  24. package/lib/job-runner/jobExecution/beginJob/beginJob.spec.js +62 -0
  25. package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.d.ts +3 -0
  26. package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.js +65 -0
  27. package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.d.ts +1 -0
  28. package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.js +63 -0
  29. package/lib/job-runner/jobExecution/terminateJob/terminateJob.d.ts +3 -0
  30. package/lib/job-runner/jobExecution/terminateJob/terminateJob.js +62 -0
  31. package/lib/job-runner/jobExecution/terminateJob/terminateJob.spec.d.ts +1 -0
  32. package/lib/job-runner/jobExecution/terminateJob/terminateJob.spec.js +60 -0
  33. package/lib/job-runner/utils.d.ts +19 -0
  34. package/lib/job-runner/utils.js +144 -0
  35. package/lib/job-runner/utils.spec.d.ts +1 -0
  36. package/lib/job-runner/utils.spec.js +116 -0
  37. package/package.json +5 -2
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
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 utils_1 = require("./utils");
16
+ const commander_1 = require("commander");
17
+ const axios_1 = require("axios");
18
+ const chalk_1 = __importDefault(require("chalk"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {
21
+ return undefined;
22
+ }); // prevent process exit on error
23
+ const stderrSpy = jest.spyOn(process.stderr, 'write');
24
+ const logSpy = jest.spyOn(global.console, 'log');
25
+ beforeEach(() => {
26
+ jest.resetAllMocks();
27
+ });
28
+ describe('handleCommandError', () => {
29
+ it('correctly displays the console logs for command error', () => __awaiter(void 0, void 0, void 0, function* () {
30
+ const command = new commander_1.Command();
31
+ const message = 'Something bad happened';
32
+ (0, utils_1.handleCommandError)(command, new Error(message));
33
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
34
+ console.log(stderrSpy.mock.calls);
35
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
36
+ expect(stderrSpy.mock.calls[0][0]).toContain(message);
37
+ }));
38
+ it('correctly displays the console logs for axios error', () => __awaiter(void 0, void 0, void 0, function* () {
39
+ const command = new commander_1.Command();
40
+ const message = 'Something bad happened';
41
+ const responseMessage = 'I am an error response';
42
+ const errDetails = 'i am error details';
43
+ (0, utils_1.handleCommandError)(command, new axios_1.AxiosError(message, '500', undefined, undefined, {
44
+ data: { message: responseMessage, details: errDetails },
45
+ }));
46
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
47
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
48
+ expect(stderrSpy.mock.calls[0][0]).toContain(`${message}: ${responseMessage} - ${errDetails}`);
49
+ }));
50
+ it('correctly displays the console logs for error without a message', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ const command = new commander_1.Command();
52
+ (0, utils_1.handleCommandError)(command, new Error());
53
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
54
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
55
+ expect(stderrSpy.mock.calls[0][0]).toContain('An unknown error occurred');
56
+ }));
57
+ });
58
+ describe('writeLineSeparator', () => {
59
+ it('correctly displays the console logs for line separator', () => __awaiter(void 0, void 0, void 0, function* () {
60
+ (0, utils_1.writeLineSeparator)();
61
+ expect(logSpy).toHaveBeenCalledTimes(1);
62
+ expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
63
+ }));
64
+ });
65
+ describe('validateAxiosStatus', () => {
66
+ it('correctly validates the status', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ expect((0, utils_1.validateAxiosStatus)(200)).toBe(true);
68
+ expect((0, utils_1.validateAxiosStatus)(400)).toBe(false);
69
+ }));
70
+ });
71
+ describe('buildJobRunnerUrl', () => {
72
+ it('correctly builds the url with override set ', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const url = yield (0, utils_1.buildJobRunnerUrl)(undefined, 'http://localhost:9999/someTenant');
74
+ expect(url).toBe('http://localhost:9999/someTenant');
75
+ }));
76
+ });
77
+ describe('readInputFile', () => {
78
+ it('correctly reads the file ', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ const res = yield (0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/inputs/input.json'));
80
+ expect(res).toStrictEqual({ something: 'amazing' });
81
+ }));
82
+ it('errors if file extension is not .json', () => __awaiter(void 0, void 0, void 0, function* () {
83
+ yield expect((0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/simple-job/main.js'))).rejects.toThrow('Input must be a .json file');
84
+ }));
85
+ it('errors if file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ yield expect((0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/simple-job/input.json'))).rejects.toThrow('Input could not be found');
87
+ }));
88
+ it('errors if file has json extension but cannot be parsed', () => __awaiter(void 0, void 0, void 0, function* () {
89
+ const source = './src/__tests__/job-runner/inputs/badInput.json';
90
+ yield expect((0, utils_1.readInputFile)(path_1.default.join(source))).rejects.toThrow(`Unable to read file ${path_1.default.join(source)} - Unexpected token i in JSON at position 1`);
91
+ }));
92
+ });
93
+ describe('addPaginationToUrl', () => {
94
+ it('correctly adds the pagination size param to the url', () => __awaiter(void 0, void 0, void 0, function* () {
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?&page[size]=5');
97
+ }));
98
+ it('correctly adds the pagination params to the url', () => __awaiter(void 0, void 0, void 0, function* () {
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?&page[size]=5&page[before]=12345');
101
+ }));
102
+ it('correctly throws error for before and after params', () => __awaiter(void 0, void 0, void 0, function* () {
103
+ expect(() => {
104
+ (0, utils_1.addPaginationToUrl)('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?', { size: 'tiny', before: '12345', after: '54321' });
105
+ }).toThrow('Only one of before and after can be set');
106
+ }));
107
+ });
108
+ describe('logArrayResults', () => {
109
+ it('correctly logs results with links', () => __awaiter(void 0, void 0, void 0, function* () {
110
+ yield (0, utils_1.logArrayResults)([{ something: 'awesome' }, { somethingElse: 'also awesome' }], { next: 'page[after]=12345', prev: 'page[before]=1234' });
111
+ expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('something')}: "awesome"`);
112
+ expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: "also awesome"`);
113
+ expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('prevPageToken')}: 1234`);
114
+ expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('nextPageToken')}: 12345`);
115
+ }));
116
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.5.1",
3
+ "version": "5.6.0-develop.10",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
6
6
  },
@@ -39,12 +39,14 @@
39
39
  "codecov"
40
40
  ],
41
41
  "dependencies": {
42
- "@squiz/component-cli-lib": "1.22.0",
42
+ "@squiz/component-cli-lib": "^1.50.1-alpha",
43
43
  "axios": "1.1.3",
44
44
  "cli-color": "2.0.3",
45
45
  "commander": "9.4.0",
46
+ "dotenv": "^16.3.1",
46
47
  "env-paths": "2.2.1",
47
48
  "inquirer": "8.2.5",
49
+ "ora": "^5.4.1",
48
50
  "prompt": "^1.3.0",
49
51
  "tough-cookie": "4.1.2",
50
52
  "update-notifier": "5.1.0"
@@ -74,6 +76,7 @@
74
76
  "husky": "8.0.1",
75
77
  "jest": "28.1.3",
76
78
  "lint-staged": "13.0.3",
79
+ "nock": "^13.3.1",
77
80
  "prettier": "2.7.1",
78
81
  "semantic-release": "19.0.3",
79
82
  "ts-jest": "28.0.7",