Skip to content

Commit bfd24b8

Browse files
committed
fix: updating unit tests
1 parent a37388b commit bfd24b8

26 files changed

+140
-537
lines changed

packages/respect-core/src/utils/__tests__/mtls/create-mtls-client.test.ts renamed to packages/cli/src/__tests__/commands/respect/mtls/create-mtls-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMtlsClient } from '../../../../../cli/src/commands/respect/mtls/create-mtls-client.js';
1+
import { createMtlsClient } from '../../../../commands/respect/mtls/create-mtls-client.js';
22

33
describe('createMtlsClient', () => {
44
it('should create a client with the correct certificates', () => {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { handleRespect, type RespectArgv } from '../../../commands/respect/index.js';
2+
import { handleRun } from '@redocly/respect-core';
3+
import { Config } from '@redocly/openapi-core';
4+
5+
// Mock node:fs
6+
vi.mock('node:fs', async () => {
7+
return {
8+
writeFileSync: vi.fn(),
9+
existsSync: vi.fn(() => false), // Return false to prevent plugin loading
10+
readFileSync: vi.fn(() => ''),
11+
accessSync: vi.fn(() => true),
12+
constants: {
13+
F_OK: 0,
14+
R_OK: 4,
15+
},
16+
};
17+
});
18+
19+
// Mock the handleRun function
20+
vi.mock('@redocly/respect-core', async () => {
21+
const actual = await vi.importActual('@redocly/respect-core');
22+
return {
23+
...actual,
24+
handleRun: vi.fn(),
25+
};
26+
});
27+
28+
// Mock @redocly/openapi-core
29+
vi.mock('@redocly/openapi-core', async () => {
30+
const actual = await vi.importActual('@redocly/openapi-core');
31+
return {
32+
...actual,
33+
logger: {
34+
info: vi.fn(),
35+
output: vi.fn(),
36+
printNewLine: vi.fn(),
37+
indent: vi.fn((text) => text),
38+
},
39+
stringifyYaml: vi.fn(() => 'mocked yaml'),
40+
};
41+
});
42+
43+
// Mock displayFilesSummaryTable
44+
vi.mock('../../../commands/respect/display-files-summary-table.js', () => ({
45+
displayFilesSummaryTable: vi.fn(),
46+
}));
47+
48+
describe('handleRespect', () => {
49+
beforeEach(() => {
50+
vi.clearAllMocks();
51+
});
52+
it('should call handleRun with the correct arguments', async () => {
53+
const mockConfig = new Config({});
54+
const commandArgs = {
55+
argv: {
56+
files: ['test.arazzo.yaml'],
57+
input: 'name=John',
58+
server: 'server1=http://localhost:3000',
59+
workflow: ['workflow3'],
60+
verbose: true,
61+
'max-steps': 2000,
62+
severity: 'STATUS_CODE_CHECK=warn',
63+
'max-fetch-timeout': 40_000,
64+
'execution-timeout': 3_600_000,
65+
} as RespectArgv,
66+
config: mockConfig,
67+
version: '1.0.0',
68+
collectSpecData: vi.fn(),
69+
};
70+
71+
vi.mocked(handleRun).mockResolvedValue([
72+
{
73+
hasProblems: false,
74+
hasWarnings: false,
75+
file: 'test.arazzo.yaml',
76+
executedWorkflows: [],
77+
options: {} as any,
78+
ctx: {} as any,
79+
totalTimeMs: 100,
80+
totalRequests: 1,
81+
globalTimeoutError: false,
82+
harLogs: {},
83+
},
84+
]);
85+
86+
await handleRespect(commandArgs);
87+
88+
expect(handleRun).toHaveBeenCalledWith(
89+
expect.objectContaining({
90+
files: ['test.arazzo.yaml'],
91+
input: 'name=John',
92+
server: 'server1=http://localhost:3000',
93+
workflow: ['workflow3'],
94+
verbose: true,
95+
config: expect.anything(),
96+
version: '1.0.0',
97+
collectSpecData: expect.anything(),
98+
severity: 'STATUS_CODE_CHECK=warn',
99+
harOutput: undefined,
100+
jsonOutput: undefined,
101+
maxSteps: 2000,
102+
maxFetchTimeout: 40_000,
103+
executionTimeout: 3_600_000,
104+
})
105+
);
106+
});
107+
});

packages/cli/src/__tests__/commands/respect/with-har/add-headers.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/add-headers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addHeaders } from '../../../../commands/respect/har-logs/helpers/add-headers.js';
1+
import { addHeaders } from '../../../../../commands/respect/har-logs/helpers/add-headers.js';
22

33
describe('addHeaders', () => {
44
it('should add headers to an existing Headers object', () => {

packages/cli/src/__tests__/commands/respect/with-har/build-headers.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/build-headers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildHeaders } from '../../../../commands/respect/har-logs/helpers/build-headers.js';
1+
import { buildHeaders } from '../../../../../commands/respect/har-logs/helpers/build-headers.js';
22

33
describe('buildHeaders', () => {
44
it('should build headers from an array', () => {

packages/cli/src/__tests__/commands/respect/with-har/build-params.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/build-params.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildParams } from '../../../../commands/respect/har-logs/helpers/build-params.js';
1+
import { buildParams } from '../../../../../commands/respect/har-logs/helpers/build-params.js';
22

33
describe('buildParams', () => {
44
it('should parse url-encoded form data into HAR params format', () => {

packages/cli/src/__tests__/commands/respect/with-har/build-request-cookies.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/build-request-cookies.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildRequestCookies } from '../../../../commands/respect/har-logs/helpers/build-request-cookies.js';
1+
import { buildRequestCookies } from '../../../../../commands/respect/har-logs/helpers/build-request-cookies.js';
22

33
describe('buildRequestCookies', () => {
44
it('should build cookies from an array', () => {

packages/cli/src/__tests__/commands/respect/with-har/build-response-cookies.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/build-response-cookies.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildResponseCookies } from '../../../../commands/respect/har-logs/helpers/build-response-cookies.js';
1+
import { buildResponseCookies } from '../../../../../commands/respect/har-logs/helpers/build-response-cookies.js';
22

33
describe('buildResponseCookies', () => {
44
it('should build response cookies', () => {

packages/cli/src/__tests__/commands/respect/with-har/get-agent.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/get-agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Dispatcher } from 'undici';
22
import * as http from 'http';
33

4-
import { getAgent } from '../../../../commands/respect/har-logs/helpers/get-agent.js';
4+
import { getAgent } from '../../../../../commands/respect/har-logs/helpers/get-agent.js';
55

66
describe('getAgent', () => {
77
it('should return an agent', () => {

packages/cli/src/__tests__/commands/respect/with-har/get-duration.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/get-duration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDuration } from '../../../../commands/respect/har-logs/helpers/get-duration.js';
1+
import { getDuration } from '../../../../../commands/respect/har-logs/helpers/get-duration.js';
22

33
describe('getDuration', () => {
44
it('should return the duration in milliseconds', () => {

packages/cli/src/__tests__/commands/respect/with-har/get-input-url.test.ts renamed to packages/cli/src/__tests__/commands/respect/with-har/helpers/get-input-url.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInputUrl } from '../../../../commands/respect/har-logs/helpers/get-input-url.js';
1+
import { getInputUrl } from '../../../../../commands/respect/har-logs/helpers/get-input-url.js';
22

33
describe('getInputUrl', () => {
44
it('should return a URL object', () => {

0 commit comments

Comments
 (0)