@@ -2,7 +2,7 @@ import { ImageSource } from '@nativescript/core';
22import * as TKUnit from '../tk-unit' ;
33import * as http from '@nativescript/core/http' ;
44import * as fs from '@nativescript/core/file-system' ;
5- import { addHeader } from '@nativescript/core/http/http-request' ;
5+ import { requestInternal , addHeader , BaseHttpContent } from '@nativescript/core/http/http-request-internal ' ;
66
77export var test_getString_isDefined = function ( ) {
88 TKUnit . assert ( typeof http . getString !== 'undefined' , 'Method http.getString() should be defined!' ) ;
@@ -329,6 +329,89 @@ export var test_request_requestShouldTimeout = function (done) {
329329 } ) ;
330330} ;
331331
332+ export var test_requestInternal_responseStatusCodeShouldBeDefined = function ( done ) {
333+ requestInternal ( { url : 'https://http-echo.nativescript.org/get' , method : 'GET' } ) . then (
334+ function ( response ) {
335+ //// Argument (response) is HttpResponse!
336+ var statusCode = response . statusCode ;
337+ try {
338+ TKUnit . assert ( typeof statusCode !== 'undefined' , 'response.statusCode should be defined!' ) ;
339+ done ( null ) ;
340+ } catch ( err ) {
341+ done ( err ) ;
342+ }
343+ } ,
344+ function ( e ) {
345+ //// Argument (e) is Error!
346+ done ( e ) ;
347+ } ,
348+ ) ;
349+ } ;
350+
351+ export var test_requestInternal_responseContentShouldExposeNativeContentFunctions = function ( done ) {
352+ requestInternal ( { url : 'https://http-echo.nativescript.org/get' , method : 'GET' } ) . then (
353+ function ( response ) {
354+ try {
355+ TKUnit . assert ( typeof response . content . toNativeImage === 'function' && typeof response . content . toNativeString === 'function' , `response.content should expose native content functions!` ) ;
356+ done ( null ) ;
357+ } catch ( err ) {
358+ done ( err ) ;
359+ }
360+ } ,
361+ function ( e ) {
362+ //// Argument (e) is Error!
363+ done ( e ) ;
364+ } ,
365+ ) ;
366+ } ;
367+
368+ export var test_requestInternal_responseContentShouldExposeHandlerFunctions = function ( done ) {
369+ const responseHandler = {
370+ toDummy1 : ( ) => 'dummy1' ,
371+ toDummy2 : ( ) => 'dummy2' ,
372+ } ;
373+
374+ requestInternal ( { url : 'https://http-echo.nativescript.org/get' , method : 'GET' } , responseHandler ) . then (
375+ function ( response ) {
376+ try {
377+ TKUnit . assert ( typeof response . content . toDummy1 === 'function' && typeof response . content . toDummy2 === 'function' , `response.content should expose content handler functions!` ) ;
378+ done ( null ) ;
379+ } catch ( err ) {
380+ done ( err ) ;
381+ }
382+ } ,
383+ function ( e ) {
384+ //// Argument (e) is Error!
385+ done ( e ) ;
386+ } ,
387+ ) ;
388+ } ;
389+
390+ export var test_requestInternal_responseHandlerShouldBeAvailable = function ( done ) {
391+ const suffix = '-nsformatted' ;
392+ const responseHandler = {
393+ toFormattedString : function ( this : BaseHttpContent ) {
394+ return this . toNativeString ( ) + suffix ;
395+ } ,
396+ } ;
397+
398+ requestInternal ( { url : 'https://http-echo.nativescript.org/get' , method : 'GET' } , responseHandler ) . then (
399+ function ( response ) {
400+ const value = response . content . toFormattedString ( ) ;
401+ try {
402+ TKUnit . assert ( typeof value === 'string' && value . endsWith ( suffix ) , `response.content.toFormattedString should return the response string appended with ${ suffix } at the end!` ) ;
403+ done ( null ) ;
404+ } catch ( err ) {
405+ done ( err ) ;
406+ }
407+ } ,
408+ function ( e ) {
409+ //// Argument (e) is Error!
410+ done ( e ) ;
411+ } ,
412+ ) ;
413+ } ;
414+
332415export var test_request_responseStatusCodeShouldBeDefined = function ( done ) {
333416 var result : http . HttpResponse ;
334417
0 commit comments