UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

98 lines (88 loc) 2.75 kB
import { outdent } from 'outdent'; import { lintDocument } from '../../../lint'; import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils'; import { BaseResolver } from '../../../resolve'; describe('no-channel-trailing-slash', () => { it('should report on trailing slash in a channel path', async () => { const document = parseYamlToDocument( outdent` asyncapi: '2.6.0' info: title: Excellent API version: 1.0.0 channels: /trailing/: subscribe: message: messageId: Message1 `, 'asyncapi.yaml' ); const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, config: await makeConfig({ 'no-channel-trailing-slash': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` Array [ Object { "location": Array [ Object { "pointer": "#/channels/~1trailing~1", "reportOnKey": true, "source": "asyncapi.yaml", }, ], "message": "\`/trailing/\` should not have a trailing slash.", "ruleId": "no-channel-trailing-slash", "severity": "error", "suggest": Array [], }, ] `); }); it('should not report on if no trailing slash in path', async () => { const document = parseYamlToDocument( outdent` asyncapi: '2.6.0' info: title: Excellent API version: 1.0.0 channels: /expected: subscribe: message: messageId: Message1 `, 'asyncapi.yaml' ); const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, config: await makeConfig({ 'no-channel-trailing-slash': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); }); it('should not report on trailing slash in path if the path is root', async () => { const document = parseYamlToDocument( outdent` asyncapi: '2.6.0' info: title: Excellent API version: 1.0.0 channels: /: subscribe: message: messageId: Message1 `, 'foobar.yaml' ); const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, config: await makeConfig({ 'no-channel-trailing-slash': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); }); });