@squiz/dxp-cli-next 5.15.0 → 5.16.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.
@@ -7,4 +7,5 @@ export declare const PORTER_ERRORS: {
7
7
  projectDirectoryInvalid: string;
8
8
  portIdBlankError: string;
9
9
  loginError: string;
10
+ loginPermissionError: string;
10
11
  };
@@ -9,5 +9,6 @@ exports.PORTER_ERRORS = {
9
9
  projectNameMissing: 'Project name is missing from the config.json file',
10
10
  projectDirectoryInvalid: 'You must be within a porter project directory to use this command',
11
11
  portIdBlankError: 'Cannot be blank.',
12
- loginError: 'To use this service you must be logged in as a DXP super admin, Squiz support staff or be assigned the Migration Agent secondary role for the selected tenant',
12
+ loginError: 'You must login to interact with the porter service. See `dxp-next auth login`',
13
+ loginPermissionError: 'To use this service you must be logged in as a DXP super admin, Squiz support staff or be assigned the Migration Agent secondary role for the selected tenant. See `dxp-next auth login`',
13
14
  };
@@ -4,11 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = require("commander");
7
- const portCommand_1 = __importDefault(require("./port/portCommand"));
8
- const projectCommand_1 = __importDefault(require("./project/projectCommand"));
7
+ const abort_1 = __importDefault(require("./port/abort/abort"));
8
+ const get_1 = __importDefault(require("./port/get/get"));
9
+ const start_1 = __importDefault(require("./port/start/start"));
10
+ const add_1 = __importDefault(require("./project/add/add"));
11
+ const get_2 = __importDefault(require("./project/get/get"));
12
+ const remove_1 = __importDefault(require("./project/remove/remove"));
9
13
  const porterCommand = new commander_1.Command('porter');
10
14
  porterCommand
11
15
  .description('Porter Service Commands')
12
- .addCommand((0, projectCommand_1.default)())
13
- .addCommand((0, portCommand_1.default)());
16
+ // project commands
17
+ .addCommand((0, add_1.default)())
18
+ .addCommand((0, get_2.default)())
19
+ .addCommand((0, remove_1.default)())
20
+ // port commands
21
+ .addCommand((0, start_1.default)())
22
+ .addCommand((0, get_1.default)())
23
+ .addCommand((0, abort_1.default)());
14
24
  exports.default = porterCommand;
@@ -55,6 +55,7 @@ const createAddProjectCommand = () => {
55
55
  const projectName = options.projectName;
56
56
  const projectPath = options.path;
57
57
  const spinner = (0, ora_1.default)();
58
+ // Local filesystem validation
58
59
  const projectDir = path_1.default.resolve(projectPath);
59
60
  try {
60
61
  const pathExists = yield (0, utils_1.doesPathExist)(projectPath);
@@ -69,6 +70,10 @@ const createAddProjectCommand = () => {
69
70
  throw new Error(`Project parent directory "${parentDir}" does not exist`);
70
71
  }
71
72
  spinner.start('Creating a new project..');
73
+ const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
74
+ const requestBody = { 'new-project': true };
75
+ const response = yield apiService.client.put(`/projects/${projectName}`, requestBody);
76
+ (0, utils_1.logDebug)(response.data);
72
77
  yield promises_1.default.mkdir(projectDir);
73
78
  (0, utils_1.logDebug)(`Directory created successfully at ${projectDir}`);
74
79
  const configJsonFile = path_1.default.join(projectDir, 'config.json');
@@ -86,29 +91,31 @@ const createAddProjectCommand = () => {
86
91
  yield promises_1.default.mkdir(stageDir);
87
92
  (0, utils_1.logDebug)(`Directory created successfully at ${stageDir}`);
88
93
  })));
