Skip to content

Commit 1e0465f

Browse files
committed
feat: Add tests for apikind
1 parent 86b45b4 commit 1e0465f

File tree

7 files changed

+164
-68
lines changed

7 files changed

+164
-68
lines changed

src/apitypes/async/async.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { v3 as AsyncAPIV3 } from '@asyncapi/parser/esm/spec-types'
1818
import { isObject } from '../../utils'
1919
import { AsyncOperationActionType, AsyncProtocol } from './async.types'
2020
import { normalize } from '@netcracker/qubership-apihub-api-unifier'
21-
import { APIHUB_API_COMPATIBILITY_KIND_BWC, ApihubApiCompatibilityKind } from '../../consts'
2221
import { ASYNC_SUPPORTED_PROTOCOLS } from './async.consts'
22+
import { APIHUB_API_COMPATIBILITY_KIND_BWC, ApihubApiCompatibilityKind } from '../../consts'
2323

2424
// Re-export shared utilities
2525
export { dump, getCustomTags, resolveApiAudience } from '../../utils/apihubSpecificationExtensions'
@@ -100,8 +100,8 @@ export function toExternalDocumentationObject(
100100
}
101101

102102
export const calculateAsyncApiKind = (
103-
channelApiKind: ApihubApiCompatibilityKind | undefined,
104103
operationApiKind: ApihubApiCompatibilityKind | undefined,
104+
channelApiKind: ApihubApiCompatibilityKind | undefined,
105105
): ApihubApiCompatibilityKind => {
106-
return channelApiKind || operationApiKind || APIHUB_API_COMPATIBILITY_KIND_BWC
106+
return operationApiKind || channelApiKind || APIHUB_API_COMPATIBILITY_KIND_BWC
107107
}

test/async.operation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('AsyncAPI 3.0 Operation Tests', () => {
109109
})
110110

