@redocly/cli 1.7.0 → 1.8.1

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 (118) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/lib/__tests__/commands/build-docs.test.js +3 -3
  3. package/lib/__tests__/commands/bundle.test.js +5 -5
  4. package/lib/__tests__/commands/join.test.js +11 -11
  5. package/lib/__tests__/commands/lint.test.js +14 -14
  6. package/lib/__tests__/commands/push-region.test.js +1 -1
  7. package/lib/__tests__/commands/push.test.js +11 -11
  8. package/lib/__tests__/fetch-with-timeout.test.js +4 -13
  9. package/lib/__tests__/spinner.test.js +43 -0
  10. package/lib/__tests__/utils.test.js +36 -36
  11. package/lib/__tests__/wrapper.test.js +8 -8
  12. package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
  13. package/lib/cms/api/__tests__/api-keys.test.js +26 -0
  14. package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
  15. package/lib/cms/api/__tests__/api.client.test.js +217 -0
  16. package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
  17. package/lib/cms/api/__tests__/domains.test.js +13 -0
  18. package/lib/cms/api/api-client.d.ts +50 -0
  19. package/lib/cms/api/api-client.js +148 -0
  20. package/lib/cms/api/api-keys.d.ts +1 -0
  21. package/lib/cms/api/api-keys.js +24 -0
  22. package/lib/cms/api/domains.d.ts +1 -0
  23. package/lib/cms/api/domains.js +12 -0
  24. package/lib/cms/api/index.d.ts +3 -0
  25. package/lib/cms/api/index.js +19 -0
  26. package/lib/cms/api/types.d.ts +91 -0
  27. package/lib/cms/api/types.js +2 -0
  28. package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
  29. package/lib/cms/commands/__tests__/push-status.test.js +164 -0
  30. package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
  31. package/lib/cms/commands/__tests__/push.test.js +226 -0
  32. package/lib/cms/commands/push-status.d.ts +12 -0
  33. package/lib/cms/commands/push-status.js +150 -0
  34. package/lib/cms/commands/push.d.ts +23 -0
  35. package/lib/cms/commands/push.js +142 -0
  36. package/lib/cms/utils.d.ts +2 -0
  37. package/lib/cms/utils.js +6 -0
  38. package/lib/commands/build-docs/index.js +4 -4
  39. package/lib/commands/build-docs/utils.js +2 -2
  40. package/lib/commands/bundle.js +13 -13
  41. package/lib/commands/join.js +25 -25
  42. package/lib/commands/lint.js +10 -10
  43. package/lib/commands/login.js +2 -2
  44. package/lib/commands/preview-docs/index.js +4 -4
  45. package/lib/commands/preview-docs/preview-server/preview-server.js +2 -2
  46. package/lib/commands/preview-project/types.d.ts +1 -1
  47. package/lib/commands/push.d.ts +5 -0
  48. package/lib/commands/push.js +25 -17
  49. package/lib/commands/split/__tests__/index.test.js +2 -2
  50. package/lib/commands/split/index.js +17 -17
  51. package/lib/commands/stats.js +4 -4
  52. package/lib/index.d.ts +1 -1
  53. package/lib/index.js +130 -17
  54. package/lib/types.d.ts +8 -1
  55. package/lib/{__mocks__/utils.js → utils/__mocks__/miscellaneous.js} +1 -1
  56. package/lib/utils/assert-node-version.d.ts +1 -0
  57. package/lib/{fetch-with-timeout.js → utils/fetch-with-timeout.js} +2 -7
  58. package/lib/{utils.d.ts → utils/miscellaneous.d.ts} +1 -1
  59. package/lib/{utils.js → utils/miscellaneous.js} +2 -2
  60. package/lib/utils/spinner.d.ts +10 -0
  61. package/lib/utils/spinner.js +42 -0
  62. package/lib/{update-version-notifier.js → utils/update-version-notifier.js} +4 -4
  63. package/lib/wrapper.js +5 -5
  64. package/package.json +5 -3
  65. package/src/__tests__/commands/build-docs.test.ts +2 -2
  66. package/src/__tests__/commands/bundle.test.ts +2 -2
  67. package/src/__tests__/commands/join.test.ts +2 -2
  68. package/src/__tests__/commands/lint.test.ts +3 -3
  69. package/src/__tests__/commands/push-region.test.ts +1 -1
  70. package/src/__tests__/commands/push.test.ts +2 -2
  71. package/src/__tests__/fetch-with-timeout.test.ts +4 -16
  72. package/src/__tests__/spinner.test.ts +51 -0
  73. package/src/__tests__/utils.test.ts +2 -5
  74. package/src/__tests__/wrapper.test.ts +2 -2
  75. package/src/cms/api/__tests__/api-keys.test.ts +37 -0
  76. package/src/cms/api/__tests__/api.client.test.ts +275 -0
  77. package/src/cms/api/__tests__/domains.test.ts +15 -0
  78. package/src/cms/api/api-client.ts +199 -0
  79. package/src/cms/api/api-keys.ts +26 -0
  80. package/src/cms/api/domains.ts +11 -0
  81. package/src/cms/api/index.ts +3 -0
  82. package/src/cms/api/types.ts +101 -0
  83. package/src/cms/commands/__tests__/push-status.test.ts +212 -0
  84. package/src/cms/commands/__tests__/push.test.ts +293 -0
  85. package/src/cms/commands/push-status.ts +203 -0
  86. package/src/cms/commands/push.ts +215 -0
  87. package/src/cms/utils.ts +1 -0
  88. package/src/commands/build-docs/index.ts +1 -1
  89. package/src/commands/build-docs/utils.ts +1 -1
  90. package/src/commands/bundle.ts +2 -2
  91. package/src/commands/join.ts +2 -2
  92. package/src/commands/lint.ts +1 -1
  93. package/src/commands/login.ts +1 -1
  94. package/src/commands/preview-docs/index.ts +5 -1
  95. package/src/commands/preview-docs/preview-server/preview-server.ts +1 -1
  96. package/src/commands/preview-project/types.ts +1 -1
  97. package/src/commands/push.ts +15 -1
  98. package/src/commands/split/__tests__/index.test.ts +3 -4
  99. package/src/commands/split/index.ts +2 -2
  100. package/src/commands/stats.ts +2 -2
  101. package/src/index.ts +138 -20
  102. package/src/types.ts +8 -0
  103. package/src/{__mocks__/utils.ts → utils/__mocks__/miscellaneous.ts} +1 -1
  104. package/src/{fetch-with-timeout.ts → utils/fetch-with-timeout.ts} +1 -6
  105. package/src/{utils.ts → utils/miscellaneous.ts} +2 -2
  106. package/src/utils/spinner.ts +50 -0
  107. package/src/{update-version-notifier.ts → utils/update-version-notifier.ts} +2 -2
  108. package/src/wrapper.ts +7 -2
  109. package/tsconfig.tsbuildinfo +1 -1
  110. /package/lib/{assert-node-version.d.ts → __tests__/spinner.test.d.ts} +0 -0
  111. /package/lib/{__mocks__/utils.d.ts → utils/__mocks__/miscellaneous.d.ts} +0 -0
  112. /package/lib/{assert-node-version.js → utils/assert-node-version.js} +0 -0
  113. /package/lib/{fetch-with-timeout.d.ts → utils/fetch-with-timeout.d.ts} +0 -0
  114. /package/lib/{js-utils.d.ts → utils/js-utils.d.ts} +0 -0
  115. /package/lib/{js-utils.js → utils/js-utils.js} +0 -0
  116. /package/lib/{update-version-notifier.d.ts → utils/update-version-notifier.d.ts} +0 -0
  117. /package/src/{assert-node-version.ts → utils/assert-node-version.ts} +0 -0
  118. /package/src/{js-utils.ts → utils/js-utils.ts} +0 -0
