Skip to content

Commit

Permalink
Display verb when expanding chapters.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Dec 11, 2024
1 parent 92c2bd4 commit 41446b8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion json_schemas/test_story.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ definitions:
synopsis:
type: string
description: A brief description of the chapter.
pattern: ^\p{Lu}[\s\S]*\.$
pattern: ^\p{Lu}[\s\S]*\.$|^\p{Lu}[\s\S]*\. \[(GET|PUT|POST|DELETE|PATCH|HEAD|OPTIONS)\]$
response:
$ref: '#/definitions/ExpectedResponse'
warnings:
Expand Down
5 changes: 1 addition & 4 deletions tools/src/tester/StoryEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,14 @@ export default class StoryEvaluator {
async #evaluate_chapters(chapters: ParsedChapter[], has_errors: boolean, dry_run: boolean, story_outputs: StoryOutputs, version?: string, distribution?: string): Promise<ChapterEvaluation[]> {
const evaluations: ChapterEvaluation[] = []
for (const chapter of chapters) {
const title = chapter.synopsis || `${chapter.method} ${chapter.path}`
if (dry_run) {
const title = chapter.synopsis || `${chapter.method} ${chapter.path}`
evaluations.push({ title, overall: { result: Result.SKIPPED, message: 'Dry Run' } })
} else if (distribution != undefined && chapter.distributions?.included !== undefined && chapter.distributions?.included.length > 0 && !chapter.distributions.included.includes(distribution)) {
const title = chapter.synopsis || `${chapter.method} ${chapter.path}`
evaluations.push({ title, overall: { result: Result.SKIPPED, message: `Skipped because distribution ${distribution} is not ${chapter.distributions.included.length > 1 ? 'one of ' : ''}${chapter.distributions.included.join(', ')}.` } })
} else if (distribution != undefined && chapter.distributions?.excluded !== undefined && chapter.distributions?.excluded.length > 0 && chapter.distributions.excluded.includes(distribution)) {
const title = chapter.synopsis || `${chapter.method} ${chapter.path}`
evaluations.push({ title, overall: { result: Result.SKIPPED, message: `Skipped because distribution ${distribution} is ${chapter.distributions.excluded.length > 1 ? 'one of ' : ''}${chapter.distributions.excluded.join(', ')}.` } })
} else if (version != undefined && chapter.version !== undefined && !semver.satisfies(version, chapter.version)) {
const title = chapter.synopsis || `${chapter.method} ${chapter.path}`
evaluations.push({ title, overall: { result: Result.SKIPPED, message: `Skipped because version ${version} does not satisfy ${chapter.version}.` } })
} else {
const evaluation = await this._chapter_evaluator.evaluate(chapter, has_errors, story_outputs)
Expand Down
8 changes: 6 additions & 2 deletions tools/src/tester/StoryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import _ from "lodash";
import { ChapterRequest, Story } from "./types/story.types";
import { Chapter, Story } from "./types/story.types";
import { ParsedChapter, ParsedStory } from "./types/parsed_story.types";

export default class StoryParser {
Expand All @@ -23,12 +23,16 @@ export default class StoryParser {
return [...(Array.isArray(methods) ? methods : [methods])]
}

static #expand_chapters(chapters?: ChapterRequest[]): ParsedChapter[] {
static #expand_chapters(chapters?: Chapter[]): ParsedChapter[] {
if (chapters === undefined) return []
return _.flatMap(_.map(chapters, (chapter) => {
return _.map(this.#chapter_methods(chapter.method), (method) => {
let synopsis = chapter.synopsis && Array.isArray(chapter.method) ?
`${chapter.synopsis} [${method}]` :
chapter.synopsis
return {
...chapter,
synopsis,
method
}
})
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/tester/StoryValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('StoryValidator', () => {
expect(evaluation?.result).toBe('ERROR')
expect(evaluation?.message).toBe("Invalid Story: " +
"data/description must match pattern \"^\\p{Lu}[\\s\\S]*\\.$\" --- " +
"data/chapters/0/synopsis must match pattern \"^\\p{Lu}[\\s\\S]*\\.$\"")
"data/chapters/0/synopsis must match pattern \"^\\p{Lu}[\\s\\S]*\\.$|^\\p{Lu}[\\s\\S]*\\. \\[(GET|PUT|POST|DELETE|PATCH|HEAD|OPTIONS)\\]$\"")
})

test('valid story', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ prologues:
overall:
result: PASSED
chapters:
- title: Create and update index.
- title: Create and update index. [PUT]
path: 'PUT /{index}'
overall:
result: PASSED
Expand All @@ -30,7 +30,7 @@ chapters:
result: PASSED
status:
result: PASSED
- title: Create and update index.
- title: Create and update index. [HEAD]
path: 'HEAD /{index}'
overall:
result: PASSED
Expand Down

0 comments on commit 41446b8

Please sign in to comment.