persona-community-5/.pnpm-store/v3/files/7c/25ace36776166decbb92efa8c1e99d9ad4d7e0020bcc1a07cd36e0a0110aee788a2a77367caa418d26163c6d00f057bb1a119f41e5494b544d33a68e3b5882
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

146 lines
3.7 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('Async2 channels-kebab-case', () => {
it('should report on no kebab-case channel path', async () => {
const document = parseYamlToDocument(
outdent`
asyncapi: '2.6.0'
info:
title: Cool API
version: 1.0.0
channels:
NOT_A_KEBAB:
subscribe:
message:
messageId: Message1
`,
'asyncapi.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'channels-kebab-case': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/channels/NOT_A_KEBAB",
"reportOnKey": true,
"source": "asyncapi.yaml",
},
],
"message": "\`NOT_A_KEBAB\` does not use kebab-case.",
"ruleId": "channels-kebab-case",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should report on snake_case in channel path', async () => {
const document = parseYamlToDocument(
outdent`
asyncapi: '2.6.0'
info:
title: Cool API
version: 1.0.0
channels:
snake_kebab:
subscribe:
message:
messageId: Message1
`,
'asyncapi.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'channels-kebab-case': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/channels/snake_kebab",
"reportOnKey": true,
"source": "asyncapi.yaml",
},
],
"message": "\`snake_kebab\` does not use kebab-case.",
"ruleId": "channels-kebab-case",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should allow trailing slash in channel path with "channels-kebab-case" rule', async () => {
const document = parseYamlToDocument(
outdent`
asyncapi: '2.6.0'
info:
title: Cool API
version: 1.0.0
channels:
kebab/:
subscribe:
message:
messageId: Message1
`,
'asyncapi.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({
rules: {
'paths-kebab-case': 'error',
'no-path-trailing-slash': 'off',
},
}),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('words with hyphens are allowed with "channels-kebab-case" rule', async () => {
const document = parseYamlToDocument(
outdent`
asyncapi: '2.6.0'
info:
title: Cool API
version: 1.0.0
channels:
kebab-with-longer-channel-path:
subscribe:
message:
messageId: Message1
`,
'asyncapi.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({
rules: {
'paths-kebab-case': 'error',
},
}),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});