forked from asyncapi/parser-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply-unique-ids.spec.ts
66 lines (65 loc) · 3.55 KB
/
apply-unique-ids.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 operations', async function() {
const input = {asyncapi: '3.0.0', operations: {testOperation: {}}};
const output = {...input, operations: {testOperation: {'x-parser-unique-object-id': 'testOperation'}}};
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);
});
it('should set unique id when input has channels under components', async function() {
const input = {asyncapi: '3.0.0', components: {channels: {testChannel: {}}}};
const output = {...input, components: {channels: {testChannel: {'x-parser-unique-object-id': 'testChannel'}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
it('should set unique id when input has operations under components', async function() {
const input = {asyncapi: '3.0.0', components: {operations: {testOperation: {}}}};
const output = {...input, components: {operations: {testOperation: {'x-parser-unique-object-id': 'testOperation'}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
it('should set unique id when input has messages in channels under components', async function() {
const input = {asyncapi: '3.0.0', components: {channels: {testChannel: {messages: {testMessage: {}}}}}};
const output = {...input, components: {channels: {testChannel: {'x-parser-unique-object-id': 'testChannel', messages: {testMessage: {'x-parser-unique-object-id': 'testMessage'}}}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
it('should set unique id when input has messages under components', async function() {
const input = {asyncapi: '3.0.0', components: { messages: {testMessage: {}}}};
const output = {...input, components: { messages: {testMessage: {'x-parser-unique-object-id': 'testMessage'}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
it('should not overwrite existing unique ids', async function() {
const input = {asyncapi: '3.0.0', components: { messages: {testMessage: {'x-parser-unique-object-id': 'testMessage2'}}}};
const output = {...input, components: { messages: {testMessage: {'x-parser-unique-object-id': 'testMessage2'}}}};
applyUniqueIds(input);
expect(input).toEqual(output);
});
});
});