-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/169-MUST-use-standard-formats-for-date-and-time-properties.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import { loadOpenApiSpec, lint } from './helpers'; | ||
|
||
describe('MUST use standard formats for date and time properties [169]', () => { | ||
test('Providing an example should not warn', async () => { | ||
const openApi = await loadOpenApiSpec('base-openapi.yml'); | ||
const result = await lint(openApi); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('Not providing an example should warn', async () => { | ||
const openApi = await loadOpenApiSpec('base-openapi.yml'); | ||
delete openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties.rule169.example; | ||
const result = await lint(openApi); | ||
expect(result).toEqual([ | ||
expect.objectContaining({ | ||
code: 'must-use-standard-formats-for-date-and-time-properties-example', | ||
message: 'You should provide an example for rule169.example', | ||
severity: DiagnosticSeverity.Warning, | ||
}), | ||
]); | ||
}); | ||
|
||
test('Not providing an example in a nested structure should warn', async () => { | ||
const openApi = await loadOpenApiSpec('base-openapi.yml'); | ||
|
||
openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties = { | ||
...openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties, | ||
rule169nested: { | ||
type: 'object', | ||
properties: { | ||
second: { | ||
type: 'string', | ||
format: 'date-time', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const result = await lint(openApi); | ||
expect(result).toEqual([ | ||
expect.objectContaining({ | ||
code: 'must-use-standard-formats-for-date-and-time-properties-example', | ||
message: 'You should provide an example for second.example', | ||
severity: DiagnosticSeverity.Warning, | ||
}), | ||
]); | ||
}); | ||
|
||
test.each(['date-time', 'date', 'time', 'duration', 'period'])( | ||
'Not providing an example for format %s should warn', | ||
async (format) => { | ||
const openApi = await loadOpenApiSpec('base-openapi.yml'); | ||
|
||
openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties = { | ||
...openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties, | ||
rule169format: { | ||
type: 'string', | ||
format, | ||
}, | ||
}; | ||
|
||
const result = await lint(openApi); | ||
expect(result).toEqual([ | ||
expect.objectContaining({ | ||
code: 'must-use-standard-formats-for-date-and-time-properties-example', | ||
message: 'You should provide an example for rule169format.example', | ||
severity: DiagnosticSeverity.Warning, | ||
}), | ||
]); | ||
}, | ||
); | ||
|
||
test('Not using UTC should warn', async () => { | ||
const openApi = await loadOpenApiSpec('base-openapi.yml'); | ||
openApi.paths['/example'].patch.requestBody.content['application/json'].schema.properties.rule169.example = | ||
'2015-05-28T14:07:17+00:00'; | ||
const result = await lint(openApi); | ||
expect(result).toEqual([ | ||
expect.objectContaining({ | ||
code: 'must-use-standard-formats-for-date-and-time-properties-utc', | ||
message: 'You should UTC for example', | ||
severity: DiagnosticSeverity.Warning, | ||
}), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters