1
1
import * as dgraph from "../src" ;
2
2
import { Request } from "../src/types" ;
3
3
4
- import { setup } from "./helper" ;
4
+ import { SERVER_ADDR , setup } from "./helper" ;
5
5
6
6
async function checkHealth ( stub : dgraph . DgraphClientStub ) : Promise < void > {
7
- await expect ( stub . getHealth ( ) ) . resolves . toHaveProperty ( "0.status" , "healthy" ) ;
7
+ await expect ( stub . getHealth ( ) ) . resolves . toHaveProperty (
8
+ "0.status" ,
9
+ "healthy" ,
10
+ ) ;
8
11
}
9
12
10
13
describe ( "clientStub" , ( ) => {
11
14
describe ( "constructor" , ( ) => {
12
15
it ( "should accept undefined argument" , async ( ) => {
13
16
await checkHealth ( new dgraph . DgraphClientStub ( ) ) ;
14
17
} ) ;
18
+ it ( "should accept custom JSON parser" , async ( ) => {
19
+ const mockParser = jest . fn ( ( input : string ) => ( { input } ) ) ;
20
+ const stub = new dgraph . DgraphClientStub ( SERVER_ADDR , {
21
+ jsonParser : mockParser ,
22
+ } ) ;
23
+ await expect (
24
+ stub . query ( {
25
+ query : "{ q(func: uid(1)) { uid } }" ,
26
+ } ) ,
27
+ ) . resolves . toBeTruthy ( ) ;
28
+ expect ( mockParser . mock . calls . length ) . toBe ( 1 ) ;
29
+ } ) ;
15
30
} ) ;
16
31
17
32
describe ( "health" , ( ) => {
@@ -24,9 +39,9 @@ describe("clientStub", () => {
24
39
describe ( "fetchUiKeywords" , ( ) => {
25
40
it ( "should return keywords object" , async ( ) => {
26
41
const client = await setup ( ) ;
27
- await expect ( client . anyClient ( ) . fetchUiKeywords ( ) )
28
- . resolves
29
- . toHaveProperty ( "keywords" ) ;
42
+ await expect (
43
+ client . anyClient ( ) . fetchUiKeywords ( ) ,
44
+ ) . resolves . toHaveProperty ( "keywords" ) ;
30
45
const resp = await client . anyClient ( ) . fetchUiKeywords ( ) ;
31
46
expect ( resp . keywords ) . toContainEqual ( {
32
47
type : "" ,
@@ -53,7 +68,9 @@ describe("clientStub", () => {
53
68
// tslint:disable-next-line no-any
54
69
expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
55
70
// tslint:disable-next-line no-unsafe-any no-any
56
- expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 0 ] ) . toContain ( "timeout=777s" ) ;
71
+ expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 0 ] ) . toContain (
72
+ "timeout=777s" ,
73
+ ) ;
57
74
58
75
req . timeout = 0 ;
59
76
req . startTs = 0 ;
@@ -80,8 +97,10 @@ describe("clientStub", () => {
80
97
// tslint:disable-next-line no-any
81
98
expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
82
99
// tslint:disable-next-line no-unsafe-any no-any
83
- expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 1 ] . headers )
84
- . toHaveProperty ( "Content-Type" , "application/rdf" ) ;
100
+ expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 1 ] . headers ) . toHaveProperty (
101
+ "Content-Type" ,
102
+ "application/rdf" ,
103
+ ) ;
85
104
86
105
await stub . mutate ( {
87
106
mutation : '{ "setJson": { "name": "Alice" } }' ,
@@ -90,9 +109,10 @@ describe("clientStub", () => {
90
109
// tslint:disable-next-line no-any
91
110
expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 2 ) ;
92
111
// tslint:disable-next-line no-unsafe-any no-any
93
- expect ( ( < any > stub ) . callAPI . mock . calls [ 1 ] [ 1 ] . headers )
94
- . toHaveProperty ( "Content-Type" , "application/json" ) ;
95
-
112
+ expect ( ( < any > stub ) . callAPI . mock . calls [ 1 ] [ 1 ] . headers ) . toHaveProperty (
113
+ "Content-Type" ,
114
+ "application/json" ,
115
+ ) ;
96
116
} ) ;
97
117
98
118
it ( "should use specified Content-Type if present" , async ( ) => {
@@ -108,8 +128,10 @@ describe("clientStub", () => {
108
128
// tslint:disable-next-line no-any
109
129
expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
110
130
// tslint:disable-next-line no-unsafe-any no-any
111
- expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 1 ] . headers )
112
- . toHaveProperty ( "Content-Type" , "application/json" ) ;
131
+ expect ( ( < any > stub ) . callAPI . mock . calls [ 0 ] [ 1 ] . headers ) . toHaveProperty (
132
+ "Content-Type" ,
133
+ "application/json" ,
134
+ ) ;
113
135
114
136
await stub . mutate ( {
115
137
mutation : '{ "setJson": { "name": "Alice" } }' ,
@@ -119,9 +141,10 @@ describe("clientStub", () => {
119
141
// tslint:disable-next-line no-any
120
142
expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 2 ) ;
121
143
// tslint:disable-next-line no-unsafe-any no-any
122
- expect ( ( < any > stub ) . callAPI . mock . calls [ 1 ] [ 1 ] . headers )
123
- . toHaveProperty ( "Content-Type" , "application/rdf" ) ;
124
-
144
+ expect ( ( < any > stub ) . callAPI . mock . calls [ 1 ] [ 1 ] . headers ) . toHaveProperty (
145
+ "Content-Type" ,
146
+ "application/rdf" ,
147
+ ) ;
125
148
} ) ;
126
149
} ) ;
127
150
0 commit comments