@squiz/dxp-cli-next 5.25.0-develop.1 → 5.25.0-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.
@@ -52,7 +52,7 @@ const createLoginCommand = () => {
52
52
  .addOption(new commander_1.Option('--dxp-base-url <baseURL>', 'DXP Console URL')
53
53
  .env('DXP_BASE_URL')
54
54
  .default(constants_1.PRODUCTION_URL))
55
- .addOption(new commander_1.Option('--region <region>').choices(['au']).default('au'))
55
+ .addOption(new commander_1.Option('--region <region>').choices(['au', 'us', 'uk']).default('au'))
56
56
  .addOption(new commander_1.Option('--override-session', 'Override the existing authorized session if it exists'))
57
57
  .addOption(new commander_1.Option('--tenant <tenantID>'))
58
58
  .configureOutput({
@@ -47,7 +47,7 @@ const createActivateCommand = () => {
47
47
  return status < 400 || status === 404;
48
48
  },
49
49
  });
50
- const scvDeployBaseUrl = yield (0, utils_1.buildDXPUrl)(constants_1.SCV_DEPLOY_SERVICE_NAME, undefined, options.overrideUrl, undefined);
50
+ const scvDeployBaseUrl = yield (0, utils_1.buildDXPUrl)(constants_1.SCV_DEPLOY_SERVICE_NAME);
51
51
  const apiUrl = `${scvDeployBaseUrl.dxpUrl}/${scvDeployBaseUrl.tenant}`;
52
52
  const getDeployResponse = (yield apiService.client
53
53
  .get(apiUrl)
@@ -86,9 +86,6 @@ const createActivateCommand = () => {
86
86
  (0, utils_1.handleCommandError)(error);
87
87
  }
88
88
  }));
89
- if (process.env.ENABLE_OVERRIDE_CDP_SCHEMA_URL === 'true') {
90
- activateCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire DXP url with a custom value'));
91
- }
92
89
  return activateCommand;
93
90
  };
94
91
  exports.default = createActivateCommand;
@@ -35,12 +35,13 @@ 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 activate_1 = __importStar(require("./activate"));
40
39
  const deploy_const_1 = require("../../schema/deploy/deploy.const");
41
40
  const utils_1 = require("../../utils");
42
41
  const activate = __importStar(require("./activate"));
43
42
  const utils = __importStar(require("../../utils"));
43
+ const axios_1 = __importDefault(require("axios"));
44
+ jest.mock('axios');
44
45
  const mockDomainWithPath = 'http://localhost:9999/__dxp/us/scv-deploy/myTenant';
