|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { describe, expect, test } from '@jest/globals' |
| 17 | +import { describe, expect, it, test } from '@jest/globals' |
18 | 18 | import * as fs from 'fs/promises' |
19 | 19 | import * as path from 'path' |
20 | 20 | import YAML from 'js-yaml' |
@@ -93,26 +93,53 @@ describe('AsyncAPI 3.0 Operation Tests', () => { |
93 | 93 | }) |
94 | 94 |
|
95 | 95 | describe('protocol', () => { |
96 | | - it('unit unique values', () => { |
97 | | - const data = [ |
98 | | - [{ |
99 | | - title: 'channel1', |
100 | | - servers: [{ |
101 | | - protocol: 'amqp', |
102 | | - }], |
103 | | - } as AsyncAPIV3.ChannelObject, 'result1'], |
104 | | - ] |
105 | | - data.forEach(([channel, expected]) => { |
106 | | - const result = extractProtocol(channel as AsyncAPIV3.ChannelObject) |
107 | | - expect(result).toBe(expected) |
108 | | - }) |
| 96 | + it('should uses the (first) server protocol when supported', () => { |
| 97 | + const channel = { |
| 98 | + title: 'channel1', |
| 99 | + servers: [ |
| 100 | + { protocol: 'amqp' }, |
| 101 | + { protocol: 'kafka' }, |
| 102 | + ], |
| 103 | + } as unknown as AsyncAPIV3.ChannelObject |
| 104 | + |
| 105 | + expect(extractProtocol(channel)).toBe('amqp') |
| 106 | + }) |
| 107 | + |
| 108 | + it('should returns unknown for unsupported protocol', () => { |
| 109 | + const channel = { |
| 110 | + title: 'channel1', |
| 111 | + servers: [ |
| 112 | + { protocol: 'mqtt' }, |
| 113 | + { protocol: 'amqp' }, |
| 114 | + ], |
| 115 | + } as unknown as AsyncAPIV3.ChannelObject |
| 116 | + |
| 117 | + expect(extractProtocol(channel)).toBe('unknown') |
| 118 | + }) |
| 119 | + |
| 120 | + it('should returns first server with protocol', () => { |
| 121 | + const channel = { |
| 122 | + title: 'channel1', |
| 123 | + servers: [ |
| 124 | + { $ref: '#/servers/amqp1' }, |
| 125 | + { protocol: 'amqp' }, |
| 126 | + ], |
| 127 | + } as unknown as AsyncAPIV3.ChannelObject |
| 128 | + |
| 129 | + expect(extractProtocol(channel)).toBe('unknown') |
| 130 | + }) |
| 131 | + |
| 132 | + it('should returns unknown when servers are missing or empty', () => { |
| 133 | + expect(extractProtocol({ title: 'no-servers' } as unknown as AsyncAPIV3.ChannelObject)).toBe('unknown') |
| 134 | + expect(extractProtocol({ title: 'empty-servers', servers: [] } as unknown as AsyncAPIV3.ChannelObject)).toBe('unknown') |
109 | 135 | }) |
110 | 136 |
|
111 | 137 | it('e2e', async () => { |
112 | 138 | const result = await buildPackage('asyncapi/operations/single-operation') |
113 | 139 | const operations = Array.from(result.operations.values()) |
114 | 140 | const [operation] = operations |
115 | | - expect(operation.metadata.protocol).toBe('protocol') |
| 141 | + // In test spec, channel's first server is amqp. |
| 142 | + expect(operation.metadata.protocol).toBe('amqp') |
116 | 143 | }) |
117 | 144 | }) |
118 | 145 |
|
|
0 commit comments