11import * as dgraph from "../src" ;
22import { Request } from "../src/types" ;
33
4- import { setup } from "./helper" ;
4+ import { SERVER_ADDR , setup } from "./helper" ;
55
66async 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+ ) ;
811}
912
1013describe ( "clientStub" , ( ) => {
1114 describe ( "constructor" , ( ) => {
1215 it ( "should accept undefined argument" , async ( ) => {
1316 await checkHealth ( new dgraph . DgraphClientStub ( ) ) ;
1417 } ) ;
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+ } ) ;
1530 } ) ;
1631
1732 describe ( "health" , ( ) => {
@@ -24,9 +39,9 @@ describe("clientStub", () => {
2439 describe ( "fetchUiKeywords" , ( ) => {
2540 it ( "should return keywords object" , async ( ) => {
2641 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" ) ;
3045 const resp = await client . anyClient ( ) . fetchUiKeywords ( ) ;
3146 expect ( resp . keywords ) . toContainEqual ( {
3247 type : "" ,
@@ -53,7 +68,9 @@ describe("clientStub", () => {
5368 // tslint:disable-next-line no-any
5469 expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
5570 // 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+ ) ;
5774
5875 req . timeout = 0 ;
5976 req . startTs = 0 ;
@@ -80,8 +97,10 @@ describe("clientStub", () => {
8097 // tslint:disable-next-line no-any
8198 expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
8299 // 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+ ) ;
85104
86105 await stub . mutate ( {
87106 mutation : '{ "setJson": { "name": "Alice" } }' ,
@@ -90,9 +109,10 @@ describe("clientStub", () => {
90109 // tslint:disable-next-line no-any
91110 expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 2 ) ;
92111 // 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+ ) ;
96116 } ) ;
97117
98118 it ( "should use specified Content-Type if present" , async ( ) => {
@@ -108,8 +128,10 @@ describe("clientStub", () => {
108128 // tslint:disable-next-line no-any
109129 expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 1 ) ;
110130 // 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+ ) ;
113135
114136 await stub . mutate ( {
115137 mutation : '{ "setJson": { "name": "Alice" } }' ,
@@ -119,9 +141,10 @@ describe("clientStub", () => {
119141 // tslint:disable-next-line no-any
120142 expect ( ( < any > stub ) . callAPI ) . toHaveBeenCalledTimes ( 2 ) ;
121143 // 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+ ) ;
125148 } ) ;
126149 } ) ;
127150
0 commit comments