Skip to content

Commit 1293315

Browse files
committed
test: add test coverage for DefaultConstructorSignature (asyncapi#1944)
Co-authored-by: Harsh Gupta <harsh16official@gmail.com>
1 parent 961e811 commit 1293315

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { getQueryParams } from '@asyncapi/generator-helpers';
5+
import { DefaultConstructorSignature } from '../../components/DefaultConstructorSignature.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
9+
10+
describe('DefaultConstructorSignature component (integration with AsyncAPI document)', () => {
11+
let parsedAsyncAPIDocument;
12+
let channels;
13+
let queryParamsArray;
14+
15+
beforeAll(async () => {
16+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
17+
parsedAsyncAPIDocument = parseResult.document;
18+
channels = parsedAsyncAPIDocument.channels();
19+
20+
const queryParams = getQueryParams(channels);
21+
queryParamsArray = queryParams ? Array.from(queryParams.entries()) : null;
22+
});
23+
24+
test('renders nothing when queryParams is null', () => {
25+
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={null} />);
26+
expect(result.trim()).toMatchSnapshot();
27+
});
28+
29+
test('renders nothing when queryParams is undefined', () => {
30+
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" />);
31+
expect(result.trim()).toMatchSnapshot();
32+
});
33+
34+
test('renders default constructor with no arguments when queryParams is empty array', () => {
35+
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={[]} />);
36+
expect(result.trim()).toMatchSnapshot();
37+
});
38+
39+
test('renders default constructor with query parameters from fixture', () => {
40+
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={queryParamsArray} />);
41+
expect(result.trim()).toMatchSnapshot();
42+
});
43+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders default constructor with no arguments when queryParams is empty array 1`] = `
4+
"public WebSocketClient(){
5+
this();
6+
}"
7+
`;
8+
9+
exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders default constructor with query parameters from fixture 1`] = `
10+
"public WebSocketClient(){
11+
this(\\"false\\", \\"true\\", null);
12+
}"
13+
`;
14+
15+
exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is null 1`] = `""`;
16+
17+
exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is undefined 1`] = `""`;

packages/templates/clients/websocket/java/quarkus/test/components/__snapshots__/URIParams.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ exports[`URIParams component (integration with AsyncAPI document) renders URI pa
1616
}
1717
query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8);
1818
19+
String sessionId = System.getenv(\\"SESSIONID\\");
20+
if(sessionId == null || sessionId.isEmpty()){
21+
throw new IllegalArgumentException(\\"Required environment variable SESSIONID is missing or empty\\");
22+
}
23+
query += \\"&sessionId=\\" + URLEncoder.encode(sessionId, StandardCharsets.UTF_8);
24+
1925
2026
String queryUri = baseURI + \\"/link\\" + \\"?\\" + query;
2127
WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait();

packages/templates/clients/websocket/test/__fixtures__/asyncapi-websocket-components.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ channels:
2626
bids:
2727
type: boolean
2828
default: true
29+
sessionId:
30+
type: string
2931
messages:
3032
testMessage:
3133
summary: Test message

0 commit comments

Comments
 (0)