Skip to content

Commit 9858fdb

Browse files
authored
test: add missing unit tests to utils (#292)
- add a few missing unit tests - exclude generated ajv validators from code coverage metrics
1 parent 718e3fc commit 9858fdb

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

packages/openapi-code-generator/src/core/schemas/openapi-3.0-specification-validator.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** AUTOGENERATED - DO NOT EDIT **/
22
// @ts-nocheck
3+
/* istanbul ignore file */
4+
/* c8 ignore start */
35
"use strict"
46
module.exports = validate10
57
module.exports.default = validate10
@@ -18759,3 +18761,4 @@ function validate10(
1875918761
validate10.errors = vErrors
1876018762
return errors === 0
1876118763
}
18764+
/* c8 ignore end */

packages/openapi-code-generator/src/core/schemas/openapi-3.1-specification-validator.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** AUTOGENERATED - DO NOT EDIT **/
22
// @ts-nocheck
3+
/* istanbul ignore file */
4+
/* c8 ignore start */
35

46
"use strict"
57
const {logger} = require("../logger")
@@ -12,3 +14,5 @@ function validate() {
1214
)
1315
return true
1416
}
17+
18+
/* c8 ignore end */

packages/openapi-code-generator/src/core/utils.spec.ts

+62
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,50 @@ import {describe, expect, it} from "@jest/globals"
22
import {
33
camelCase,
44
coalesce,
5+
hasSingleElement,
6+
isDefined,
7+
isHttpMethod,
58
kebabCase,
69
mediaTypeToIdentifier,
710
normalizeFilename,
811
snakeCase,
912
titleCase,
13+
upperFirst,
1014
} from "./utils"
1115

1216
describe("core/utils", () => {
17+
describe("#isDefined", () => {
18+
it.each([
19+
["", true],
20+
[0, true],
21+
[false, true],
22+
[null, true],
23+
[undefined, false],
24+
])("%s -> %s", (input, expected) => {
25+
expect(isDefined(input)).toBe(expected)
26+
})
27+
})
28+
29+
describe("#hasSingleElement", () => {
30+
it.each([
31+
[[], false],
32+
[[1], true],
33+
[[1, 2], false],
34+
])("%s -> %s", (input, expected) => {
35+
expect(hasSingleElement(input)).toBe(expected)
36+
})
37+
})
38+
39+
describe("#isHttpMethod", () => {
40+
it.each([
41+
["GET", true],
42+
["post", true],
43+
["random", false],
44+
])("%s -> %s", (input, expected) => {
45+
expect(isHttpMethod(input)).toBe(expected)
46+
})
47+
})
48+
1349
describe("#coalesce", () => {
1450
it("returns the first defined parameter", () => {
1551
expect(coalesce(null, undefined, 1, 2)).toBe(1)
@@ -32,11 +68,37 @@ describe("core/utils", () => {
3268
["single", "Single"],
3369
["two words", "TwoWords"],
3470
["camelCase", "CamelCase"],
71+
["pipe-case", "PipeCase"],
72+
["snake_case", "SnakeCase"],
3573
])("%s -> %s", (input, expected) => {
3674
expect(titleCase(input)).toBe(expected)
3775
})
3876
})
3977

78+
describe("#camelCase", () => {
79+
it.each([
80+
["single", "single"],
81+
["two words", "twoWords"],
82+
["camelCase", "camelCase"],
83+
["pipe-case", "pipeCase"],
84+
["snake_case", "snakeCase"],
85+
])("%s -> %s", (input, expected) => {
86+
expect(camelCase(input)).toBe(expected)
87+
})
88+
})
89+
90+
describe("#upperFirst", () => {
91+
it.each([
92+
["single", "Single"],
93+
["two words", "Two words"],
94+
["camelCase", "CamelCase"],
95+
["pipe-case", "Pipe-case"],
96+
["snake_case", "Snake_case"],
97+
])("%s -> %s", (input, expected) => {
98+
expect(upperFirst(input)).toBe(expected)
99+
})
100+
})
101+
40102
describe("#normalizeFilename", () => {
41103
const cases = [
42104
{

scripts/generate-ajv-validator.js

+3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ const writeOutput = async (filepath, moduleCode) => {
3333
const raw = `
3434
/** AUTOGENERATED - DO NOT EDIT **/
3535
// @ts-nocheck
36+
/* istanbul ignore file */
37+
/* c8 ignore start */
3638
${moduleCode}
39+
/* c8 ignore end */
3740
`
3841

3942
const biome = await Biome.create({

0 commit comments

Comments
 (0)