45
46
  function createMockArgs() {
46
47
  return ['node', 'dxp-cli', 'cdp', 'instance', 'activate'];
@@ -52,91 +53,115 @@ describe('cdpInstanceCommand', () => {
52
53
  let mockDomain;
53
54
  let logSpy;
54
55
  let errorSpy;
55
- let activateErrorSpy;
56
56
  beforeEach(() => {
57
57
  process.env.ENABLE_CDP_ADMIN = 'true';
58
- process.env.ENABLE_OVERRIDE_CDP_SCHEMA_URL = 'true';
59
58
  mockTenant = 'myTenant';
60
59
  mockRegion = 'us';
61
60
  mockFilePath = './src/__tests__/cdp/scv/schema.json';
62
61
  mockDomain = 'http://localhost:9999';
63
62
  logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
64
63
  errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
65
- activateErrorSpy = jest
66
- .spyOn(activate, 'handleActivateError')
67
- .mockImplementation(() => { });
68
- if (!nock_1.default.isActive()) {
69
- nock_1.default.activate();
70
- }
71
- nock_1.default.cleanAll(); // Ensures each test runs in isolation
72
64
  });
73
65
  afterEach(() => {
74
- jest.clearAllMocks(); // Clear all spies after each test
75
- nock_1.default.cleanAll(); // Clear all HTTP mocks
66
+ jest.clearAllMocks();
76
67
  });
77
68
  it('should throw error when tenant exists', () => __awaiter(void 0, void 0, void 0, function* () {
69
+ const mockedAxiosInstance = {
70
+ get: jest.fn().mockResolvedValue({ status: 200 }),
71
+ interceptors: {
72
+ request: { use: jest.fn() },
73
+ response: { use: jest.fn() },
74
+ },
75
+ };
76
+ axios_1.default.create.mockReturnValue(mockedAxiosInstance);
78
77
  jest.spyOn(utils, 'buildDXPUrl').mockResolvedValue({
79
78
  dxpUrl: `${mockDomain}/__dxp/us/scv-deploy`,
80
79
  tenant: mockTenant,
81
80
  });
82
81
  const mockPath = (0, utils_1.createMockUrl)(mockRegion, mockTenant);
83
82
  expect(`${mockDomain}${mockPath}`).toEqual(mockDomainWithPath);
84
- (0, nock_1.default)(mockDomain)
85
- .get(mockPath)
86
- .reply(200, { status: deploy_const_1.CDP_DEPLOY_STATUS_ERROR });
87
83
  const program = (0, activate_1.default)();
88
84
  yield program.parseAsync(createMockArgs());
89
85
  expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining(activate_1.errorMessage));
90
86
  }));
91
- it('should throw error when get tenant returns 403', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ it('deploys a default schema and activate an instance', () => __awaiter(void 0, void 0, void 0, function* () {
92
88
  jest.spyOn(utils, 'buildDXPUrl').mockResolvedValue({
93
89
  dxpUrl: `${mockDomain}/__dxp/us/scv-deploy`,
94
90
  tenant: mockTenant,
95
91
  });
92
+ jest.spyOn(utils, 'pollForDeployedSchema').mockResolvedValue({});
93
+ const mockedAxiosInstance = {
94
+ get: jest.fn().mockResolvedValue({ status: 404 }),
95
+ put: jest
96
+ .fn()
97
+ .mockResolvedValue({ status: 200, data: { message: 'Success' } }),
98
+ interceptors: {
99
+ request: { use: jest.fn() },
100
+ response: { use: jest.fn() },
101
+ },
102
+ };
103
+ axios_1.default.create.mockReturnValue(mockedAxiosInstance);
96
104
  const mockPath = (0, utils_1.createMockUrl)(mockRegion, mockTenant);
97
105
  expect(`${mockDomain}${mockPath}`).toEqual(mockDomainWithPath);
98
- (0, nock_1.default)(mockDomain).get(mockPath).reply(403, {
99
- title: 'Forbidden',
100
- status: 403,
101
- });
102
106
  const program = (0, activate_1.default)();
103
107
  yield program.parseAsync(createMockArgs());
104
- expect(activateErrorSpy).toHaveBeenCalledWith(403, {
105
- status: 403,
106
- title: 'Forbidden',
107
- });
108
+ expect(mockedAxiosInstance.put).toHaveBeenCalledWith(`${mockDomain}${mockPath}`);
109
+ // Note the output from the spinner doesn't seem to appear here but this still tests that it
110
+ // ran without displaying an error.
111
+ expect(logSpy).toHaveBeenNthCalledWith(1, '');
112
+ expect(logSpy).toHaveBeenNthCalledWith(2, '');
113
+ expect(logSpy).toHaveBeenNthCalledWith(3, 'Your Schema has been deployed and instance has been activated.');
114
+ expect(logSpy).toHaveBeenNthCalledWith(4, '');
115
+ expect(errorSpy).not.toHaveBeenCalled();
108
116
  }));
109
- it('deploys a default schema and activate an instance', () => __awaiter(void 0, void 0, void 0, function* () {
117
+ it('should throw error when trying to activate an instance currently', () => __awaiter(void 0, void 0, void 0, function* () {
110
118
  jest.spyOn(utils, 'buildDXPUrl').mockResolvedValue({
111
119
  dxpUrl: `${mockDomain}/__dxp/us/scv-deploy`,
112
120
  tenant: mockTenant,
113
121
  });
122
+ jest.spyOn(utils, 'pollForDeployedSchema').mockResolvedValue({});
123
+ const mockedAxios = axios_1.default;
124
+ //GET request (404)
125
+ mockedAxios.get.mockResolvedValueOnce({
126
+ status: 404,
127
+ data: { status: deploy_const_1.CDP_DEPLOY_STATUS_ERROR },
128
+ });
129
+ // PUT request (409)
130
+ mockedAxios.put.mockResolvedValueOnce({
131
+ status: 409,
132
+ data: {
133
+ tenantid: 'myTenant',
134
+ version: 'unknown',
135
+ stack: 'stackName',
136
+ status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYING,
137
+ },
138
+ });
139
+ axios_1.default.create.mockReturnValue(mockedAxios);
114
140
  const mockPath = (0, utils_1.createMockUrl)(mockRegion, mockTenant);
115
141
  expect(`${mockDomain}${mockPath}`).toEqual(mockDomainWithPath);
116
- (0, nock_1.default)(mockDomain)
117
- .get(mockPath)
118
- .reply(404, {
119
- status: deploy_const_1.CDP_DEPLOY_STATUS_ERROR,
120
- })
121
- .put(mockPath)
122
- .reply(200, {
123
- tenantid: 'myTenant',
124
- version: 'unknown',
125
- stack: 'stackName',
126
- status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYING,
127
- })
128
- .get(mockPath)
129
- .reply(200, {
130
- status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYED,
142
+ const program = (0, activate_1.default)();
143
+ yield program.parseAsync(createMockArgs());
144
+ expect(mockedAxios.put).toHaveBeenCalledWith(`${mockDomain}${mockPath}`);
145
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Currently activating instance. Please try again later.'));
146
+ }));
147
+ it('should throw error when get tenant returns 403', () => __awaiter(void 0, void 0, void 0, function* () {
148
+ const mockedAxiosInstance = {
149
+ get: jest.fn().mockRejectedValue({
150
+ response: { status: 403, data: {} },
151
+ }),
152
+ interceptors: {
153
+ request: { use: jest.fn() },
154
+ response: { use: jest.fn() },
155
+ },
156
+ };
157
+ axios_1.default.create.mockReturnValue(mockedAxiosInstance);
158
+ jest.spyOn(utils, 'buildDXPUrl').mockResolvedValue({
159
+ dxpUrl: `${mockDomain}/__dxp/us/scv-deploy`,
160
+ tenant: mockTenant,
131
161
  });
162
+ const handleActivateErrorSpy = jest.spyOn(activate, 'handleActivateError');
132
163
  const program = (0, activate_1.default)();
133
164
  yield program.parseAsync(createMockArgs());
134
- // Note the output from the spinner doesn't seem to appear here but this still tests that it
135
- // ran without displaying an error.
136
- expect(logSpy).toHaveBeenNthCalledWith(1, '');
137
- expect(logSpy).toHaveBeenNthCalledWith(2, '');
138
- expect(logSpy).toHaveBeenNthCalledWith(3, 'Your Schema has been deployed and instance has been activated.');
139
- expect(logSpy).toHaveBeenNthCalledWith(4, '');
140
- expect(errorSpy).not.toHaveBeenCalled();
165
+ expect(handleActivateErrorSpy).toHaveBeenCalledWith(403, {});
141
166
  }));
142
167
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.25.0-develop.1",
3
+ "version": "5.25.0-develop.2",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },