Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lag-of-death committed Sep 4, 2019
1 parent b59ceda commit 5667936
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import { RuleType, Spectral } from '../../../spectral';
import * as ruleset from '../../oas2/index.json';

describe('parameter-description', () => {
const s = new Spectral();

s.setRules({
'parameter-description': Object.assign(ruleset.rules['parameter-description'], {
recommended: true,
type: RuleType[ruleset.rules['parameter-description'].type],
}),
});

export default (s: any) => {
test('should work for shared level parameters', async () => {
const results = await s.run({
swagger: '2.0',
Expand Down Expand Up @@ -66,27 +54,6 @@ describe('parameter-description', () => {
expect(results.length).toEqual(0);
});

test('return errors if shared level parameter description is missing', async () => {
const results = await s.run({
swagger: '2.0',
parameters: {
limit: {
name: 'limit',
in: 'query',
type: 'integer',
},
},
});
expect(results).toEqual([
expect.objectContaining({
code: 'parameter-description',
message: 'Parameter objects should have a `description`.',
path: ['parameters', 'limit'],
severity: 1,
}),
]);
});

test('return errors if top level path parameter description is missing', async () => {
const results = await s.run({
swagger: '2.0',
Expand Down Expand Up @@ -155,82 +122,4 @@ describe('parameter-description', () => {
}),
).not.rejects;
});

xdescribe('$.components.parameters', () => {
it('validates description', async () => {
const results = await s.run({
openapi: '3.0.2',
components: {
parameters: {
address: {
in: 'body',
},
},
},
});

expect(results).toEqual([
expect.objectContaining({
code: 'parameter-description',
message: 'Parameter objects should have a `description`.',
path: ['components', 'parameters', 'address'],
severity: 1,
}),
]);
});
});

xdescribe('description for parameters in links', () => {
describe('$.components.links', () => {
it('does not validate description', async () => {
const results = await s.run({
openapi: '3.0.2',
components: {
links: {
address: {
operationId: 'getUserAddressByUUID',
parameters: {
param: {
value: 'value',
in: 'header',
},
},
},
},
},
});

expect(results).toEqual([]);
});
});

describe('links in a response', () => {
it('does not validate description', async () => {
const results = await s.run({
paths: {
'/pets': {
get: {
responses: {
'200': {
links: {
abc: {
parameters: {
param: {
in: 'body',
val: 2,
},
},
},
},
},
},
},
},
},
});

expect(results).toEqual([]);
});
});
});
});
};
37 changes: 37 additions & 0 deletions src/rulesets/oas2/__tests__/oas2-parameter-description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { RuleType, Spectral } from '../../../spectral';
import testParameterDescription from '../../__tests__/shared/_parameter-description';
import * as ruleset from '../index.json';

describe('oas2-parameter-description', () => {
const s = new Spectral();

s.setRules({
'oas2-parameter-description': Object.assign(ruleset.rules['oas2-parameter-description'], {
recommended: true,
type: RuleType[ruleset.rules['oas2-parameter-description'].type],
}),
});

testParameterDescription(s);

test('return errors if shared level parameter description is missing', async () => {
const results = await s.run({
swagger: '2.0',
parameters: {
limit: {
name: 'limit',
in: 'query',
type: 'integer',
},
},
});
expect(results).toEqual([
expect.objectContaining({
code: 'oas2-parameter-description',
message: 'Parameter objects should have a `description`.',
path: ['parameters', 'limit'],
severity: 1,
}),
]);
});
});
94 changes: 94 additions & 0 deletions src/rulesets/oas3/__tests__/oas3-parameter-description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { RuleType, Spectral } from '../../../spectral';
import testParameterDescription from '../../__tests__/shared/_parameter-description';
import * as ruleset from '../index.json';

describe('oas3-parameter-description', () => {
const s = new Spectral();

s.setRules({
'oas3-parameter-description': Object.assign(ruleset.rules['oas3-parameter-description'], {
recommended: true,
type: RuleType[ruleset.rules['oas3-parameter-description'].type],
}),
});

testParameterDescription(s);

describe('$.components.parameters', () => {
it('validates description', async () => {
const results = await s.run({
openapi: '3.0.2',
components: {
parameters: {
address: {
in: 'body',
},
},
},
});

expect(results).toEqual([
expect.objectContaining({
code: 'oas3-parameter-description',
message: 'Parameter objects should have a `description`.',
path: ['components', 'parameters', 'address'],
severity: 1,
}),
]);
});
});

describe('description for parameters in links', () => {
describe('$.components.links', () => {
it('does not validate description', async () => {
const results = await s.run({
openapi: '3.0.2',
components: {
links: {
address: {
operationId: 'getUserAddressByUUID',
parameters: {
param: {
value: 'value',
in: 'header',
},
},
},
},
},
});

expect(results).toEqual([]);
});
});

describe('links in a response', () => {
it('does not validate description', async () => {
const results = await s.run({
paths: {
'/pets': {
get: {
responses: {
'200': {
links: {
abc: {
parameters: {
param: {
in: 'body',
val: 2,
},
},
},
},
},
},
},
},
},
});

expect(results).toEqual([]);
});
});
});
});

0 comments on commit 5667936

Please sign in to comment.