Skip to content

Commit

Permalink
add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Nov 28, 2023
1 parent f80a23b commit d8d9c1a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/custom-operations/apply-unique-ids.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { applyUniqueIds } from '../../src/custom-operations';

describe('applying unique ids', function() {
it('should not do anything for v2 inputs', async function() {
const input = {asyncapi: '2.0.0'};
const output = {...input};
applyUniqueIds(output);
expect(input).toEqual(output);
});
describe('for v3', function() {
it('should work with no channels input', async function() {
const input = {asyncapi: '3.0.0'};
const output = {...input};
applyUniqueIds(output);
expect(input).toEqual(output);
});
it('should set unique id when input has channels', async function() {
const input = {asyncapi: '3.0.0', channels: {testChannel: {}}};
const output = {...input, channels: {testChannel: {'x-parser-unique-object-id': 'testChannel'}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
it('should set unique id when input has messages in channels', async function() {
const input = {asyncapi: '3.0.0', channels: {testChannel: {messages: {testMessage: {}}}}};
const output = {...input, channels: {testChannel: {'x-parser-unique-object-id': 'testChannel', messages: {testMessage: {'x-parser-unique-object-id': 'testMessage'}}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
});
});

0 comments on commit d8d9c1a

Please sign in to comment.