89
- const crawlConfigExample = path_1.default.join(stageConfigDir, 'crawl', 'config.json.example');
90
- yield promises_1.default.writeFile(crawlConfigExample, JSON.stringify({
91
- start_urls: ['https://...', 'https://...'],
92
- exclude_patterns: ['https://...', 'https://...'],
93
- max_download_size: 'MB',
94
- request_delay: 'INT',
95
- max_dir_depth: 'INT',
96
- max_files_stored: 'INT',
97
- run: true,
98
- }, null, 2));
94
+ const crawlConfigExample = path_1.default.join(stageConfigDir, dxp_porter_shared_1.Stage.crawl, 'config.json.example');
95
+ yield promises_1.default.writeFile(crawlConfigExample, `{
96
+ "start_urls": ["https://...", "https://..."],
97
+ "exclude_patterns": ["https://...", "https://..."],
98
+ "max_download_size": INT (MB),
99
+ "request_delay": INT (ms),
100
+ "max_dir_depth": INT,
101
+ "max_files_stored": INT,
102
+ "run": true,
103
+ }`);
99
104
  (0, utils_1.logDebug)(`File created successfully at ${crawlConfigExample}`);
105
+ const templateDedupeConfigExample = path_1.default.join(stageConfigDir, dxp_porter_shared_1.Stage.templateDedupe, 'config.json.example');
106
+ yield promises_1.default.writeFile(templateDedupeConfigExample, `{
107
+ "sensitivity": INT,
108
+ "run": false,
109
+ }`);
110
+ (0, utils_1.logDebug)(`File created successfully at ${templateDedupeConfigExample}`);
100
111
  // Default example configs for other stages
101
112
  stageDirsToCreate
102
- .filter(dir => dir !== dxp_porter_shared_1.Stage.crawl)
113
+ .filter(dir => dir !== dxp_porter_shared_1.Stage.crawl && dir !== dxp_porter_shared_1.Stage.templateDedupe)
103
114
  .map((dir) => __awaiter(void 0, void 0, void 0, function* () {
104
115
  const configExample = path_1.default.join(stageConfigDir, dir, 'config.json.example');
105
116
  yield promises_1.default.writeFile(configExample, JSON.stringify({ run: true }, null, 2));
106
117
  (0, utils_1.logDebug)(`File created successfully at ${configExample}`);
107
118
  }));
108
- const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
109
- const requestBody = { 'new-project': true };
110
- const response = yield apiService.client.put(`/projects/${projectName}`, requestBody);
111
- (0, utils_1.logDebug)(response.data);
112
119
  spinner.succeed(`Project "${projectName}" created. Project directory initialized`);
113
120
  }
