@redocly/cli 1.0.0-beta.125 → 1.0.0-beta.127

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 (67) hide show
  1. package/lib/__mocks__/@redocly/openapi-core.d.ts +20 -2
  2. package/lib/__mocks__/@redocly/openapi-core.js +17 -1
  3. package/lib/__mocks__/utils.d.ts +12 -0
  4. package/lib/__mocks__/utils.js +3 -1
  5. package/lib/__tests__/commands/join.test.js +21 -0
  6. package/lib/__tests__/commands/lint.test.js +9 -0
  7. package/lib/__tests__/commands/push.test.js +16 -0
  8. package/lib/__tests__/fixtures/config.d.ts +10 -0
  9. package/lib/__tests__/fixtures/config.js +10 -0
  10. package/lib/__tests__/utils.test.js +151 -0
  11. package/lib/commands/build-docs/utils.js +6 -2
  12. package/lib/commands/bundle.js +3 -2
  13. package/lib/commands/join.d.ts +2 -0
  14. package/lib/commands/join.js +17 -1
  15. package/lib/commands/lint.js +4 -0
  16. package/lib/commands/preview-docs/index.js +1 -1
  17. package/lib/commands/push.js +3 -3
  18. package/lib/index.js +6 -0
  19. package/lib/update-version-notifier.d.ts +2 -0
  20. package/lib/update-version-notifier.js +100 -0
  21. package/lib/utils.d.ts +4 -1
  22. package/lib/utils.js +82 -13
  23. package/package.json +5 -3
  24. package/src/__mocks__/@redocly/openapi-core.ts +0 -66
  25. package/src/__mocks__/documents.ts +0 -63
  26. package/src/__mocks__/fs.ts +0 -6
  27. package/src/__mocks__/perf_hooks.ts +0 -3
  28. package/src/__mocks__/redoc.ts +0 -2
  29. package/src/__mocks__/utils.ts +0 -17
  30. package/src/__tests__/commands/build-docs.test.ts +0 -61
  31. package/src/__tests__/commands/bundle.test.ts +0 -169
  32. package/src/__tests__/commands/join.test.ts +0 -83
  33. package/src/__tests__/commands/lint.test.ts +0 -154
  34. package/src/__tests__/commands/push-region.test.ts +0 -51
  35. package/src/__tests__/commands/push.test.ts +0 -342
  36. package/src/__tests__/fixtures/config.ts +0 -11
  37. package/src/__tests__/utils.test.ts +0 -263
  38. package/src/assert-node-version.ts +0 -8
  39. package/src/commands/build-docs/index.ts +0 -56
  40. package/src/commands/build-docs/template.hbs +0 -23
  41. package/src/commands/build-docs/types.ts +0 -26
  42. package/src/commands/build-docs/utils.ts +0 -108
  43. package/src/commands/bundle.ts +0 -163
  44. package/src/commands/join.ts +0 -789
  45. package/src/commands/lint.ts +0 -154
  46. package/src/commands/login.ts +0 -21
  47. package/src/commands/preview-docs/index.ts +0 -182
  48. package/src/commands/preview-docs/preview-server/default.hbs +0 -24
  49. package/src/commands/preview-docs/preview-server/hot.js +0 -42
  50. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  51. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -156
  52. package/src/commands/preview-docs/preview-server/server.ts +0 -91
  53. package/src/commands/push.ts +0 -387
  54. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  55. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  56. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -88
  57. package/src/commands/split/__tests__/index.test.ts +0 -137
  58. package/src/commands/split/index.ts +0 -378
  59. package/src/commands/split/types.ts +0 -85
  60. package/src/commands/stats.ts +0 -117
  61. package/src/custom.d.ts +0 -1
  62. package/src/index.ts +0 -429
  63. package/src/js-utils.ts +0 -17
  64. package/src/types.ts +0 -28
  65. package/src/utils.ts +0 -393
  66. package/tsconfig.json +0 -9
  67. package/tsconfig.tsbuildinfo +0 -1
