@squiz/dxp-cli-next 5.15.0-develop.1 → 5.15.0-develop.3

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 (35) hide show
  1. package/lib/porter/constants.d.ts +2 -0
  2. package/lib/porter/constants.js +2 -0
  3. package/lib/porter/index.js +3 -1
  4. package/lib/porter/port/abort/abort.d.ts +3 -0
  5. package/lib/porter/port/abort/abort.js +77 -0
  6. package/lib/porter/port/abort/abort.spec.d.ts +1 -0
  7. package/lib/porter/port/abort/abort.spec.js +182 -0
  8. package/lib/porter/port/get/get.d.ts +3 -0
  9. package/lib/porter/port/get/get.js +93 -0
  10. package/lib/porter/port/get/get.spec.d.ts +1 -0
  11. package/lib/porter/port/get/get.spec.js +273 -0
  12. package/lib/porter/port/portCommand.d.ts +3 -0
  13. package/lib/porter/port/portCommand.js +19 -0
  14. package/lib/porter/port/start/start.d.ts +3 -0
  15. package/lib/porter/port/start/start.js +79 -0
  16. package/lib/porter/port/start/start.spec.d.ts +1 -0
  17. package/lib/porter/port/start/start.spec.js +198 -0
  18. package/lib/porter/project/add/add.js +6 -1
  19. package/lib/porter/project/add/add.spec.js +52 -99
  20. package/lib/porter/project/get/get.js +4 -9
  21. package/lib/porter/project/get/get.spec.js +47 -83
  22. package/lib/porter/project/projectCommand.js +1 -1
  23. package/lib/porter/project/remove/remove.js +1 -6
  24. package/lib/porter/project/remove/remove.spec.js +42 -77
  25. package/lib/porter/utils/ErrorUtils/ErrorUtils.js +4 -1
  26. package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.js +17 -2
  27. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.js +2 -1
  28. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.js +4 -3
  29. package/lib/porter/utils/GetProjectName/GetProjectName.d.ts +4 -0
  30. package/lib/porter/utils/GetProjectName/GetProjectName.js +30 -0
  31. package/lib/porter/utils/GetProjectName/GetProjectName.spec.d.ts +1 -0
  32. package/lib/porter/utils/GetProjectName/GetProjectName.spec.js +91 -0
  33. package/lib/porter/utils/index.d.ts +1 -0
  34. package/lib/porter/utils/index.js +1 -0
  35. package/package.json +2 -2
@@ -35,14 +35,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const nock_1 = __importDefault(require("nock"));
39
38
  const commander_1 = require("commander");
40
39
  const promises_1 = __importDefault(require("fs/promises"));
41
40
  const axios_1 = require("axios");
42
41
  const ApiService = __importStar(require("../../../ApiService"));
43
- const BuildPorterUrl = __importStar(require("../../utils/BuildPorterUrl/BuildPorterUrl"));
44
- const ErrorUtils = __importStar(require("../../utils/ErrorUtils/ErrorUtils"));
45
- const DoesPathExist = __importStar(require("../../utils/DoesPathExist/DoesPathExist"));
42
+ const PorterUtils = __importStar(require("../../utils"));
46
43
  const mockCliVersion = '1.2.3';
