@@ -2,7 +2,11 @@ import { createHttpClient } from "../src/ts/conformanceApi";
2
2
import { expect , should } from "chai" ;
3
3
import fetch from "node-fetch" ;
4
4
import conformanceTestsJson from "../ConformanceTests.json" ;
5
+ import { isDeepStrictEqual } from "util" ;
5
6
7
+ const tests = conformanceTestsJson . tests ;
8
+
9
+ validateTests ( ) ;
6
10
should ( ) ;
7
11
8
12
const httpClient = createHttpClient ( {
@@ -12,7 +16,7 @@ const httpClient = createHttpClient({
12
16
} ) ;
13
17
14
18
describe ( "tests" , ( ) => {
15
- conformanceTestsJson . tests . forEach ( ( data : any ) => {
19
+ tests . forEach ( ( data : any ) => {
16
20
it ( data . test , async ( ) => {
17
21
return ( httpClient as any )
18
22
[ data . method ] ( data . request )
@@ -28,3 +32,27 @@ describe("tests", () => {
28
32
} ) ;
29
33
} ) ;
30
34
} ) ;
35
+
36
+ function validateTests ( ) {
37
+ tests . forEach ( ( data ) => {
38
+ if ( ! data . test ) {
39
+ throw new Error ( `Test is missing 'test'` ) ;
40
+ }
41
+ if ( ! data . method ) {
42
+ throw new Error ( `'${ data . test } ' is missing 'method'` ) ;
43
+ }
44
+ if ( data . httpRequest && ! data . httpRequest . method ) {
45
+ throw new Error ( `Test '${ data . test } ' is missintg 'httpRequest.method'` ) ;
46
+ }
47
+ if ( data . httpRequest && ! data . httpRequest . path ) {
48
+ throw new Error ( `Test '${ data . test } ' is missintg 'httpRequest.path'` ) ;
49
+ }
50
+ if ( tests . filter ( ( x ) => x . test === data . test ) . length !== 1 ) {
51
+ throw new Error ( `Multiple tests found with name '${ data . test } '` ) ;
52
+ }
53
+ if ( tests . filter ( ( x ) => x . method === data . method && isDeepStrictEqual ( x . request , data . request ) ) . length !== 1 ) {
54
+ throw new Error ( `Multiple tests found for with method '${ data . method } ' and request '${ JSON . stringify ( data . request ) } '` ) ;
55
+ }
56
+ } ) ;
57
+ }
58
+
0 commit comments