@@ -1,83 +0,0 @@
1
- import { handleJoin } from '../../commands/join';
2
- import { exitWithError, writeYaml } from '../../utils';
3
- import { yellow } from 'colorette';
4
- import { detectOpenAPI } from '@redocly/openapi-core';
5
-
6
- jest.mock('../../utils');
7
- jest.mock('colorette');
8
-
9
- describe('handleJoin fails', () => {
10
- const colloreteYellowMock = yellow as jest.Mock<any, any>;
11
- colloreteYellowMock.mockImplementation((string: string) => string);
12
-
13
- it('should call exitWithError because only one entrypoint', async () => {
14
- await handleJoin({ apis: ['first.yaml'] }, 'cli-version');
15
- expect(exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
16
- });
17
-
18
- it('should call exitWithError because passed all 3 options for tags', async () => {
19
- await handleJoin(
20
- {
21
- apis: ['first.yaml', 'second.yaml'],
22
- 'prefix-tags-with-info-prop': 'something',
23
- 'without-x-tag-groups': true,
24
- 'prefix-tags-with-filename': true,
25
- },
26
- 'cli-version'
27
- );
28
-
29
- expect(exitWithError).toHaveBeenCalledWith(
30
- `You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one! \n\n`
31
- );
32
- });
33
-
34
- it('should call exitWithError because passed all 2 options for tags', async () => {
35
- await handleJoin(
36
- {
37
- apis: ['first.yaml', 'second.yaml'],
38
- 'without-x-tag-groups': true,
39
- 'prefix-tags-with-filename': true,
40
- },
41
- 'cli-version'
42
- );
43
-
44
- expect(exitWithError).toHaveBeenCalledWith(
45
- `You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one! \n\n`
46
- );
47
- });
48
-
49
- it('should call exitWithError because Only OpenAPI 3 is supported', async () => {
50
- await handleJoin(
51
- {
52
- apis: ['first.yaml', 'second.yaml'],
53
- },
54
- 'cli-version'
55
- );
56
- expect(exitWithError).toHaveBeenCalledWith('Only OpenAPI 3 is supported: undefined \n\n');
57
- });
58
-
59
- it('should call writeYaml function', async () => {
60
- (detectOpenAPI as jest.Mock).mockReturnValue('oas3_0');
61
- await handleJoin(
62
- {
63
- apis: ['first.yaml', 'second.yaml'],
64
- },
65
- 'cli-version'
66
- );
67
-
68
- expect(writeYaml).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
69
- });
70
-
71
- it('should call writeYaml function with custom output file', async () => {
72
- (detectOpenAPI as jest.Mock).mockReturnValue('oas3_0');
73
- await handleJoin(
74
- {
75
- apis: ['first.yaml', 'second.yaml'],
76
- output: 'output.yml',
77
- },
78
- 'cli-version'
79
- );
80
-
81
- expect(writeYaml).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
82
- });
83
- });
@@ -1,154 +0,0 @@
1
- import { handleLint, LintOptions } from '../../commands/lint';
2
- import {
3
- getMergedConfig,
4
- lint,
5
- getTotals,
6
- formatProblems,
7
- doesYamlFileExist,
8
- } from '@redocly/openapi-core';
9
- import {
10
- getFallbackApisOrExit,
11
- getExecutionTime,
12
- printUnusedWarnings,
13
- handleError,
14
- exitWithError,
15
- loadConfigAndHandleErrors,
16
- } from '../../utils';
17
- import { ConfigFixture } from '../fixtures/config';
18
- import { performance } from 'perf_hooks';
19
-
20
- jest.mock('@redocly/openapi-core');
21
- jest.mock('../../utils');
22
- jest.mock('perf_hooks');
23
-
24
- const argvMock: LintOptions = {
25
- apis: ['openapi.yaml'],
26
- 'lint-config': 'off',
27
- format: 'codeframe',
28
- };
29
-
30
- const versionMock = '1.0.0';
31
-
32
- describe('handleLint', () => {
33
- let processExitMock: jest.SpyInstance;
34
- let exitCb: any;
35
- const getMergedConfigMock = getMergedConfig as jest.Mock<any, any>;
36
-
37
- beforeEach(() => {
38
- jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
39
- (performance.now as jest.Mock<any, any>).mockImplementation(() => 42);
40
- processExitMock = jest.spyOn(process, 'exit').mockImplementation();
41
- jest.spyOn(process, 'once').mockImplementation((_e, cb) => {
42
- exitCb = cb;
43
- return process.on(_e, cb);
44
- });
45
- getMergedConfigMock.mockReturnValue(ConfigFixture);
46
- (doesYamlFileExist as jest.Mock<any, any>).mockImplementation(
47
- (path) => path === 'redocly.yaml'
48
- );
49
- });
50
-
51
- afterEach(() => {
52
- getMergedConfigMock.mockReset();
53
- });
54
-
55
- describe('loadConfig and getEnrtypoints stage', () => {
56
- it('should fail if config file does not exist', async () => {
57
- await handleLint({ ...argvMock, config: 'config.yaml' }, versionMock);
58
- expect(exitWithError).toHaveBeenCalledWith(
59
- 'Please, provide valid path to the configuration file'
60
- );
61
- expect(loadConfigAndHandleErrors).toHaveBeenCalledTimes(0);
62
- });
63
-
64
- it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', async () => {
65
- await handleLint(argvMock, versionMock);
66
- expect(loadConfigAndHandleErrors).toHaveBeenCalledWith({
67
- configPath: undefined,
68
- customExtends: undefined,
69
- processRawConfig: undefined,
70
- });
71
- expect(getFallbackApisOrExit).toHaveBeenCalled();
72
- });
73
-
74
- it('should call loadConfig with args if such exist', async () => {
75
- await handleLint(
76
- { ...argvMock, config: 'redocly.yaml', extends: ['some/path'] },
77
- versionMock
78
- );
79
- expect(loadConfigAndHandleErrors).toHaveBeenCalledWith({
80
- configPath: 'redocly.yaml',
81
- customExtends: ['some/path'],
82
- processRawConfig: undefined,
83
- });
84
- });
85
-
86
- it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', async () => {
87
- await handleLint({ ...argvMock, 'generate-ignore-file': true }, versionMock);
88
- expect(getMergedConfigMock).toHaveBeenCalled();
89
- });
90
- });
91
-
92
- describe('loop through entrypints and lint stage', () => {
93
- it('should call getMergedConfig and lint ', async () => {
94
- await handleLint(argvMock, versionMock);
95
- expect(performance.now).toHaveBeenCalled();
96
- expect(getMergedConfigMock).toHaveBeenCalled();
97
- expect(lint).toHaveBeenCalled();
98
- });
99
-
100
- it('should call skipRules,skipPreprocessors and addIgnore with argv', async () => {
101
- (lint as jest.Mock<any, any>).mockResolvedValueOnce(['problem']);
102
- await handleLint(
103
- {
104
- ...argvMock,
105
- 'skip-preprocessor': ['preprocessor'],
106
- 'skip-rule': ['rule'],
107
- 'generate-ignore-file': true,
108
- },
109
- versionMock
110
- );
111
- expect(ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
112
- expect(ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
113
- });
114
-
115
- it('should call formatProblems and getExecutionTime with argv', async () => {
116
- (lint as jest.Mock<any, any>).mockResolvedValueOnce(['problem']);
117
- await handleLint({ ...argvMock, 'max-problems': 2, format: 'stylish' }, versionMock);
118
- expect(getTotals).toHaveBeenCalledWith(['problem']);
119
- expect(formatProblems).toHaveBeenCalledWith(['problem'], {
120
- format: 'stylish',
121
- maxProblems: 2,
122
- totals: { errors: 0 },
123
- version: versionMock,
124
- });
125
- expect(getExecutionTime).toHaveBeenCalledWith(42);
126
- });
127
-
128
- it('should catch error in handleError if something fails', async () => {
129
- (lint as jest.Mock<any, any>).mockRejectedValueOnce('error');
130
- await handleLint(argvMock, versionMock);
131
- expect(handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
132
- });
133
- });
134
-
135
- describe('erros and warning handle after lint stage', () => {
136
- it('should call printLintTotals and printLintTotals', async () => {
137
- await handleLint(argvMock, versionMock);
138
- expect(printUnusedWarnings).toHaveBeenCalled();
139
- });
140
-
141
- it('should call exit with 0 if no errors', async () => {
142
- await handleLint(argvMock, versionMock);
143
- exitCb?.();
144
- expect(processExitMock).toHaveBeenCalledWith(0);
145
- });
146
-
147
- it('should exit with 1 if tootals error > 0', async () => {
148
- (getTotals as jest.Mock<any, any>).mockReturnValueOnce({ errors: 1 });
149
- await handleLint(argvMock, versionMock);
150
- exitCb?.();
151
- expect(processExitMock).toHaveBeenCalledWith(1);
152
- });
153
- });
154
- });
@@ -1,51 +0,0 @@
1
- import { getMergedConfig } from '@redocly/openapi-core';
2
- import { handlePush } from '../../commands/push';
3
- import { promptClientToken } from '../../commands/login';
4
-
5
- jest.mock('fs');
6
- jest.mock('node-fetch', () => ({
7
- default: jest.fn(() => ({
8
- ok: true,
9
- json: jest.fn().mockResolvedValue({}),
10
- })),
11
- }));
12
- jest.mock('@redocly/openapi-core');
13
- jest.mock('../../commands/login');
14
- jest.mock('../../utils');
15
-
16
- (getMergedConfig as jest.Mock).mockImplementation((config) => config);
17
-
18
- const mockPromptClientToken = promptClientToken as jest.MockedFunction<typeof promptClientToken>;
19
-
20
- describe('push-with-region', () => {
21
- const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
22
- redoclyClient.isAuthorizedWithRedoclyByRegion = jest.fn().mockResolvedValue(false);
23
-
24
- beforeAll(() => {
25
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
26
- });
27
-
28
- it('should call login with default domain when region is US', async () => {
29
- redoclyClient.domain = 'redoc.ly';
30
- await handlePush({
31
- upsert: true,
32
- api: 'spec.json',
33
- destination: '@org/my-api@1.0.0',
34
- branchName: 'test',
35
- });
36
- expect(mockPromptClientToken).toBeCalledTimes(1);
37
- expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
38
- });
39
-
40
- it('should call login with EU domain when region is EU', async () => {
41
- redoclyClient.domain = 'eu.redocly.com';
42
- await handlePush({
43
- upsert: true,
44
- api: 'spec.json',
45
- destination: '@org/my-api@1.0.0',
46
- branchName: 'test',
47
- });
48
- expect(mockPromptClientToken).toBeCalledTimes(1);
49
- expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
50
- });
51
- });
@@ -1,342 +0,0 @@
1
- import * as fs from 'fs';
2
- import { Config, getMergedConfig } from '@redocly/openapi-core';
3
- import { exitWithError, loadConfigAndHandleErrors } from '../../utils';
4
- import { getApiRoot, getDestinationProps, handlePush, transformPush } from '../../commands/push';
5
- import { ConfigFixture } from '../fixtures/config';
6
- import { yellow } from 'colorette';
7
-
8
- jest.mock('fs');
9
- jest.mock('node-fetch', () => ({
10
- default: jest.fn(() => ({
11
- ok: true,
12
- json: jest.fn().mockResolvedValue({}),
13
- })),
14
- }));
15
- jest.mock('@redocly/openapi-core');
16
- jest.mock('../../utils');
17
-
18
- (getMergedConfig as jest.Mock).mockImplementation((config) => config);
19
-
20
- describe('push', () => {
21
- const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
22
-
23
- beforeEach(() => {
24
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
25
- });
26
-
27
- it('pushes definition', async () => {
28
- await handlePush({
29
- upsert: true,
30
- api: 'spec.json',
31
- destination: '@org/my-api@1.0.0',
32
- branchName: 'test',
33
- public: true,
34
- 'batch-id': '123',
35
- 'batch-size': 2,
36
- });
37
-
38
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
39
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
40
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
41
- branch: 'test',
42
- filePaths: ['filePath'],
43
- isUpsert: true,
44
- isPublic: true,
45
- name: 'my-api',
46
- organizationId: 'org',
47
- rootFilePath: 'filePath',
48
- version: '1.0.0',
49
- batchId: '123',
50
- batchSize: 2,
51
- });
52
- });
53
-
54
- it('fails if batchId value is an empty string', async () => {
55
- await handlePush({
56
- upsert: true,
57
- api: 'spec.json',
58
- destination: '@org/my-api@1.0.0',
59
- branchName: 'test',
60
- public: true,
61
- 'batch-id': ' ',
62
- 'batch-size': 2,
63
- });
64
-
65
- expect(exitWithError).toBeCalledTimes(1);
66
- });
67
-
68
- it('fails if batchSize value is less than 2', async () => {
69
- await handlePush({
70
- upsert: true,
71
- api: 'spec.json',
72
- destination: '@org/my-api@1.0.0',
73
- branchName: 'test',
74
- public: true,
75
- 'batch-id': '123',
76
- 'batch-size': 1,
77
- });
78
-
79
- expect(exitWithError).toBeCalledTimes(1);
80
- });
81
-
82
- it('push with --files', async () => {
83
- (loadConfigAndHandleErrors as jest.Mock).mockImplementation(({ files }) => {
84
- return { ...ConfigFixture, files };
85
- });
86
-
87
- //@ts-ignore
88
- fs.statSync.mockImplementation(() => {
89
- return { isDirectory: () => false, size: 10 };
90
- });
91
-
92
- await handlePush({
93
- upsert: true,
94
- api: 'spec.json',
95
- destination: '@org/my-api@1.0.0',
96
- public: true,
97
- files: ['./resouces/1.md', './resouces/2.md'],
98
- });
99
-
100
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
101
- filePaths: ['filePath', 'filePath', 'filePath'],
102
- isUpsert: true,
103
- isPublic: true,
104
- name: 'my-api',
105
- organizationId: 'org',
106
- rootFilePath: 'filePath',
107
- version: '1.0.0',
108
- });
109
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
110
- });
111
-
112
- it('push should fail if organization not provided', async () => {
113
- await handlePush({
114
- upsert: true,
115
- api: 'spec.json',
116
- destination: 'test@v1',
117
- branchName: 'test',
118
- public: true,
119
- 'batch-id': '123',
120
- 'batch-size': 2,
121
- });
122
-
123
- expect(exitWithError).toBeCalledTimes(1);
124
- expect(exitWithError).toBeCalledWith(
125
- `No organization provided, please use the right format: ${yellow(
126
- '<@organization-id/api-name@api-version>'
127
- )} or specify the 'organization' field in the config file.`
128
- );
129
- });
130
-
131
- it('push should work with organization in config', async () => {
132
- (loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
133
- return { ...ConfigFixture, organization: 'test_org' };
134
- });
135
- await handlePush({
136
- upsert: true,
137
- api: 'spec.json',
138
- destination: 'my-api@1.0.0',
139
- branchName: 'test',
140
- public: true,
141
- 'batch-id': '123',
142
- 'batch-size': 2,
143
- });
144
-
145
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
146
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
147
- branch: 'test',
148
- filePaths: ['filePath'],
149
- isUpsert: true,
150
- isPublic: true,
151
- name: 'my-api',
152
- organizationId: 'test_org',
153
- rootFilePath: 'filePath',
154
- version: '1.0.0',
155
- batchId: '123',
156
- batchSize: 2,
157
- });
158
- });
159
-
160
- it('push should work if destination not provided and api in config is provided', async () => {
161
- (loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
162
- return {
163
- ...ConfigFixture,
164
- organization: 'test_org',
165
- apis: { 'my-api@1.0.0': { root: 'path' } },
166
- };
167
- });
168
- await handlePush({
169
- upsert: true,
170
- api: 'spec.json',
171
- branchName: 'test',
172
- public: true,
173
- 'batch-id': '123',
174
- 'batch-size': 2,
175
- });
176
-
177
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
178
- });
179
-
180
- it('push should fail if destination and apis not provided', async () => {
181
- (loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
182
- return { organization: 'test_org', apis: {} };
183
- });
184
- await handlePush({
185
- upsert: true,
186
- branchName: 'test',
187
- public: true,
188
- 'batch-id': '123',
189
- 'batch-size': 2,
190
- });
191
-
192
- expect(exitWithError).toBeCalledTimes(1);
193
- expect(exitWithError).toHaveBeenLastCalledWith(
194
- 'Api not found. Please make sure you have provided the correct data in the config file.'
195
- );
196
- });
197
- });
198
-
199
- describe('transformPush', () => {
200
- it('should adapt the existing syntax', () => {
201
- const cb = jest.fn();
202
- transformPush(cb)({
203
- maybeApiOrDestination: 'openapi.yaml',
204
- maybeDestination: '@testing_org/main@v1',
205
- });
206
- expect(cb).toBeCalledWith({
207
- api: 'openapi.yaml',
208
- destination: '@testing_org/main@v1',
209
- });
210
- });
211
- it('should adapt the existing syntax (including branchName)', () => {
212
- const cb = jest.fn();
213
- transformPush(cb)({
214
- maybeApiOrDestination: 'openapi.yaml',
215
- maybeDestination: '@testing_org/main@v1',
216
- maybeBranchName: 'other',
217
- });
218
- expect(cb).toBeCalledWith({
219
- api: 'openapi.yaml',
220
- destination: '@testing_org/main@v1',
221
- branchName: 'other',
222
- });
223
- });
224
- it('should use --branch option firstly', () => {
225
- const cb = jest.fn();
226
- transformPush(cb)({
227
- maybeApiOrDestination: 'openapi.yaml',
228
- maybeDestination: '@testing_org/main@v1',
229
- maybeBranchName: 'other',
230
- branch: 'priority-branch',
231
- });
232
- expect(cb).toBeCalledWith({
233
- api: 'openapi.yaml',
234
- destination: '@testing_org/main@v1',
235
- branchName: 'priority-branch',
236
- });
237
- });
238
- it('should work for a destination only', () => {
239
- const cb = jest.fn();
240
- transformPush(cb)({
241
- maybeApiOrDestination: '@testing_org/main@v1',
242
- });
243
- expect(cb).toBeCalledWith({
244
- destination: '@testing_org/main@v1',
245
- });
246
- });
247
- it('should accept aliases for the old syntax', () => {
248
- const cb = jest.fn();
249
- transformPush(cb)({
250
- maybeApiOrDestination: 'alias',
251
- maybeDestination: '@testing_org/main@v1',
252
- });
253
- expect(cb).toBeCalledWith({
254
- destination: '@testing_org/main@v1',
255
- api: 'alias',
256
- });
257
- });
258
- it('should accept no arguments at all', () => {
259
- const cb = jest.fn();
260
- transformPush(cb)({});
261
- expect(cb).toBeCalledWith({});
262
- });
263
- });
264
-
265
- describe('getDestinationProps', () => {
266
- it('should get valid destination props for the full destination syntax', () => {
267
- expect(getDestinationProps('@testing_org/main@v1', 'org-from-config')).toEqual({
268
- organizationId: 'testing_org',
269
- name: 'main',
270
- version: 'v1',
271
- });
272
- });
273
- it('should fallback the organizationId from a config for the short destination syntax', () => {
274
- expect(getDestinationProps('main@v1', 'org-from-config')).toEqual({
275
- organizationId: 'org-from-config',
276
- name: 'main',
277
- version: 'v1',
278
- });
279
- });
280
- it('should fallback the organizationId from a config if no destination provided', () => {
281
- expect(getDestinationProps(undefined, 'org-from-config')).toEqual({
282
- organizationId: 'org-from-config',
283
- });
284
- });
285
- it('should return empty organizationId if there is no one found', () => {
286
- expect(getDestinationProps('main@v1', undefined)).toEqual({
287
- organizationId: undefined,
288
- name: 'main',
289
- version: 'v1',
290
- });
291
- });
292
- it('should return organizationId from destination string', () => {
293
- expect(getDestinationProps('@test-org/main@main-v1', undefined)).toEqual({
294
- organizationId: 'test-org',
295
- name: 'main',
296
- version: 'main-v1',
297
- });
298
- });
299
-
300
- it('should return organizationId, version and empty name from destination string', () => {
301
- expect(getDestinationProps('@test_org/@main_v1', undefined)).toEqual({
302
- organizationId: 'test_org',
303
- name: '',
304
- version: 'main_v1',
305
- });
306
- });
307
-
308
- it('should validate organizationId with space and version with dot', () => {
309
- expect(getDestinationProps('@test org/simple_name@main.v1', undefined)).toEqual({
310
- organizationId: 'test org',
311
- name: 'simple_name',
312
- version: 'main.v1',
313
- });
314
- });
315
-
316
- it('should not work with "@" in destination name', () => {
317
- expect(getDestinationProps('@test org/simple@name@main.v1', undefined)).toEqual({
318
- organizationId: undefined,
319
- name: undefined,
320
- version: undefined,
321
- });
322
- });
323
- });
324
-
325
- describe('getApiRoot', () => {
326
- let config: Config = {
327
- apis: {
328
- 'main@v1': {
329
- root: 'openapi.yaml',
330
- },
331
- main: {
332
- root: 'latest.yaml',
333
- },
334
- },
335
- } as unknown as Config;
336
- it('should resolve the correct api for a valid name & version', () => {
337
- expect(getApiRoot({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
338
- });
339
- it('should resolve the latest version of api if there is no matching version', () => {
340
- expect(getApiRoot({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
341
- });
342
- });
@@ -1,11 +0,0 @@
1
- export const ConfigFixture = {
2
- configFile: null,
3
- styleguide: {
4
- addIgnore: jest.fn(),
5
- skipRules: jest.fn(),
6
- skipPreprocessors: jest.fn(),
7
- saveIgnore: jest.fn(),
8
- skipDecorators: jest.fn(),
9
- ignore: null,
10
- },
11
- };