diff --git a/json_schemas/test_story.schema.yaml b/json_schemas/test_story.schema.yaml index 10f87a34..95751843 100644 --- a/json_schemas/test_story.schema.yaml +++ b/json_schemas/test_story.schema.yaml @@ -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: diff --git a/tools/src/tester/StoryEvaluator.ts b/tools/src/tester/StoryEvaluator.ts index 3ed87d7d..a17df942 100644 --- a/tools/src/tester/StoryEvaluator.ts +++ b/tools/src/tester/StoryEvaluator.ts @@ -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 { 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) diff --git a/tools/src/tester/StoryParser.ts b/tools/src/tester/StoryParser.ts index d9c4c773..21f507cd 100644 --- a/tools/src/tester/StoryParser.ts +++ b/tools/src/tester/StoryParser.ts @@ -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 { @@ -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 } }) diff --git a/tools/tests/tester/StoryValidator.test.ts b/tools/tests/tester/StoryValidator.test.ts index cc76a487..2feee018 100644 --- a/tools/tests/tester/StoryValidator.test.ts +++ b/tools/tests/tester/StoryValidator.test.ts @@ -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', () => { diff --git a/tools/tests/tester/fixtures/evals/passed/multiple_methods.yaml b/tools/tests/tester/fixtures/evals/passed/multiple_methods.yaml index 7132a94d..7627ee44 100644 --- a/tools/tests/tester/fixtures/evals/passed/multiple_methods.yaml +++ b/tools/tests/tester/fixtures/evals/passed/multiple_methods.yaml @@ -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 @@ -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