Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import path from 'path';
import { render } from '@asyncapi/generator-react-sdk';
import { Parser, fromFile } from '@asyncapi/parser';
import { getQueryParams } from '@asyncapi/generator-helpers';
import { DefaultConstructorSignature } from '../../components/DefaultConstructorSignature.js';

const parser = new Parser();
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');

describe('DefaultConstructorSignature component (integration with AsyncAPI document)', () => {
let parsedAsyncAPIDocument;
let channels;
let queryParamsArray;

beforeAll(async () => {
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
parsedAsyncAPIDocument = parseResult.document;
channels = parsedAsyncAPIDocument.channels();

const queryParams = getQueryParams(channels);
queryParamsArray = queryParams ? Array.from(queryParams.entries()) : null;
});

test('renders nothing when queryParams is null', () => {
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={null} />);
expect(result.trim()).toMatchSnapshot();
});

test('renders nothing when queryParams is undefined', () => {
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" />);
expect(result.trim()).toMatchSnapshot();
});

test('renders default constructor with no arguments when queryParams is empty array', () => {
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={[]} />);
expect(result.trim()).toMatchSnapshot();
});

test('renders default constructor with query parameters from fixture', () => {
const result = render(<DefaultConstructorSignature clientName="WebSocketClient" queryParams={queryParamsArray} />);
expect(result.trim()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders default constructor with no arguments when queryParams is empty array 1`] = `
"public WebSocketClient(){
this();
}"
`;

exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders default constructor with query parameters from fixture 1`] = `
"public WebSocketClient(){
this(\\"false\\", \\"true\\", null);
}"
`;

exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is null 1`] = `""`;

exports[`DefaultConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is undefined 1`] = `""`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ exports[`URIParams component (integration with AsyncAPI document) renders URI pa
}
query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8);
String sessionId = System.getenv(\\"SESSIONID\\");
if(sessionId == null || sessionId.isEmpty()){
throw new IllegalArgumentException(\\"Required environment variable SESSIONID is missing or empty\\");
}
query += \\"&sessionId=\\" + URLEncoder.encode(sessionId, StandardCharsets.UTF_8);
String queryUri = baseURI + \\"/link\\" + \\"?\\" + query;
WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ channels:
bids:
type: boolean
default: true
sessionId:
type: string
messages:
testMessage:
summary: Test message
Expand Down