114
121
  catch (error) {
@@ -117,8 +124,6 @@ const createAddProjectCommand = () => {
117
124
  spinner.fail();
118
125
  }
119
126
  if (((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.status) === 409) {
120
- (0, utils_1.logDebug)(`Failed to create new project, removing project directory: "${projectDir}"`);
121
- yield promises_1.default.rm(projectDir, { recursive: true });
122
127
  const errorMessage = `Project "${projectName}" already exists. Try a different project name`;
123
128
  return (0, utils_1.handleError)(addCommand, errorMessage);
124
129
  }
@@ -106,7 +106,7 @@ describe('addProject', () => {
106
106
  const { default: createAddCommand } = require('./add');
107
107
  const program = createAddCommand();
108
108
  yield expect(() => program.parseAsync([
109
- 'project',
109
+ '',
110
110
  'addProject',
111
111
  '--project-name',
112
112
  projectNameInvalid,
@@ -125,7 +125,7 @@ describe('addProject', () => {
125
125
  const { default: createAddCommand } = require('./add');
126
126
  const program = createAddCommand();
127
127
  yield expect(() => program.parseAsync([
128
- 'project',
128
+ '',
129
129
  'addProject',
130
130
  '--project-name',
131
131
  projectName,
@@ -145,7 +145,7 @@ describe('addProject', () => {
145
145
  const { default: createAddCommand } = require('./add');
146
146
  const program = createAddCommand();
147
147
  yield program.parseAsync([
148
- 'project',
148
+ '',
149
149
  'addProject',
150
150
  '--project-name',
151
151
  projectName,
@@ -167,7 +167,7 @@ describe('addProject', () => {
167
167
  const { default: createAddCommand } = require('./add');
168
168
  const program = createAddCommand();
169
169
  yield program.parseAsync([
170
- 'project',
170
+ '',
171
171
  'addProject',
172
172
  '--project-name',
173
173
  projectName,
@@ -183,7 +183,7 @@ describe('addProject', () => {
183
183
  expect(mockClient.put).not.toHaveBeenCalled();
184
184
  expect(PorterUtils.handleCommandError).toHaveBeenCalled();
185
185
  }));
186
- it('should clean up the directory if project already exists', () => __awaiter(void 0, void 0, void 0, function* () {
186
+ it('should handle 409 error if project already exists', () => __awaiter(void 0, void 0, void 0, function* () {
187
187
  mockClient.put = jest.fn(() => {
188
188
  throw new axios_1.AxiosError('Project already exists', '409', undefined, undefined, {
189
189
  data: { status: 409 },
@@ -192,7 +192,7 @@ describe('addProject', () => {
192
192
  const { default: createAddCommand } = require('./add');
193
193
  const program = createAddCommand();
194
194
  yield program.parseAsync([
195
- 'project',
195
+ '',
196
196
  'addProject',
197
197
  '--project-name',
198
198
  projectName,
@@ -205,15 +205,8 @@ describe('addProject', () => {
205
205
  expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
206
206
  expect(PorterUtils.doesPathExist).toHaveBeenCalled();
207
207
  expect(promises_1.default.access).toHaveBeenCalled();
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);
214
- expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
215
208
  expect(mockClient.put).toHaveBeenCalled();
216
- expect(promises_1.default.rm).toHaveBeenCalled();
209
+ expect(promises_1.default.mkdir).not.toHaveBeenCalled();
217
210
  expect(PorterUtils.handleError).toHaveBeenCalled();
218
211
  expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
219
212
  }));
@@ -221,7 +214,7 @@ describe('addProject', () => {
221
214
  const { default: createAddCommand } = require('./add');
222
215
  const program = createAddCommand();
223
216
  yield program.parseAsync([
224
- 'project',
217
+ '',
225
218
  'addProject',
226
219
  '--project-name',
227
220
  projectName,
@@ -248,7 +241,7 @@ describe('addProject', () => {
248
241
  const { default: createAddCommand } = require('./add');
249
242
  const program = createAddCommand();
250
243
  yield program.parseAsync([
251
- 'project',
244
+ '',
252
245
  'addProject',
253
246
  '--project-name',
254
247
  projectName,
@@ -16,7 +16,6 @@ exports.throwErrorIfNotLoggedIn = exports.handleError = exports.handleCommandErr
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const ApplicationStore_1 = require("../../../ApplicationStore");
19
- const CheckAuthorisation_1 = require("../AuthUtils/CheckAuthorisation");
20
19
  const constants_1 = require("../../constants");
21
20
  function handleCommandError(command, error) {
22
21
  if (!axios_1.default.isAxiosError(error)) {
@@ -32,7 +31,7 @@ function handleCommandError(command, error) {
32
31
  return command.error(chalk_1.default.red(error.message));
33
32
  }
34
33
  if (error.response.status === 401 || error.response.status === 403) {
35
- return command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginError));
34
+ return command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginPermissionError));
36
35
  }
37
36
  if (error.response.status >= 500) {
38
37
  const errorMessage = `Action failed. Service responded with "${error.response.status}" response code`;
@@ -60,11 +59,7 @@ exports.handleError = handleError;
60
59
  function throwErrorIfNotLoggedIn(command) {
61
60
  return __awaiter(this, void 0, void 0, function* () {
62
61
  if (!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
63
- return command.error(chalk_1.default.red('You must login to interact with the porter service. See `dxp-next auth login`'));
64
- }
65
- const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
66
- if (!isAuthorised) {
67
- command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginError));
62
+ return command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginError));
68
63
  }
69
64
  });
70
65
  }
@@ -35,7 +35,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const axios_1 = require("axios");
36
36
  const commander_1 = require("commander");
37
37
  const GetApplicationFile = __importStar(require("../../../ApplicationStore"));
38
- const CheckAuthorisation = __importStar(require("../AuthUtils/CheckAuthorisation"));
39
38
  const ErrorUtils_1 = require("./ErrorUtils");
40
39
  const constants_1 = require("../../constants");
41
40
  describe('handleCommandError', () => {
@@ -96,7 +95,7 @@ describe('handleCommandError', () => {
96
95
  }));
97
96
  expect(stderrSpy).toHaveBeenCalledTimes(1);
98
97
  // read the mock call strings directly otherwise colours cause test failures with .toEqual()
99
- expect(stderrSpy.mock.calls[0][0]).toContain(constants_1.PORTER_ERRORS.loginError);
98
+ expect(stderrSpy.mock.calls[0][0]).toContain(constants_1.PORTER_ERRORS.loginPermissionError);
100
99
  }));
101
100
  it('correctly displays the console logs for invalid-params errors from the porter service', () => __awaiter(void 0, void 0, void 0, function* () {
102
101
  const command = new commander_1.Command();
@@ -163,17 +162,6 @@ describe('throwErrorIfNotLoggedIn', () => {
163
162
  .spyOn(GetApplicationFile, 'getApplicationFile')
164
163
  .mockImplementationOnce(() => Promise.resolve(undefined));
165
164
  yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
166
- expect(stderrSpy.mock.calls[0][0]).toContain('You must login to interact with the porter service. See `dxp-next auth login');
167
- expect(process.exit).toHaveBeenCalled();
168
- }));
169
- it('should call the command error if unauthorised', () => __awaiter(void 0, void 0, void 0, function* () {
170
- jest
171
- .spyOn(GetApplicationFile, 'getApplicationFile')
172
- .mockImplementationOnce(() => Promise.resolve('cookie'));
173
- jest
174
- .spyOn(CheckAuthorisation, 'checkAuthorisation')
175
- .mockImplementationOnce(() => Promise.resolve(false));
176
- yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
177
165
  expect(stderrSpy.mock.calls[0][0]).toContain(constants_1.PORTER_ERRORS.loginError);
178
166
  expect(process.exit).toHaveBeenCalled();
179
167
  }));
@@ -181,9 +169,6 @@ describe('throwErrorIfNotLoggedIn', () => {
181
169
  jest
182
170
  .spyOn(GetApplicationFile, 'getApplicationFile')
183
171
  .mockImplementationOnce(() => Promise.resolve('cookie'));
184
- jest
185
- .spyOn(CheckAuthorisation, 'checkAuthorisation')
186
- .mockImplementationOnce(() => Promise.resolve(true));
187
172
  yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
188
173
  expect(stderrSpy).not.toHaveBeenCalled();
189
174
  expect(process.exit).not.toHaveBeenCalled();
@@ -1,6 +1,5 @@
1
- export * from './AuthUtils/CheckAuthorisation';
2
- export * from './BuildPorterUrl/BuildPorterUrl';
3
1
  export * from './BuildDXPUrl/BuildDXPUrl';
2
+ export * from './BuildPorterUrl/BuildPorterUrl';
4
3
  export * from './CoreUtils/CoreUtils';
5
4
  export * from './DoesPathExist/DoesPathExist';
6
5
  export * from './ErrorUtils/ErrorUtils';
@@ -14,9 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./AuthUtils/CheckAuthorisation"), exports);
18
- __exportStar(require("./BuildPorterUrl/BuildPorterUrl"), exports);
19
17
  __exportStar(require("./BuildDXPUrl/BuildDXPUrl"), exports);
18
+ __exportStar(require("./BuildPorterUrl/BuildPorterUrl"), exports);
20
19
  __exportStar(require("./CoreUtils/CoreUtils"), exports);
21
20
  __exportStar(require("./DoesPathExist/DoesPathExist"), exports);
22
21
  __exportStar(require("./ErrorUtils/ErrorUtils"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.15.0",
3
+ "version": "5.16.0",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- declare const createPortCommand: () => Command;
3
- export default createPortCommand;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const commander_1 = require("commander");
7
- const abort_1 = __importDefault(require("./abort/abort"));
8
- const get_1 = __importDefault(require("./get/get"));
9
- const start_1 = __importDefault(require("./start/start"));
10
- const createPortCommand = () => {
11
- const portCommand = new commander_1.Command('port');
12
- portCommand
13
- .description('Porter port commands')
14
- .addCommand((0, start_1.default)())
15
- .addCommand((0, get_1.default)())
16
- .addCommand((0, abort_1.default)());
17
- return portCommand;
18
- };
19
- exports.default = createPortCommand;
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- declare const createProjectCommand: () => Command;
3
- export default createProjectCommand;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const commander_1 = require("commander");
7
- const get_1 = __importDefault(require("./get/get"));
8
- const add_1 = __importDefault(require("./add/add"));
9
- const remove_1 = __importDefault(require("./remove/remove"));
10
- const createProjectCommand = () => {
11
- const projectCommand = new commander_1.Command('project');
12
- projectCommand
13
- .description('Porter project commands')
14
- .addCommand((0, add_1.default)())
15
- .addCommand((0, get_1.default)())
16
- .addCommand((0, remove_1.default)());
17
- return projectCommand;
18
- };
19
- exports.default = createProjectCommand;
@@ -1 +0,0 @@
1
- export declare function checkAuthorisation(): Promise<boolean>;
@@ -1,32 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.checkAuthorisation = void 0;
13
- const ApiService_1 = require("../../../ApiService");
14
- const BuildPorterUrl_1 = require("../BuildPorterUrl/BuildPorterUrl");
15
- const CoreUtils_1 = require("../CoreUtils/CoreUtils");
16
- function checkAuthorisation() {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- try {
19
- const baseUrl = yield (0, BuildPorterUrl_1.buildPorterUrl)();
20
- const apiService = new ApiService_1.ApiService(CoreUtils_1.validateAxiosStatus, baseUrl);
21
- const healthEndpoint = '/health';
22
- const response = yield apiService.client.get(healthEndpoint);
23
- return response.status === 200;
24
- }
25
- catch (err) {
26
- (0, CoreUtils_1.logDebug)('Error while checking auth');
27
- (0, CoreUtils_1.logDebug)(err);
28
- return false;
29
- }
30
- });
31
- }
32
- exports.checkAuthorisation = checkAuthorisation;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- const ApiService = __importStar(require("../../../ApiService"));
36
- const BuildPorterUrl = __importStar(require("../BuildPorterUrl/BuildPorterUrl"));
37
- const CheckAuthorisation_1 = require("./CheckAuthorisation");
38
- describe('checkAuthorisation', () => {
39
- beforeEach(() => {
40
- jest.resetAllMocks();
41
- });
42
- it('should return false if failed to construct the porter url', () => __awaiter(void 0, void 0, void 0, function* () {
43
- jest.spyOn(BuildPorterUrl, 'buildPorterUrl').mockImplementationOnce(() => {
44
- throw new Error();
45
- });
46
- const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
47
- expect(isAuthorised).toEqual(false);
48
- }));
49
- it('should return false if the health endpoint return with a non-200 status', () => __awaiter(void 0, void 0, void 0, function* () {
50
- jest
51
- .spyOn(BuildPorterUrl, 'buildPorterUrl')
52
- .mockReturnValue(Promise.resolve('1234'));
53
- jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
54
- return {
55
- client: {
56
- get: jest.fn(() => Promise.resolve({ status: 401 })),
57
- },
58
- };
59
- });
60
- const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
61
- expect(isAuthorised).toEqual(false);
62
- }));
63
- it('should return true if the health endpoint returns with 200 status', () => __awaiter(void 0, void 0, void 0, function* () {
64
- jest
65
- .spyOn(BuildPorterUrl, 'buildPorterUrl')
66
- .mockImplementationOnce(() => Promise.resolve('1234'));
67
- jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
68
- return {
69
- client: {
70
- get: jest.fn(() => Promise.resolve({ status: 200 })),
71
- },
72
- };
73
- });
74
- const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
75
- expect(isAuthorised).toEqual(true);
76
- }));
77
- });