@@ -26,70 +26,83 @@ describe('internal tests', function() {
2626 done ( ) ;
2727 } ) ) ;
2828
29- it ( 'test internal object exists' , function ( done ) {
30-
29+ it ( 'test internal sendRequest GET' , function ( done ) {
3130 try {
32- should . exist ( dbWriter . internal ) ;
33- done ( ) ;
31+ dbWriter . internal . sendRequest (
32+ "/v1/internal/forestinfo" ,
33+ requestOptions => {
34+ requestOptions . method = "GET" ;
35+ requestOptions . headers = { "Accept" : "application/json" }
36+ }
37+ )
38+ . result ( function ( response ) {
39+ for ( let i = 0 ; i < response . length ; i ++ ) {
40+ should . exist ( response [ i ] . host ) ;
41+ should . exist ( response [ i ] . name ) ;
42+ should . exist ( response [ i ] . id ) ;
43+ }
44+ } ) . then ( ( ) => done ( ) )
45+ . catch ( error => done ( error ) ) ;
3446 } catch ( error ) {
3547 done ( error ) ;
3648 }
3749 } ) ;
3850
39- it ( 'test newRequestOptions creation' , function ( done ) {
40- const requestOptions = dbWriter . internal . newRequestOptions ( '/v1/ping' ) ;
41- requestOptions . method = 'POST' ;
42- requestOptions . headers = {
43- 'Accept' : 'application/json' ,
44- 'Content-Type' : 'application/json'
45- } ;
51+ it ( 'test internal sendRequest POST' , function ( done ) {
4652 try {
47- should . deepEqual ( requestOptions . path , '/v1/ping' ) ;
48- should . deepEqual ( requestOptions . headers . Accept , 'application/json' ) ;
49- should . deepEqual ( requestOptions . headers [ 'Content-Type' ] , 'application/json' ) ;
50- done ( ) ;
53+ dbWriter . internal . sendRequest (
54+ "/v1/search" ,
55+ requestOptions => {
56+ requestOptions . method = "POST" ;
57+ requestOptions . headers = { "Accept" : "application/json" , "Content-type" : "application/json" } ;
58+ } ,
59+ null
60+ )
61+ . result ( function ( response ) {
62+ should . exist ( response . total ) ;
63+ should . exist ( response . start ) ;
64+ should . exist ( response [ 'page-length' ] ) ;
65+ for ( let i = 0 ; i < response . length ; i ++ ) {
66+ should . exist ( response . results [ i ] ) ;
67+ }
68+ } )
69+ . then ( ( ) => done ( ) )
70+ . catch ( error => done ( error ) ) ;
5171 } catch ( error ) {
5272 done ( error ) ;
5373 }
5474 } ) ;
5575
56- it ( 'test internal sendRequest' , function ( done ) {
57- const requestOptions = dbWriter . internal . newRequestOptions ( '/v1/internal/forestinfo' ) ;
58- requestOptions . method = 'GET' ;
59- requestOptions . headers = {
60- 'Accept' : 'application/json'
61- } ;
76+ it ( 'test internal sendRequest without path' , function ( done ) {
6277 try {
63- should . deepEqual ( requestOptions . path , '/v1/internal/forestinfo' ) ;
64- should . deepEqual ( requestOptions . method , 'GET' ) ;
65- should . deepEqual ( requestOptions . headers . Accept , 'application/json' ) ;
66- dbWriter . internal . sendRequest ( requestOptions , 'read forestInfo' , 'single' , 'empty' )
67- . result ( function ( response ) {
68- for ( let i = 0 ; i < response . length ; i ++ ) {
69- should . exist ( response [ i ] . host ) ;
70- should . exist ( response [ i ] . name ) ;
71- should . exist ( response [ i ] . id ) ;
72- }
73- } ) . then ( ( ) => done ( ) )
74- . catch ( e => done ( e ) ) ;
78+ dbWriter . internal . sendRequest (
79+ null ,
80+ requestOptions => {
81+ requestOptions . method = "GET" ;
82+ requestOptions . headers = { "Accept" : "application/json" }
83+ }
84+ )
7585 } catch ( error ) {
76- done ( error ) ;
86+ should . equal ( error . message , 'Path is needed to send request.' ) ;
87+ done ( ) ;
7788 }
7889 } ) ;
7990
80- it ( 'test newRequestOptions creation with optional database and basePath' , function ( done ) {
81- testconfig . restWriterConnection . basePath = '/test-basePath' ;
82- testconfig . restWriterConnection . database = 'test-database' ;
83- dbWriter = marklogic . createDatabaseClient ( testconfig . restWriterConnection ) ;
84- const requestOptions = dbWriter . internal . newRequestOptions ( '/v1/ping' ) ;
85- requestOptions . method = 'POST' ;
86- requestOptions . headers = {
87- 'Accept' : 'application/json' ,
88- 'Content-Type' : 'application/json'
89- } ;
91+ it ( 'test internal sendRequest without optional callbacks' , function ( done ) {
9092 try {
91- should . deepEqual ( requestOptions . path , '/test-basePath/v1/ping?database=test-database' ) ;
92- done ( ) ;
93+ dbWriter . internal . sendRequest (
94+ "/v1/search"
95+ )
96+ . result ( function ( response ) {
97+ should . exist ( response . total ) ;
98+ should . exist ( response . start ) ;
99+ should . exist ( response [ 'page-length' ] ) ;
100+ for ( let i = 0 ; i < response . length ; i ++ ) {
101+ should . exist ( response . results [ i ] ) ;
102+ }
103+ } )
104+ . then ( ( ) => done ( ) )
105+ . catch ( error => done ( error ) ) ;
93106 } catch ( error ) {
94107 done ( error ) ;
95108 }
0 commit comments