-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add unit tests #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thulieblack
wants to merge
4
commits into
derberg:main
Choose a base branch
from
thulieblack:unit-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import filenamify from 'filenamify'; | ||
|
|
||
| /** | ||
| * Converts a channel address into a safe filename. | ||
| * - Splits the address by '/' and formats each part to lowercase. | ||
| * - Uses `filenamify` to remove invalid filename characters. | ||
| * | ||
| * @param {string} channelAddress - The original channel address. | ||
| * @returns {string} A sanitized and formatted filename. | ||
| */ | ||
|
|
||
| export function convertChannelToFilename(channelAddress) { | ||
| if (!channelAddress) return ''; | ||
|
|
||
| const formatted = channelAddress | ||
| .split('/').map(word => word.charAt(0).toLowerCase() + word.slice(1)).join(''); | ||
|
|
||
| return filenamify(formatted, { replacement: '-', maxLength: 255 }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { | ||
| getServiceClientName, | ||
| getServiceClientDescription, | ||
| getClientClassName, | ||
| getFunctionName, | ||
| getFunctionDetails, | ||
| getSendOperations, | ||
| getReceiveOperations | ||
| } from '../components/helpers/utils'; | ||
|
|
||
| describe('Service Client Helpers', () => { | ||
| const mockAsyncAPI = { | ||
| info: jest.fn(() => ({ | ||
| title: jest.fn(() => 'TestService'), | ||
| description: jest.fn(() => 'Test Service Description'), | ||
| hasDescription: jest.fn(() => true) | ||
| })), | ||
| }; | ||
|
|
||
| const mockAsyncAPIWithoutDesc = { | ||
| info: jest.fn(() => ({ | ||
| title: jest.fn(() => 'TestService'), | ||
| description: jest.fn(() => undefined), | ||
| hasDescription: jest.fn(() => false) | ||
| })), | ||
| }; | ||
|
|
||
| const mockOperations = [ | ||
| { | ||
| hasOperationId: jest.fn(() => true), | ||
| operationId: jest.fn(() => 'sendTestOperation'), | ||
| id: jest.fn(() => 'sendTestOperation'), | ||
| channels: jest.fn(() => [{ address: jest.fn(() => 'test/topic') }]), | ||
| summary: jest.fn(() => 'Test Operation Summary'), | ||
| isSend: jest.fn(() => true), | ||
| isReceive: jest.fn(() => false), | ||
| }, | ||
| { | ||
| hasOperationId: jest.fn(() => true), | ||
| operationId: jest.fn(() => 'receiveTestOperation'), | ||
| id: jest.fn(() => 'receiveTestOperation'), | ||
| channels: jest.fn(() => [{ address: jest.fn(() => 'test/topic') }]), | ||
| summary: jest.fn(() => 'Test Operation Summary'), | ||
| isSend: jest.fn(() => false), | ||
| isReceive: jest.fn(() => true), | ||
| } | ||
| ]; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('getServiceClientName', () => { | ||
| it('should return the correct service client name', () => { | ||
| const result = getServiceClientName(mockAsyncAPI); | ||
| expect(result).toEqual('TestService Client'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getServiceClientDescription', () => { | ||
| it('should return the correct service client description', () => { | ||
| const result = getServiceClientDescription(mockAsyncAPI); | ||
| expect(result).toEqual('Test Service Description'); | ||
| }); | ||
|
|
||
| it('should return empty string if no description provided', () => { | ||
| const result = getServiceClientDescription(mockAsyncAPIWithoutDesc); | ||
| expect(result).toEqual(''); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getClientClassName', () => { | ||
| it('should return the correct client class name', () => { | ||
| const result = getClientClassName(mockAsyncAPI); | ||
| expect(result).toEqual('TestServiceClient'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getFunctionName', () => { | ||
| it('should return the correct function name for a given operation', () => { | ||
| const result = getFunctionName(mockOperations[0]); | ||
thulieblack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(result).toEqual('sendTestOperation'); | ||
| }); | ||
|
|
||
| it('should return the correct function name using convertChannelToFilename if operationId is not available', () => { | ||
| mockOperations[0].hasOperationId.mockReturnValue(false); | ||
| const result = getFunctionName(mockOperations[0]); | ||
| expect(result).toEqual('sendTestOperation'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getFunctionDetails', () => { | ||
| it('should return the correct function details for operations', () => { | ||
| const result = getFunctionDetails(mockOperations); | ||
| expect(result).toEqual([ | ||
| { functionName: 'sendTestOperation', topic: 'test/topic', summary: 'Test Operation Summary' }, | ||
| { functionName: 'receiveTestOperation', topic: 'test/topic', summary: 'Test Operation Summary' } | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSendOperations', () => { | ||
| it('should return only send operations', () => { | ||
| const result = getSendOperations(mockOperations); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0].operationId()).toEqual('sendTestOperation'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getReceiveOperations', () => { | ||
| it('should return only receive operations', () => { | ||
| const result = getReceiveOperations(mockOperations); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0].operationId()).toEqual('receiveTestOperation'); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.