@@ -17,8 +17,8 @@ describe('request', function () {
17
17
} ) ;
18
18
19
19
it ( 'can request a web page' , function ( done ) {
20
- request ( 'https://httpbin.org ' )
21
- . get ( '/html ' )
20
+ request ( 'https://chaijs.com ' )
21
+ . get ( '/guide/ ' )
22
22
. end ( function ( err , res ) {
23
23
res . should . have . status ( 200 ) ;
24
24
res . should . be . html ;
@@ -35,8 +35,8 @@ describe('request', function () {
35
35
} ) ;
36
36
37
37
it ( 'can request JSON data' , function ( done ) {
38
- request ( 'https://httpbin.org ' )
39
- . get ( '/get ' )
38
+ request ( 'https://chaijs.com ' )
39
+ . get ( '/package-lock.json ' )
40
40
. end ( function ( err , res ) {
41
41
res . should . have . status ( 200 ) ;
42
42
res . should . be . json ;
@@ -49,47 +49,76 @@ describe('request', function () {
49
49
} ) ;
50
50
51
51
it ( 'can read response headers' , function ( done ) {
52
- request ( 'https://httpbin.org' )
53
- . get ( '/response-headers' )
54
- . query ( { 'content-type' : 'application/json' } )
55
- . query ( { 'pragma' : 'test1' } )
56
- . query ( { 'location' : 'test2' } )
57
- . query ( { 'x-api-key' : 'test3' } )
52
+ this . timeout ( 5000 )
53
+ request ( 'https://webhook.site' )
54
+ . post ( '/token' )
58
55
. end ( function ( err , res ) {
59
- res . should . have . status ( 200 ) ;
60
-
61
- // Content-Type and Pragma are supported on Node and browser
62
- res . should . be . json ;
63
- res . should . have . header ( 'Content-Type' , / j s o n $ / ) ;
64
- res . should . have . header ( 'Pragma' , 'test1' ) ;
56
+ const uuid = res . body . uuid ;
57
+ request ( 'https://webhook.site' )
58
+ . get ( '/' + uuid )
59
+ . query ( { 'content-type' : 'application/json' } )
60
+ . query ( { 'pragma' : 'test1' } )
61
+ . query ( { 'location' : 'test2' } )
62
+ . query ( { 'x-api-key' : 'test3' } )
63
+ . end ( function ( err , res ) {
64
+ res . should . have . status ( 200 ) ;
65
+ request ( 'https://webhook.site' )
66
+ . get ( '/token/' + uuid + '/requests?sorting=newest&per_page=1' )
67
+ . end ( function ( err , res ) {
68
+ // Content-Type and Pragma are supported on Node and browser
69
+ res . should . be . json ;
70
+ res . should . have . nested . property ( '.body.data.0.query.content-type' , 'application/json' )
71
+ res . should . have . nested . property ( '.body.data.0.query.pragma' , 'test1' )
65
72
66
- // When running in a browser, only "simple" headers are readable
67
- // https://www.w3.org/TR/cors/#simple-response-header
68
- isNode && res . should . have . header ( 'Location ', 'test2' ) ;
69
- isNode && res . should . have . header ( 'X-API-Key ', 'test3' ) ;
70
- isBrowser && res . should . not . have . header ( 'Location ') ;
71
- isBrowser && res . should . not . have . header ( 'X-API-Key ') ;
73
+ // When running in a browser, only "simple" headers are readable
74
+ // https://www.w3.org/TR/cors/#simple-response-header
75
+ isNode && res . should . have . nested . property ( '.body.data.0.query.location ', 'test2' )
76
+ isNode && res . should . have . nested . property ( '.body.data.0.query.x-api-key ', 'test3' )
77
+ isBrowser && res . should . not . have . nested . property ( '.body.data.0.query.location ') ;
78
+ isBrowser && res . should . not . have . nested . property ( '.body.data.0.query.x-api-key ') ;
72
79
73
- done ( err ) ;
80
+ done ( err ) ;
81
+ } ) ;
82
+ } ) ;
74
83
} ) ;
75
84
} ) ;
76
85
77
86
it ( 'succeeds when response has an error status' , function ( done ) {
78
- request ( 'https://httpbin.org ' )
79
- . get ( '/status/400 ' )
87
+ request ( 'https://chaijs.com ' )
88
+ . get ( '/404 ' )
80
89
. end ( function ( err , res ) {
81
- res . should . have . status ( 400 ) ;
90
+ res . should . have . status ( 404 ) ;
82
91
done ( err ) ;
83
92
} ) ;
84
93
} ) ;
85
94
86
95
it ( 'can be augmented with promises' , function ( done ) {
87
- request ( 'https://httpbin.org' )
88
- . get ( '/get' )
89
- . set ( 'X-API-Key' , 'test3' )
96
+ this . timeout ( 5000 )
97
+ let uuid = ''
98
+ request ( 'https://webhook.site' )
99
+ . post ( '/token' )
100
+ . then ( function ( res ) {
101
+ uuid = res . body . uuid ;
102
+ return res . body . uuid ;
103
+ } )
104
+ . then ( function ( uuid ) {
105
+ return request ( 'https://webhook.site' )
106
+ . get ( '/' + uuid )
107
+ . query ( { 'content-type' : 'application/json' } )
108
+ . query ( { 'x-api-key' : 'test3' } )
109
+ } )
90
110
. then ( function ( res ) {
91
111
res . should . have . status ( 200 ) ;
92
- res . body . headers [ 'X-Api-Key' ] . should . equal ( 'test3' ) ;
112
+ return request ( 'https://webhook.site' )
113
+ . get ( '/token/' + uuid + '/requests?sorting=newest&per_page=1' )
114
+ } )
115
+ . then ( function ( res ) {
116
+ res . should . have . status ( 200 ) ;
117
+ res . should . be . json ;
118
+ res . should . have . nested . property ( '.body.data.0.query.content-type' , 'application/json' )
119
+ res . should . have . nested . property ( '.body.data.0.query.x-api-key' , 'test3' )
120
+ } )
121
+ . then ( function ( ) {
93
122
throw new Error ( 'Testing catch' ) ;
94
123
} )
95
124
. then ( function ( ) {
@@ -103,11 +132,11 @@ describe('request', function () {
103
132
. then ( done , done ) ;
104
133
} ) ;
105
134
106
- it ( 'can resolve a promise given status code of 400 ' , function ( ) {
107
- return request ( 'https://httpbin.org ' )
108
- . get ( '/status/400 ' )
135
+ it ( 'can resolve a promise given status code of 404 ' , function ( ) {
136
+ return request ( 'https://chaijs.com ' )
137
+ . get ( '/404 ' )
109
138
. then ( function ( res ) {
110
- res . should . have . status ( 400 ) ;
139
+ res . should . have . status ( 404 ) ;
111
140
} ) ;
112
141
} ) ;
113
142
} ) ;
0 commit comments