persona-community-5/.pnpm-store/v3/files/af/f0722bd20b893590f1964cb65302fd4bde4dd1cc2be8dec948e9b201d7de8d85a6da4aac7e50f55be0f32a0f7de5f3866a4f1fe7307e66a95672ceaa674ee1
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

114 lines
3.0 KiB
Plaintext

import { outdent } from 'outdent';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { lintDocument } from '../../../lint';
import { BaseResolver } from '../../../resolve';
describe('oas3 boolean-parameter-prefixes', () => {
it('should report on boolean param without prefix', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: a
in: path
schema:
type: boolean
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'boolean-parameter-prefixes': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1test/parameters/0/name",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Boolean parameter \`a\` should have \`is\` or \`has\` prefix.",
"ruleId": "boolean-parameter-prefixes",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should not report on boolean param with prefix', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: hasA
in: path
schema:
type: boolean
- name: isA
in: path
schema:
type: boolean
- name: has_a
in: path
schema:
type: boolean
- name: is-a
in: path
schema:
type: boolean
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'boolean-parameter-prefixes': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should not report on boolean param with custom prefix', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: should-a
in: query
schema:
type: boolean
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({
rules: {
'boolean-parameter-prefixes': {
severity: 'error',
prefixes: ['should'],
},
},
}),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});