@@ -0,0 +1,148 @@
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.ReuniteApiClient = void 0;
13
+ const fetch_with_timeout_1 = require("../../utils/fetch-with-timeout");
14
+ const node_fetch_1 = require("node-fetch");
15
+ const FormData = require("form-data");
16
+ class RemotesApiClient {
17
+ constructor(domain, apiKey) {
18
+ this.domain = domain;
19
+ this.apiKey = apiKey;
20
+ }
21
+ getParsedResponse(response) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const responseBody = yield response.json();
24
+ if (response.ok) {
25
+ return responseBody;
26
+ }
27
+ throw new Error(responseBody.title || response.statusText);
28
+ });
29
+ }
30
+ getDefaultBranch(organizationId, projectId) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const response = yield (0, node_fetch_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/source`, {
33
+ method: 'GET',
34
+ headers: {
35
+ 'Content-Type': 'application/json',
36
+ Authorization: `Bearer ${this.apiKey}`,
37
+ },
38
+ });
39
+ try {
40
+ const source = yield this.getParsedResponse(response);
41
+ return source.branchName;
42
+ }
43
+ catch (err) {
44
+ throw new Error(`Failed to fetch default branch: ${err.message || 'Unknown error'}`);
45
+ }
46
+ });
47
+ }
48
+ upsert(organizationId, projectId, remote) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const response = yield (0, node_fetch_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes`, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ Authorization: `Bearer ${this.apiKey}`,
55
+ },
56
+ body: JSON.stringify({
57
+ mountPath: remote.mountPath,
58
+ mountBranchName: remote.mountBranchName,
59
+ type: 'CICD',
60
+ autoMerge: true,
61
+ }),
62
+ });
63
+ try {
64
+ return yield this.getParsedResponse(response);
65
+ }
66
+ catch (err) {
67
+ throw new Error(`Failed to upsert remote: ${err.message || 'Unknown error'}`);
68
+ }
69
+ });
70
+ }
71
+ push(organizationId, projectId, payload, files) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const formData = new FormData();
74
+ formData.append('remoteId', payload.remoteId);
75
+ formData.append('commit[message]', payload.commit.message);
76
+ formData.append('commit[author][name]', payload.commit.author.name);
77
+ formData.append('commit[author][email]', payload.commit.author.email);
78
+ formData.append('commit[branchName]', payload.commit.branchName);
79
+ payload.commit.url && formData.append('commit[url]', payload.commit.url);
80
+ payload.commit.namespace && formData.append('commit[namespaceId]', payload.commit.namespace);
81
+ payload.commit.sha && formData.append('commit[sha]', payload.commit.sha);
82
+ payload.commit.repository && formData.append('commit[repositoryId]', payload.commit.repository);
83
+ payload.commit.createdAt && formData.append('commit[createdAt]', payload.commit.createdAt);
84
+ for (const file of files) {
85
+ formData.append(`files[${file.path}]`, file.stream);
86
+ }
87
+ payload.isMainBranch && formData.append('isMainBranch', 'true');
88
+ const response = yield (0, node_fetch_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes`, {
89
+ method: 'POST',
90
+ headers: {
91
+ Authorization: `Bearer ${this.apiKey}`,
92
+ },
93
+ body: formData,
94
+ });
95
+ try {
96
+ return yield this.getParsedResponse(response);
97
+ }
98
+ catch (err) {
99
+ throw new Error(`Failed to push: ${err.message || 'Unknown error'}`);
100
+ }
101
+ });
102
+ }
103
+ getRemotesList(organizationId, projectId, mountPath) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const response = yield (0, node_fetch_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes?filter=mountPath:/${mountPath}/`, {
106
+ method: 'GET',
107
+ headers: {
108
+ 'Content-Type': 'application/json',
109
+ Authorization: `Bearer ${this.apiKey}`,
110
+ },
111
+ });
112
+ try {
113
+ return yield this.getParsedResponse(response);
114
+ }
115
+ catch (err) {
116
+ throw new Error(`Failed to get remote list: ${err.message || 'Unknown error'}`);
117
+ }
118
+ });
119
+ }
120
+ getPush({ organizationId, projectId, pushId, }) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const response = yield (0, fetch_with_timeout_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes/${pushId}`, {
123
+ method: 'GET',
124
+ headers: {
125
+ 'Content-Type': 'application/json',
126
+ Authorization: `Bearer ${this.apiKey}`,
127
+ },
128
+ });
129
+ if (!response) {
130
+ throw new Error(`Failed to get push status: Time is up`);
131
+ }
132
+ try {
133
+ return yield this.getParsedResponse(response);
134
+ }
135
+ catch (err) {
136
+ throw new Error(`Failed to get push status: ${err.message || 'Unknown error'}`);
137
+ }
138
+ });
139
+ }
140
+ }
141
+ class ReuniteApiClient {
142
+ constructor(domain, apiKey) {
143
+ this.domain = domain;
144
+ this.apiKey = apiKey;
145
+ this.remotes = new RemotesApiClient(this.domain, this.apiKey);
146
+ }
147
+ }
148
+ exports.ReuniteApiClient = ReuniteApiClient;
@@ -0,0 +1 @@
1
+ export declare function getApiKeys(domain: string): any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getApiKeys = void 0;
4
+ const path_1 = require("path");
5
+ const os_1 = require("os");
6
+ const fs_1 = require("fs");
7
+ const utils_1 = require("@redocly/openapi-core/lib/utils");
8
+ const redocly_1 = require("@redocly/openapi-core/lib/redocly");
9
+ function readCredentialsFile(credentialsPath) {
10
+ return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
11
+ }
12
+ function getApiKeys(domain) {
13
+ const apiKey = process.env.REDOCLY_AUTHORIZATION;
14
+ if (apiKey) {
15
+ return apiKey;
16
+ }
17
+ const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), redocly_1.TOKEN_FILENAME);
18
+ const credentials = readCredentialsFile(credentialsPath);
19
+ if ((0, utils_1.isNotEmptyObject)(credentials) && credentials[domain]) {
20
+ return credentials[domain];
21
+ }
22
+ throw new Error('No api key provided, please use environment variable REDOCLY_AUTHORIZATION.');
23
+ }
24
+ exports.getApiKeys = getApiKeys;
@@ -0,0 +1 @@
1
+ export declare function getDomain(): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDomain = void 0;
4
+ const DEFAULT_DOMAIN = 'https://app.cloud.redocly.com';
5
+ function getDomain() {
6
+ const domain = process.env.REDOCLY_DOMAIN;
7
+ if (domain) {
8
+ return domain;
9
+ }
10
+ return DEFAULT_DOMAIN;
11
+ }
12
+ exports.getDomain = getDomain;
@@ -0,0 +1,3 @@
1
+ export * from './api-client';
2
+ export * from './domains';
3
+ export * from './api-keys';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api-client"), exports);
18
+ __exportStar(require("./domains"), exports);
19
+ __exportStar(require("./api-keys"), exports);
@@ -0,0 +1,91 @@
1
+ export type ProjectSourceResponse = {
2
+ branchName: string;
3
+ contentPath: string;
4
+ isInternal: boolean;
5
+ };
6
+ export type UpsertRemoteResponse = {
7
+ id: string;
8
+ type: 'CICD';
9
+ mountPath: string;
10
+ mountBranchName: string;
11
+ organizationId: string;
12
+ projectId: string;
13
+ };
14
+ export type ListRemotesResponse = {
15
+ object: 'list';
16
+ page: {
17
+ endCursor: string;
18
+ startCursor: string;
19
+ haxNextPage: boolean;
20
+ hasPrevPage: boolean;
21
+ limit: number;
22
+ total: number;
23
+ };
24
+ items: Remote[];
25
+ };
26
+ export type Remote = {
27
+ mountPath: string;
28
+ type: string;
29
+ autoSync: boolean;
30
+ autoMerge: boolean;
31
+ createdAt: string;
32
+ updatedAt: string;
33
+ providerType: string;
34
+ namespaceId: string;
35
+ repositoryId: string;
36
+ projectId: string;
37
+ mountBranchName: string;
38
+ contentPath: string;
39
+ credentialId: string;
40
+ branchName: string;
41
+ contentType: string;
42
+ id: string;
43
+ };
44
+ export type PushResponse = {
45
+ id: string;
46
+ remoteId: string;
47
+ commit: {
48
+ message: string;
49
+ branchName: string;
50
+ sha: string | null;
51
+ url: string | null;
52
+ createdAt: string | null;
53
+ namespace: string | null;
54
+ repository: string | null;
55
+ author: {
56
+ name: string;
57
+ email: string;
58
+ image: string | null;
59
+ };
60
+ };
61
+ remote: {
62
+ commits: {
63
+ branchName: string;
64
+ sha: string;
65
+ }[];
66
+ };
67
+ hasChanges: boolean;
68
+ isOutdated: boolean;
69
+ isMainBranch: boolean;
70
+ status: PushStatusResponse;
71
+ };
72
+ type DeploymentStatusResponse = {
73
+ deploy: {
74
+ url: string | null;
75
+ status: DeploymentStatus;
76
+ };
77
+ scorecard: ScorecardItem[];
78
+ };
79
+ export type PushStatusResponse = {
80
+ preview: DeploymentStatusResponse;
81
+ production: DeploymentStatusResponse;
82
+ };
83
+ export type ScorecardItem = {
84
+ name: string;
85
+ status: PushStatusBase;
86
+ description: string;
87
+ url: string;
88
+ };
89
+ export type PushStatusBase = 'pending' | 'success' | 'running' | 'failed';
90
+ export type DeploymentStatus = 'skipped' | PushStatusBase;
91
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,164 @@
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
+ const push_status_1 = require("../push-status");
13
+ const miscellaneous_1 = require("../../../utils/miscellaneous");
14
+ const remotes = {
15
+ getPush: jest.fn(),
16
+ getRemotesList: jest.fn(),
17
+ };
18
+ jest.mock('../../../utils/miscellaneous');
19
+ jest.mock('colorette', () => ({
20
+ green: (str) => str,
21
+ yellow: (str) => str,
22
+ red: (str) => str,
23
+ gray: (str) => str,
24
+ magenta: (str) => str,
25
+ cyan: (str) => str,
26
+ }));
27
+ jest.mock('../../api', () => (Object.assign(Object.assign({}, jest.requireActual('../../api')), { ReuniteApiClient: jest.fn().mockImplementation(function (...args) {
28
+ this.remotes = remotes;
29
+ }) })));
30
+ describe('handlePushStatus()', () => {
31
+ const mockConfig = { apis: {} };
32
+ const pushResponseStub = {
33
+ hasChanges: true,
34
+ status: {
35
+ preview: {
36
+ scorecard: [],
37
+ deploy: {
38
+ url: 'https://test-url',
39
+ status: 'success',
40
+ },
41
+ },
42
+ production: {
43
+ scorecard: [],
44
+ deploy: {
45
+ url: 'https://test-url',
46
+ status: 'success',
47
+ },
48
+ },
49
+ },
50
+ };
51
+ beforeEach(() => {
52
+ jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
53
+ jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
54
+ });
55
+ afterEach(() => {
56
+ jest.clearAllMocks();
57
+ });
58
+ it('should throw error if organization not provided', () => __awaiter(void 0, void 0, void 0, function* () {
59
+ yield (0, push_status_1.handlePushStatus)({
60
+ domain: 'test-domain',
61
+ organization: '',
62
+ project: 'test-project',
63
+ pushId: 'test-push-id',
64
+ 'max-execution-time': 1000,
65
+ }, mockConfig);
66
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith("No organization provided, please use --organization option or specify the 'organization' field in the config file.");
67
+ }));
68
+ it('should return success push status for preview-build', () => __awaiter(void 0, void 0, void 0, function* () {
69
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
70
+ remotes.getPush.mockResolvedValueOnce(pushResponseStub);
71
+ yield (0, push_status_1.handlePushStatus)({
72
+ domain: 'test-domain',
73
+ organization: 'test-org',
74
+ project: 'test-project',
75
+ pushId: 'test-push-id',
76
+ 'max-execution-time': 1000,
77
+ }, mockConfig);
78
+ expect(process.stdout.write).toHaveBeenCalledTimes(1);
79
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 PREVIEW deployment succeeded.\nPreview URL: https://test-url\n');
80
+ }));
81
+ it('should return success push status for preview and production builds', () => __awaiter(void 0, void 0, void 0, function* () {
82
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
83
+ remotes.getPush.mockResolvedValue(Object.assign(Object.assign({}, pushResponseStub), { isMainBranch: true }));
84
+ yield (0, push_status_1.handlePushStatus)({
85
+ domain: 'test-domain',
86
+ organization: 'test-org',
87
+ project: 'test-project',
88
+ pushId: 'test-push-id',
89
+ 'max-execution-time': 1000,
90
+ }, mockConfig);
91
+ expect(process.stdout.write).toHaveBeenCalledTimes(2);
92
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 PREVIEW deployment succeeded.\nPreview URL: https://test-url\n');
93
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 PRODUCTION deployment succeeded.\nPreview URL: https://test-url\n');
94
+ }));
95
+ it('should return failed push status for preview build', () => __awaiter(void 0, void 0, void 0, function* () {
96
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
97
+ remotes.getPush.mockResolvedValue({
98
+ isOutdated: false,
99
+ hasChanges: true,
100
+ status: {
101
+ preview: { deploy: { status: 'failed', url: 'https://test-url' }, scorecard: [] },
102
+ },
103
+ });
104
+ yield (0, push_status_1.handlePushStatus)({
105
+ domain: 'test-domain',
106
+ organization: 'test-org',
107
+ project: 'test-project',
108
+ pushId: 'test-push-id',
109
+ 'max-execution-time': 1000,
110
+ }, mockConfig);
111
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('❌ PREVIEW deployment failed.\nPreview URL: https://test-url');
112
+ }));
113
+ it('should return success push status for preview build and print scorecards', () => __awaiter(void 0, void 0, void 0, function* () {
114
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
115
+ remotes.getPush.mockResolvedValue({
116
+ isOutdated: false,
117
+ hasChanges: true,
118
+ status: {
119
+ preview: {
120
+ deploy: { status: 'success', url: 'https://test-url' },
121
+ scorecard: [
122
+ {
123
+ name: 'test-name',
124
+ status: 'success',
125
+ description: 'test-description',
126
+ url: 'test-url',
127
+ },
128
+ ],
129
+ },
130
+ },
131
+ });
132
+ yield (0, push_status_1.handlePushStatus)({
133
+ domain: 'test-domain',
134
+ organization: 'test-org',
135
+ project: 'test-project',
136
+ pushId: 'test-push-id',
137
+ 'max-execution-time': 1000,
138
+ }, mockConfig);
139
+ expect(process.stdout.write).toHaveBeenCalledTimes(4);
140
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 PREVIEW deployment succeeded.\nPreview URL: https://test-url\n');
141
+ expect(process.stdout.write).toHaveBeenCalledWith('\nScorecard:');
142
+ expect(process.stdout.write).toHaveBeenCalledWith('\n Name: test-name\n Status: success\n URL: test-url\n Description: test-description\n');
143
+ expect(process.stdout.write).toHaveBeenCalledWith('\n');
144
+ }));
145
+ it('should display message if there is no changes', () => __awaiter(void 0, void 0, void 0, function* () {
146
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
147
+ remotes.getPush.mockResolvedValueOnce({
148
+ isOutdated: false,
149
+ hasChanges: false,
150
+ status: {
151
+ preview: { deploy: { status: 'skipped', url: 'https://test-url' }, scorecard: [] },
152
+ },
153
+ });
154
+ yield (0, push_status_1.handlePushStatus)({
155
+ domain: 'test-domain',
156
+ organization: 'test-org',
157
+ project: 'test-project',
158
+ pushId: 'test-push-id',
159
+ wait: true,
160
+ 'max-execution-time': 1000,
161
+ }, mockConfig);
162
+ expect(process.stderr.write).toHaveBeenCalledWith('Files not uploaded. Reason: no changes.\n');
163
+ }));
164
+ });
@@ -0,0 +1 @@
1
+ export {};