47
44
  jest.mock('../../../../package.json', () => {
48
45
  return {
@@ -57,6 +54,7 @@ jest.mock('fs/promises', () => {
57
54
  writeFile: jest.fn(),
58
55
  };
59
56
  });
57
+ jest.mock('../../utils');
60
58
  describe('addProject', () => {
61
59
  let projectName;
62
60
  let projectPath;
@@ -69,7 +67,6 @@ describe('addProject', () => {
69
67
  beforeEach(() => {
70
68
  jest.resetAllMocks();
71
69
  jest.clearAllMocks();
72
- nock_1.default.restore();
73
70
  projectName = 'porter-project';
74
71
  projectPath = 'tmp/project-dir';
75
72
  baseUrl = 'mock-url';
@@ -83,14 +80,18 @@ describe('addProject', () => {
83
80
  mockClient = {
84
81
  put: jest.fn().mockImplementationOnce(() => mockResponse),
85
82
  };
83
+ jest.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
86
84
  jest
87
- .spyOn(BuildPorterUrl, 'buildPorterUrl')
85
+ .spyOn(PorterUtils, 'doesPathExist')
86
+ .mockImplementationOnce(() => Promise.resolve(false));
87
+ jest
88
+ .spyOn(PorterUtils, 'buildPorterUrl')
88
89
  .mockImplementationOnce(mockBuildPorterUrl);
89
90
  jest
90
- .spyOn(ErrorUtils, 'handleCommandError')
91
+ .spyOn(PorterUtils, 'handleCommandError')
91
92
  .mockImplementationOnce(mockHandleCommandError);
92
93
  jest
93
- .spyOn(ErrorUtils, 'handleError')
94
+ .spyOn(PorterUtils, 'handleError')
94
95
  .mockImplementationOnce(mockHandleError);
95
96
  jest.spyOn(process, 'exit').mockImplementation();
96
97
  jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
@@ -105,8 +106,6 @@ describe('addProject', () => {
105
106
  const { default: createAddCommand } = require('./add');
106
107
  const program = createAddCommand();
107
108
  yield expect(() => program.parseAsync([
108
- 'dxp-next',
109
- 'porter',
110
109
  'project',
111
110
  'addProject',
112
111
  '--project-name',
@@ -119,18 +118,13 @@ describe('addProject', () => {
119
118
  it('should throw an error if not logged in', () => __awaiter(void 0, void 0, void 0, function* () {
120
119
  const mockError = new Error('Error not logged in');
121
120
  jest
122
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
121
+ .spyOn(PorterUtils, 'throwErrorIfNotLoggedIn')
123
122
  .mockImplementationOnce(() => {
124
123
  throw mockError;
125
124
  });
126
- (0, nock_1.default)('http://localhost:9999')
127
- .get('/__dxp/au/porter/SquizRoot-0000/health')
128
- .reply(401);
129
125
  const { default: createAddCommand } = require('./add');
130
126
  const program = createAddCommand();
131
127
  yield expect(() => program.parseAsync([
132
- 'dxp-next',
133
- 'porter',
134
128
  'project',
135
129
  'addProject',
136
130
  '--project-name',
@@ -141,23 +135,16 @@ describe('addProject', () => {
141
135
  const opts = program.opts();
142
136
  expect(opts.projectName).toEqual(projectName);
143
137
  expect(opts.path).toEqual(projectPath);
144
- expect(BuildPorterUrl.buildPorterUrl).not.toHaveBeenCalled();
138
+ expect(PorterUtils.buildPorterUrl).not.toHaveBeenCalled();
145
139
  }));
146
140
  it('should throw an error if project directory already exists', () => __awaiter(void 0, void 0, void 0, function* () {
147
141
  jest
148
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
149
- .mockImplementationOnce(() => Promise.resolve(undefined));
150
- jest
151
- .spyOn(DoesPathExist, 'doesPathExist')
142
+ .spyOn(PorterUtils, 'doesPathExist')
143
+ .mockReset()
152
144
  .mockImplementationOnce(() => Promise.resolve(true));
153
- (0, nock_1.default)('http://localhost:9999')
154
- .get('/__dxp/au/porter/SquizRoot-0000/health')
155
- .reply(200);
156
145
  const { default: createAddCommand } = require('./add');
157
146
  const program = createAddCommand();
158
147
  yield program.parseAsync([
159
- 'dxp-next',
160
- 'porter',
161
148
  'project',
162
149
  'addProject',
163
150
  '--project-name',
@@ -168,28 +155,18 @@ describe('addProject', () => {
168
155
  const opts = program.opts();
169
156
  expect(opts.projectName).toEqual(projectName);
170
157
  expect(opts.path).toEqual(projectPath);
171
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
172
- expect(DoesPathExist.doesPathExist).toHaveBeenCalled();
173
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
158
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
159
+ expect(PorterUtils.doesPathExist).toHaveBeenCalled();
160
+ expect(mockClient.put).not.toHaveBeenCalled();
161
+ expect(PorterUtils.handleCommandError).toHaveBeenCalled();
174
162
  }));
175
163
  it('should throw an error if parent directory does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
176
- jest
177
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
178
- .mockImplementationOnce(() => Promise.resolve(undefined));
179
- jest
180
- .spyOn(DoesPathExist, 'doesPathExist')
181
- .mockImplementationOnce(() => Promise.resolve(false));
182
164
  jest.spyOn(promises_1.default, 'access').mockImplementationOnce(() => {
183
165
  throw new Error();
184
166
  });
185
- (0, nock_1.default)('http://localhost:9999')
186
- .get('/__dxp/au/porter/SquizRoot-0000/health')
187
- .reply(200);
188
167
  const { default: createAddCommand } = require('./add');
189
168
  const program = createAddCommand();
190
169
  yield program.parseAsync([
191
- 'dxp-next',
192
- 'porter',
193
170
  'project',
194
171
  'addProject',
195
172
  '--project-name',
@@ -200,31 +177,21 @@ describe('addProject', () => {
200
177
  const opts = program.opts();
201
178
  expect(opts.projectName).toEqual(projectName);
202
179
  expect(opts.path).toEqual(projectPath);
203
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
204
- expect(DoesPathExist.doesPathExist).toHaveBeenCalled();
180
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
181
+ expect(PorterUtils.doesPathExist).toHaveBeenCalled();
205
182
  expect(promises_1.default.access).toHaveBeenCalled();
206
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
183
+ expect(mockClient.put).not.toHaveBeenCalled();
184
+ expect(PorterUtils.handleCommandError).toHaveBeenCalled();
207
185
  }));
208
186
  it('should clean up the directory if project already exists', () => __awaiter(void 0, void 0, void 0, function* () {
209
- jest
210
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
211
- .mockImplementationOnce(() => Promise.resolve(undefined));
212
- jest
213
- .spyOn(DoesPathExist, 'doesPathExist')
214
- .mockImplementationOnce(() => Promise.resolve(false));
215
187
  mockClient.put = jest.fn(() => {
216
188
  throw new axios_1.AxiosError('Project already exists', '409', undefined, undefined, {
217
189
  data: { status: 409 },
218
190
  });
219
191
  });
220
- (0, nock_1.default)('http://localhost:9999')
221
- .get('/__dxp/au/porter/SquizRoot-0000/health')
222
- .reply(200);
223
192
  const { default: createAddCommand } = require('./add');
224
193
  const program = createAddCommand();
225
194
  yield program.parseAsync([
226
- 'dxp-next',
227
- 'porter',
228
195
  'project',
229
196
  'addProject',
230
197
  '--project-name',
@@ -235,34 +202,25 @@ describe('addProject', () => {
235
202
  const opts = program.opts();
236
203
  expect(opts.projectName).toEqual(projectName);
237
204
  expect(opts.path).toEqual(projectPath);
238
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
239
- expect(DoesPathExist.doesPathExist).toHaveBeenCalled();
205
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
206
+ expect(PorterUtils.doesPathExist).toHaveBeenCalled();
240
207
  expect(promises_1.default.access).toHaveBeenCalled();
241
- // Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
242
- expect(promises_1.default.mkdir).toHaveBeenCalledTimes(7);
243
- // Create project config.json as well as 5 example config.json (for each stage)
244
- expect(promises_1.default.writeFile).toHaveBeenCalledTimes(6);
208
+ // Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, report)
209
+ // But validation stage is not created (PERSONIZE-771)
210
+ expect(promises_1.default.mkdir).toHaveBeenCalledTimes(6);
211
+ // Create project config.json as well as 4 example config.json (for each stage)
212
+ // But validation stage is not created (PERSONIZE-771)
213
+ expect(promises_1.default.writeFile).toHaveBeenCalledTimes(5);
245
214
  expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
246
215
  expect(mockClient.put).toHaveBeenCalled();
247
216
  expect(promises_1.default.rm).toHaveBeenCalled();
248
- expect(ErrorUtils.handleError).toHaveBeenCalled();
249
- expect(ErrorUtils.handleCommandError).not.toHaveBeenCalled();
217
+ expect(PorterUtils.handleError).toHaveBeenCalled();
218
+ expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
250
219
  }));
251
220
  it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
252
- jest
253
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
254
- .mockImplementationOnce(() => Promise.resolve(undefined));
255
- jest
256
- .spyOn(DoesPathExist, 'doesPathExist')
257
- .mockImplementationOnce(() => Promise.resolve(false));
258
- (0, nock_1.default)('http://localhost:9999')
259
- .get('/__dxp/au/porter/SquizRoot-0000/health')
260
- .reply(200);
261
221
  const { default: createAddCommand } = require('./add');
262
222
  const program = createAddCommand();
263
223
  yield program.parseAsync([
264
- 'dxp-next',
265
- 'porter',
266
224
  'project',
267
225
  'addProject',
268
226
  '--project-name',
@@ -273,35 +231,23 @@ describe('addProject', () => {
273
231
  const opts = program.opts();
274
232
  expect(opts.projectName).toEqual(projectName);
275
233
  expect(opts.path).toEqual(projectPath);
276
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
277
- expect(DoesPathExist.doesPathExist).toHaveBeenCalled();
234
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
235
+ expect(PorterUtils.doesPathExist).toHaveBeenCalled();
278
236
  expect(promises_1.default.access).toHaveBeenCalled();
279
237
  // Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
280
- expect(promises_1.default.mkdir).toHaveBeenCalledTimes(7);
281
- // Create project config.json as well as 5 example config.json (for each stage)
282
- expect(promises_1.default.writeFile).toHaveBeenCalledTimes(6);
238
+ // But validation stage is not created (PERSONIZE-771)
239
+ expect(promises_1.default.mkdir).toHaveBeenCalledTimes(6);
240
+ // Create project config.json as well as 4 example config.json (for each stage)
241
+ // But validation stage is not created (PERSONIZE-771)
242
+ expect(promises_1.default.writeFile).toHaveBeenCalledTimes(5);
283
243
  expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
284
244
  expect(mockClient.put).toHaveBeenCalled();
285
- expect(ErrorUtils.handleCommandError).not.toHaveBeenCalled();
245
+ expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
286
246
  }));
287
247
  it('should successfully initialise the project directory and the porter project', () => __awaiter(void 0, void 0, void 0, function* () {
288
- jest
289
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
290
- .mockImplementationOnce(() => Promise.resolve(undefined));
291
- jest
292
- .spyOn(DoesPathExist, 'doesPathExist')
293
- .mockImplementationOnce(() => Promise.resolve(false));
294
- jest.spyOn(promises_1.default, 'mkdir').mockImplementationOnce(() => {
295
- throw new Error('mock error');
296
- });
297
- (0, nock_1.default)('http://localhost:9999')
298
- .get('/__dxp/au/porter/SquizRoot-0000/health')
299
- .reply(200);
300
248
  const { default: createAddCommand } = require('./add');
301
249
  const program = createAddCommand();
302
250
  yield program.parseAsync([
303
- 'dxp-next',
304
- 'porter',
305
251
  'project',
306
252
  'addProject',
307
253
  '--project-name',
@@ -312,12 +258,19 @@ describe('addProject', () => {
312
258
  const opts = program.opts();
313
259
  expect(opts.projectName).toEqual(projectName);
314
260
  expect(opts.path).toEqual(projectPath);
315
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
316
- expect(DoesPathExist.doesPathExist).toHaveBeenCalled();
261
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
262
+ expect(PorterUtils.doesPathExist).toHaveBeenCalled();
317
263
  expect(promises_1.default.access).toHaveBeenCalled();
318
- expect(promises_1.default.mkdir).toHaveBeenCalledTimes(1);
319
- expect(promises_1.default.writeFile).not.toHaveBeenCalled();
320
- expect(mockClient.put).not.toHaveBeenCalled();
321
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
264
+ // Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
265
+ // But validation stage is not created (PERSONIZE-771)
266
+ expect(promises_1.default.mkdir).toHaveBeenCalledTimes(6);
267
+ // Create project config.json as well as 4 example config.json (for each stage)
268
+ // But validation stage is not created (PERSONIZE-771)
269
+ expect(promises_1.default.writeFile).toHaveBeenCalledTimes(5);
270
+ expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
271
+ expect(mockClient.put).toHaveBeenCalled();
272
+ expect(promises_1.default.rm).not.toHaveBeenCalled();
273
+ expect(PorterUtils.handleError).not.toHaveBeenCalled();
274
+ expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
322
275
  }));
323
276
  });
@@ -17,7 +17,6 @@ const chalk_1 = __importDefault(require("chalk"));
17
17
  const ora_1 = __importDefault(require("ora"));
18
18
  const ApiService_1 = require("../../../ApiService");
19
19
  const utils_1 = require("../../utils");
20
- const constants_1 = require("../../constants");
21
20
  const createGetProjectCommand = () => {
22
21
  const getCommand = new commander_1.Command('getProject')
23
22
  .description('Retrieves the project')
@@ -33,21 +32,17 @@ const createGetProjectCommand = () => {
33
32
  let projectName = '';
34
33
  const spinner = (0, ora_1.default)();
35
34
  try {
36
- const projectConfig = yield (0, utils_1.getProjectConfig)();
37
- projectName = projectConfig.projectName;
38
- if (!projectName) {
39
- throw new Error(constants_1.PORTER_ERRORS.projectNameMissing);
40
- }
35
+ projectName = yield (0, utils_1.getProjectName)();
41
36
  spinner.start('Retrieving project..');
42
37
  const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
43
38
  const response = yield apiService.client.get(`/projects/${projectName}`);
44
39
  const jsonResponse = response.data;
45
- (0, utils_1.logDebug)(jsonResponse);
40
+ (0, utils_1.logDebug)(JSON.stringify(jsonResponse));
46
41
  spinner.succeed();
47
42
  console.log('');
48
43
  console.log(`Project name: ${projectName}`);
49
- console.log(`Download last port report: ${jsonResponse['report-link'] || 'Not generated'}`);
50
- console.log(`Download last port artifacts: ${jsonResponse['artifacts-link'] || 'Not generated'}`);
44
+ console.log(`Download last port report: ${jsonResponse['last-report-link'] || 'Not generated'}`);
45
+ console.log(`Download last port artifacts: ${jsonResponse['last-artifacts-link'] || 'Not generated'}`);
51
46
  }
52
47
  catch (error) {
53
48
  (0, utils_1.logDebug)(`ERROR: ${error instanceof Error ? `${error.message}` : JSON.stringify(error)}`);
@@ -31,22 +31,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
34
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const nock_1 = __importDefault(require("nock"));
39
- const get_1 = __importDefault(require("./get"));
40
35
  const axios_1 = require("axios");
41
36
  const ApiService = __importStar(require("../../../ApiService"));
42
- const BuildPorterUrl = __importStar(require("../../utils/BuildPorterUrl/BuildPorterUrl"));
43
- const ErrorUtils = __importStar(require("../../utils/ErrorUtils/ErrorUtils"));
44
- const GetProjectConfig = __importStar(require("../../utils/GetProjectConfig/GetProjectConfig"));
37
+ const PorterUtils = __importStar(require("../../utils"));
45
38
  const logSpy = jest.spyOn(global.console, 'log');
39
+ jest.mock('../../utils');
46
40
  describe('getProject', () => {
47
41
  let baseUrl;
48
42
  let projectName;
49
- let projectConfig;
50
43
  let mockHandleCommandError;
51
44
  let mockHandleError;
52
45
  let mockBuildPorterUrl;
@@ -55,14 +48,8 @@ describe('getProject', () => {
55
48
  beforeEach(() => {
56
49
  jest.resetAllMocks();
57
50
  jest.clearAllMocks();
58
- nock_1.default.restore();
59
51
  projectName = 'porter-project';
60
52
  baseUrl = 'mock-url';
61
- projectConfig = {
62
- service: 'dxp-porter',
63
- projectName,
64
- version: '0.1.0',
65
- };
66
53
  mockHandleCommandError = jest.fn(() => Promise.resolve());
67
54
  mockHandleError = jest.fn();
68
55
  mockBuildPorterUrl = jest.fn(() => Promise.resolve(baseUrl));
@@ -73,14 +60,18 @@ describe('getProject', () => {
73
60
  mockClient = {
74
61
  get: jest.fn().mockImplementationOnce(() => mockResponse),
75
62
  };
63
+ jest.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
64
+ jest
65
+ .spyOn(PorterUtils, 'getProjectName')
66
+ .mockImplementationOnce(() => Promise.resolve(projectName));
76
67
  jest
77
- .spyOn(BuildPorterUrl, 'buildPorterUrl')
68
+ .spyOn(PorterUtils, 'buildPorterUrl')
78
69
  .mockImplementationOnce(mockBuildPorterUrl);
79
70
  jest
80
- .spyOn(ErrorUtils, 'handleCommandError')
71
+ .spyOn(PorterUtils, 'handleCommandError')
81
72
  .mockImplementationOnce(mockHandleCommandError);
82
73
  jest
83
- .spyOn(ErrorUtils, 'handleError')
74
+ .spyOn(PorterUtils, 'handleError')
84
75
  .mockImplementationOnce(mockHandleError);
85
76
  jest.spyOn(process, 'exit').mockImplementation();
86
77
  jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
@@ -92,47 +83,34 @@ describe('getProject', () => {
92
83
  it('should throw an error if not logged in', () => __awaiter(void 0, void 0, void 0, function* () {
93
84
  const mockError = new Error('Error not logged in');
94
85
  jest
95
- .spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
96
- .mockImplementationOnce(() => {
86
+ .spyOn(PorterUtils, 'throwErrorIfNotLoggedIn')
87
+ .mockImplementation(() => {
97
88
  throw mockError;
98
89
  });
99
- (0, nock_1.default)('http://localhost:9999')
100
- .get('/__dxp/au/porter/SquizRoot-0000/health')
101
- .reply(401);
102
- const program = (0, get_1.default)();
103
- yield expect(() => program.parseAsync(['dxp-next', 'porter', 'project', 'getProject'])).rejects.toThrow(mockError);
90
+ const { default: createGetCommand } = require('./get');
91
+ const program = createGetCommand();
92
+ yield expect(() => program.parseAsync(['project', 'getProject'])).rejects.toThrow(mockError);
104
93
  const opts = program.opts();
105
94
  expect(opts).toStrictEqual({});
95
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
96
+ expect(PorterUtils.buildPorterUrl).not.toHaveBeenCalled();
106
97
  }));
107
- it('should throw an error if not in a project directory', () => __awaiter(void 0, void 0, void 0, function* () {
108
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
98
+ it('should throw an error if project name could not be found', () => __awaiter(void 0, void 0, void 0, function* () {
109
99
  jest
110
- .spyOn(GetProjectConfig, 'getProjectConfig')
111
- .mockImplementationOnce(() => {
112
- throw new Error('You must be within a porter project directory to use this command');
100
+ .spyOn(PorterUtils, 'getProjectName')
101
+ .mockReset()
102
+ .mockImplementation(() => {
103
+ throw new Error();
113
104
  });
114
105
  const { default: createGetCommand } = require('./get');
115
106
  const program = createGetCommand();
116
107
  yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
117
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
118
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
119
- }));
120
- it('should throw an error if project name is missing in the config.json file', () => __awaiter(void 0, void 0, void 0, function* () {
121
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
122
- jest
123
- .spyOn(GetProjectConfig, 'getProjectConfig')
124
- .mockImplementationOnce(() => Promise.resolve(Object.assign(Object.assign({}, projectConfig), { projectName: '' })));
125
- const { default: createGetCommand } = require('./get');
126
- const program = createGetCommand();
127
- yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
128
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
129
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
108
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
109
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
110
+ expect(mockClient.get).not.toHaveBeenCalled();
111
+ expect(PorterUtils.handleCommandError).toHaveBeenCalled();
130
112
  }));
131
113
  it('should throw an error if the project does not exist in the cloud', () => __awaiter(void 0, void 0, void 0, function* () {
132
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
133
- jest
134
- .spyOn(GetProjectConfig, 'getProjectConfig')
135
- .mockImplementationOnce(() => Promise.resolve(projectConfig));
136
114
  mockClient.get = jest.fn(() => {
137
115
  throw new axios_1.AxiosError('Project does not exist', '404', undefined, undefined, {
138
116
  data: { status: 404 },
@@ -140,16 +118,13 @@ describe('getProject', () => {
140
118
  });
141
119
  const { default: createGetCommand } = require('./get');
142
120
  const program = createGetCommand();
143
- yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
144
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
121
+ yield program.parseAsync(['project', 'getProject']);
122
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
123
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
145
124
  expect(mockClient.get).toHaveBeenCalled();
146
- expect(ErrorUtils.handleError).toHaveBeenCalled();
125
+ expect(PorterUtils.handleError).toHaveBeenCalled();
147
126
  }));
148
127
  it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
149
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
150
- jest
151
- .spyOn(GetProjectConfig, 'getProjectConfig')
152
- .mockImplementationOnce(() => Promise.resolve(projectConfig));
153
128
  mockClient.get = jest.fn(() => {
154
129
  throw new axios_1.AxiosError('Internal server error', '500', undefined, undefined, {
155
130
  data: { status: 500 },
@@ -157,23 +132,17 @@ describe('getProject', () => {
157
132
  });
158
133
  const { default: createGetCommand } = require('./get');
159
134
  const program = createGetCommand();
160
- yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
161
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
135
+ yield program.parseAsync(['project', 'getProject']);
136
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
137
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
162
138
  expect(mockClient.get).toHaveBeenCalled();
163
- expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
139
+ expect(PorterUtils.handleCommandError).toHaveBeenCalled();
164
140
  }));
165
141
  it('should successfully retrieve the project details (without generated links) and log this to the console', () => __awaiter(void 0, void 0, void 0, function* () {
166
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
167
- jest
168
- .spyOn(GetProjectConfig, 'getProjectConfig')
169
- .mockImplementationOnce(() => Promise.resolve(projectConfig));
170
142
  const mockGetResponse = {
171
- portid: '1234-5678-abcd-efgh',
172
- stages: {},
173
- status: {},
174
- 'artifacts-link': null,
175
- 'report-link': null,
176
- 'stage-settings': {},
143
+ projectid: projectName,
144
+ 'last-artifacts-link': null,
145
+ 'last-report-link': null,
177
146
  };
178
147
  mockResponse = {
179
148
  data: mockGetResponse,
@@ -181,28 +150,22 @@ describe('getProject', () => {
181
150
  };
182
151
  const { default: createGetCommand } = require('./get');
183
152
  const program = createGetCommand();
184
- yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
185
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
153
+ yield program.parseAsync(['project', 'getProject']);
154
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
155
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
186
156
  expect(mockClient.get).toHaveBeenCalled();
187
- expect(ErrorUtils.handleCommandError).not.toHaveBeenCalled();
157
+ expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
188
158
  expect(logSpy).toHaveBeenNthCalledWith(2, `Project name: ${projectName}`);
189
159
  expect(logSpy).toHaveBeenNthCalledWith(3, 'Download last port report: Not generated');
190
160
  expect(logSpy).toHaveBeenNthCalledWith(4, 'Download last port artifacts: Not generated');
191
161
  }));
192
162
  it('should successfully retrieve the project details and log this to the console', () => __awaiter(void 0, void 0, void 0, function* () {
193
- jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
194
- jest
195
- .spyOn(GetProjectConfig, 'getProjectConfig')
196
- .mockImplementationOnce(() => Promise.resolve(projectConfig));
197
163
  const mockReportLink = 'mock-report-link';
198
164
  const mockArtifactsLink = 'mock-artifacts-link';
199
165
  const mockGetResponse = {
200
- portid: '1234-5678-abcd-efgh',
201
- stages: {},
202
- status: {},
203
- 'artifacts-link': mockArtifactsLink,
204
- 'report-link': mockReportLink,
205
- 'stage-settings': {},
166
+ projectid: '1234-5678-abcd-efgh',
167
+ 'last-artifacts-link': mockArtifactsLink,
168
+ 'last-report-link': mockReportLink,
206
169
  };
207
170
  mockResponse = {
208
171
  data: mockGetResponse,
@@ -210,10 +173,11 @@ describe('getProject', () => {
210
173
  };
211
174
  const { default: createGetCommand } = require('./get');
212
175
  const program = createGetCommand();
213
- yield program.parseAsync(['dxp-next', 'porter', 'project', 'getProject']);
214
- expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
176
+ yield program.parseAsync(['project', 'getProject']);
177
+ expect(PorterUtils.throwErrorIfNotLoggedIn).toHaveBeenCalled();
178
+ expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
215
179
  expect(mockClient.get).toHaveBeenCalled();
216
- expect(ErrorUtils.handleCommandError).not.toHaveBeenCalled();
180
+ expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
217
181
  expect(logSpy).toHaveBeenNthCalledWith(2, `Project name: ${projectName}`);
218
182
  expect(logSpy).toHaveBeenNthCalledWith(3, `Download last port report: ${mockReportLink}`);
219
183
  expect(logSpy).toHaveBeenNthCalledWith(4, `Download last port artifacts: ${mockArtifactsLink}`);
@@ -11,8 +11,8 @@ const createProjectCommand = () => {
11
11
  const projectCommand = new commander_1.Command('project');
12
12
  projectCommand
13
13
  .description('Porter project commands')
14
- .addCommand((0, get_1.default)())
15
14
  .addCommand((0, add_1.default)())
15
+ .addCommand((0, get_1.default)())
16
16
  .addCommand((0, remove_1.default)());
17
17
  return projectCommand;
18
18
  };
@@ -18,7 +18,6 @@ const inquirer_1 = require("inquirer");
18
18
  const ora_1 = __importDefault(require("ora"));
19
19
  const ApiService_1 = require("../../../ApiService");
20
20
  const utils_1 = require("../../utils");
21
- const constants_1 = require("../../constants");
22
21
  const createRemoveProjectCommand = () => {
23
22
  const removeCommand = new commander_1.Command('removeProject')
24
23
  .description('Deletes the project')
@@ -34,11 +33,7 @@ const createRemoveProjectCommand = () => {
34
33
  let projectName = '';
35
34
  const spinner = (0, ora_1.default)();
36
35
  try {
37
- const projectConfig = yield (0, utils_1.getProjectConfig)();
38
- projectName = projectConfig.projectName;
39
- if (!projectName) {
40
- throw new Error(constants_1.PORTER_ERRORS.projectNameMissing);
41
- }
36
+ projectName = yield (0, utils_1.getProjectName)();
42
37
  const confirmation = yield (0, inquirer_1.prompt)({
43
38
  message: `Are you sure you wish to remove all data about the project "${projectName}" from the cloud permanently? [y/N]`,
44
39
  name: 'answer',