111111
it('e2e', async () => {
112-
const result = await buildPackage('asyncapi/operations/additional-data-and-metadata')
112+
const result = await buildPackage('asyncapi/operations/single-operation')
113113
const operations = Array.from(result.operations.values())
114114
const [operation] = operations
115115
expect(operation.metadata.protocol).toBe('protocol')

test/asyncapi-apikind.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
APIHUB_API_COMPATIBILITY_KIND_BWC,
3+
APIHUB_API_COMPATIBILITY_KIND_NO_BWC,
4+
ApihubApiCompatibilityKind,
5+
} from '../src'
6+
import { calculateAsyncApiKind } from '../src/apitypes/async/async.utils'
7+
import { buildPackage } from './helpers'
8+
9+
describe('apiKind', () => {
10+
it('unit unique values', () => {
11+
const data = [
12+
[undefined, undefined, APIHUB_API_COMPATIBILITY_KIND_BWC],
13+
[APIHUB_API_COMPATIBILITY_KIND_BWC, undefined, APIHUB_API_COMPATIBILITY_KIND_BWC],
14+
[undefined, APIHUB_API_COMPATIBILITY_KIND_BWC, APIHUB_API_COMPATIBILITY_KIND_BWC],
15+
[APIHUB_API_COMPATIBILITY_KIND_NO_BWC, undefined, APIHUB_API_COMPATIBILITY_KIND_NO_BWC],
16+
[undefined, APIHUB_API_COMPATIBILITY_KIND_NO_BWC, APIHUB_API_COMPATIBILITY_KIND_NO_BWC],
17+
[APIHUB_API_COMPATIBILITY_KIND_BWC, APIHUB_API_COMPATIBILITY_KIND_NO_BWC, APIHUB_API_COMPATIBILITY_KIND_BWC],
18+
[APIHUB_API_COMPATIBILITY_KIND_NO_BWC, APIHUB_API_COMPATIBILITY_KIND_BWC, APIHUB_API_COMPATIBILITY_KIND_NO_BWC],
19+
]
20+
data.forEach(([operationApiKind, channelApiKind, expected]) => {
21+
const result = calculateAsyncApiKind(operationApiKind as ApihubApiCompatibilityKind, channelApiKind as ApihubApiCompatibilityKind)
22+
expect(result).toBe(expected)
23+
})
24+
})
25+
26+
it('e2e', async () => {
27+
const result = await buildPackage('asyncapi/api-kind/base')
28+
const operations = Array.from(result.operations.values())
29+
30+
const [
31+
operation,
32+
operationWithCannelBwc,
33+
operationWithCannelNoBwc,
34+
operationBwc,
35+
operationNoBwc,
36+
operationBwcWithChannelBwc,
37+
operationBwcWithChannelNoBwc,
38+
operationNoBwcWithChannelBwc,
39+
operationNoBwcWithChannelNoBwc,
40+
] = operations
41+
expect(operation.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_BWC)
42+
expect(operationWithCannelBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_BWC)
43+
expect(operationWithCannelNoBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_NO_BWC)
44+
expect(operationBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_BWC)
45+
expect(operationNoBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_NO_BWC)
46+
expect(operationBwcWithChannelBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_BWC)
47+
expect(operationBwcWithChannelNoBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_BWC)
48+
expect(operationNoBwcWithChannelBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_NO_BWC)
49+
expect(operationNoBwcWithChannelNoBwc.apiKind).toEqual(APIHUB_API_COMPATIBILITY_KIND_NO_BWC)
50+
})
51+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"packageId": "asyncapi-operations",
3+
"version": "v1",
4+
"files": [
5+
{
6+
"fileId": "spec.yaml",
7+
"publish": true,
8+
"labels": []
9+
}
10+
]
11+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Account Service
4+
version: 1.0.0
5+
description: This service is in charge of processing user signups
6+
channels:
7+
channel:
8+
address: user/signedup
9+
messages:
10+
UserSignedUp:
11+
$ref: '#/components/messages/UserSignedUp'
12+
channel-bwc:
13+
x-api-kind: BWC
14+
address: user/signedup
15+
messages:
16+
UserSignedUp:
17+
$ref: '#/components/messages/UserSignedUp'
18+
channel-no-bwc:
19+
x-api-kind: no-BWC
20+
address: user/signedup
21+
messages:
22+
UserSignedUp:
23+
$ref: '#/components/messages/UserSignedUp'
24+
operations:
25+
operation:
26+
action: send
27+
channel:
28+
$ref: '#/channels/channel'
29+
messages:
30+
- $ref: '#/channels/channel/messages/UserSignedUp'
31+
operation-with-cannel-bwc:
32+
action: send
33+
channel:
34+
$ref: '#/channels/channel-bwc'
35+
messages:
36+
- $ref: '#/channels/channel-bwc/messages/UserSignedUp'
37+
operation-with-cannel-no-bwc:
38+
action: send
39+
channel:
40+
$ref: '#/channels/channel-no-bwc'
41+
messages:
42+
- $ref: '#/channels/channel-no-bwc/messages/UserSignedUp'
43+
operation-bwc:
44+
x-api-kind: BWC
45+
action: send
46+
channel:
47+
$ref: '#/channels/channel'
48+
messages:
49+
- $ref: '#/channels/channel/messages/UserSignedUp'
50+
operation-no-bwc:
51+
x-api-kind: no-BWC
52+
action: send
53+
channel:
54+
$ref: '#/channels/channel'
55+
messages:
56+
- $ref: '#/channels/channel/messages/UserSignedUp'
57+
operation-bwc-with-channel-bwc:
58+
x-api-kind: BWC
59+
action: send
60+
channel:
61+
$ref: '#/channels/channel-bwc'
62+
messages:
63+
- $ref: '#/channels/channel-bwc/messages/UserSignedUp'
64+
operation-bwc-with-channel-no-bwc:
65+
x-api-kind: BWC
66+
action: send
67+
channel:
68+
$ref: '#/channels/channel-no-bwc'
69+
messages:
70+
- $ref: '#/channels/channel-no-bwc/messages/UserSignedUp'
71+
operation-no-bwc-with-channel-bwc:
72+
x-api-kind: no-BWC
73+
action: send
74+
channel:
75+
$ref: '#/channels/channel-bwc'
76+
messages:
77+
- $ref: '#/channels/channel-bwc/messages/UserSignedUp'
78+
operation-no-bwc-with-channel-no-bwc:
79+
x-api-kind: no-BWC
80+
action: send
81+
channel:
82+
$ref: '#/channels/channel-no-bwc'
83+
messages:
84+
- $ref: '#/channels/channel-no-bwc/messages/UserSignedUp'
85+
components:
86+
messages:
87+
UserSignedUp:
88+
title: User Signed Up
89+
payload:
90+
type: object
91+
properties:
92+
displayName:
93+
type: string
94+
description: Name of the user
95+
email:
96+
type: string
97+
format: email
98+
description: Email of the user

test/projects/asyncapi/api-kind/channels/channel-api-kind.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/projects/asyncapi/api-kind/operation/operation-api-kind.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)