persona-community-5/.pnpm-store/v3/files/f1/879a618308bc41c4678d791139eefe2a994e3e9cde89f4d60d584add87f097cb11445ddcadb89e67acc1f8ef9bc3ec29e4c050c4405f3a2bf30a4ae8c8c03d
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

127 lines
3.3 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('no-path-trailing-slash', () => {
it('should report on trailing slash in path', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/bad/':
get:
summary: List all pets
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-path-trailing-slash': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1bad~1",
"reportOnKey": true,
"source": "foobar.yaml",
},
],
"message": "\`/bad/\` should not have a trailing slash.",
"ruleId": "no-path-trailing-slash",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should report on trailing slash in path on key when referencing', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/bad/':
$ref: '#/components/pathItems/MyItem'
components:
pathItems:
MyItem:
get:
summary: List all pets
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-path-trailing-slash': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1bad~1",
"reportOnKey": true,
"source": "foobar.yaml",
},
],
"message": "\`/bad/\` should not have a trailing slash.",
"ruleId": "no-path-trailing-slash",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should not report on if no trailing slash in path', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/good':
get:
summary: List all pets
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-path-trailing-slash': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should not report on trailing slash in path if the path is root', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/':
get:
summary: List all pets
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-path-trailing-slash': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});