@ibm-cloud/openapi-ruleset
Version:
Spectral ruleset for validating IBM Cloud services
53 lines (45 loc) • 1.36 kB
JavaScript
/**
* Copyright 2017 - 2024 IBM Corporation.
* SPDX-License-Identifier: Apache2.0
*/
const { errorContentTypeIsJson } = require('../../src/rules');
const {
makeCopy,
rootDocument,
testRule,
severityCodes,
} = require('../test-utils');
const ruleId = 'ibm-error-content-type-is-json';
const rule = errorContentTypeIsJson;
describe(`Spectral rule: ${ruleId}`, () => {
it('should not error with a clean spec', async () => {
const results = await testRule(ruleId, rule, rootDocument);
expect(results).toHaveLength(0);
});
it('should error if a response doesnt support application/json content', async () => {
const testDocument = makeCopy(rootDocument);
testDocument.paths['/v1/movies'].post.responses['500'] = {
content: {
'text/plain': {
description: 'just error text',
},
},
};
const results = await testRule(ruleId, rule, testDocument);
expect(results).toHaveLength(1);
const validation = results[0];
expect(validation.code).toBe(ruleId);
expect(validation.message).toBe(
'error response should support application/json'
);
expect(validation.path).toStrictEqual([
'paths',
'/v1/movies',
'post',
'responses',
'500',
'content',
]);
expect(validation.severity).toBe(severityCodes.warning);
});
});