@@ -3,7 +3,7 @@ import { HookContext } from '@feathersjs/feathers';
33import { http } from '../src' ;
44
55describe ( '@feathersjs/transport-commons HTTP helpers' , ( ) => {
6- it ( 'getData ' , ( ) => {
6+ it ( 'getResponse body ' , ( ) => {
77 const plainData = { message : 'hi' } ;
88 const dispatch = { message : 'from dispatch' } ;
99 const resultContext = {
@@ -13,22 +13,41 @@ describe('@feathersjs/transport-commons HTTP helpers', () => {
1313 dispatch
1414 } ;
1515
16- assert . strictEqual ( http . getData ( resultContext as HookContext ) , plainData ) ;
17- assert . strictEqual ( http . getData ( dispatchContext as HookContext ) , dispatch ) ;
16+ assert . strictEqual ( http . getResponse ( resultContext as HookContext ) . body , plainData ) ;
17+ assert . strictEqual ( http . getResponse ( dispatchContext as HookContext ) . body , dispatch ) ;
1818 } ) ;
1919
20- it ( 'getStatusCode ' , ( ) => {
20+ it ( 'getResponse status ' , ( ) => {
2121 const statusContext = {
22- http : { statusCode : 202 }
22+ http : { status : 202 }
2323 } ;
2424 const createContext = {
2525 method : 'create'
2626 } ;
27+ const redirectContext = {
28+ http : { location : '/' }
29+ } ;
30+
31+ assert . strictEqual ( http . getResponse ( statusContext as HookContext ) . status , 202 ) ;
32+ assert . strictEqual ( http . getResponse ( createContext as HookContext ) . status , http . statusCodes . created ) ;
33+ assert . strictEqual ( http . getResponse ( redirectContext as HookContext ) . status , http . statusCodes . seeOther ) ;
34+ assert . strictEqual ( http . getResponse ( { } as HookContext ) . status , http . statusCodes . noContent ) ;
35+ assert . strictEqual ( http . getResponse ( { result : true } as HookContext ) . status , http . statusCodes . success ) ;
36+ } ) ;
37+
38+ it ( 'getResponse headers' , ( ) => {
39+ const headers = { key : 'value' } as any ;
40+ const headersContext = {
41+ http : { headers }
42+ } ;
43+ const locationContext = {
44+ http : { location : '/' }
45+ } ;
2746
28- assert . strictEqual ( http . getStatusCode ( statusContext as HookContext , { } ) , 202 ) ;
29- assert . strictEqual ( http . getStatusCode ( createContext as HookContext , { } ) , http . statusCodes . created ) ;
30- assert . strictEqual ( http . getStatusCode ( { } as HookContext ) , http . statusCodes . noContent ) ;
31- assert . strictEqual ( http . getStatusCode ( { } as HookContext , { } ) , http . statusCodes . success ) ;
47+ assert . deepStrictEqual ( http . getResponse ( { } as HookContext ) . headers , { } ) ;
48+ assert . deepStrictEqual ( http . getResponse ( { http : { } } as HookContext ) . headers , { } ) ;
49+ assert . strictEqual ( http . getResponse ( headersContext as HookContext ) . headers , headers ) ;
50+ assert . deepStrictEqual ( http . getResponse ( locationContext as HookContext ) . headers , { Location : '/' } ) ;
3251 } ) ;
3352
3453 it ( 'getServiceMethod' , ( ) => {
@@ -39,15 +58,4 @@ describe('@feathersjs/transport-commons HTTP helpers', () => {
3958 assert . strictEqual ( http . getServiceMethod ( 'delete' , null ) , 'remove' ) ;
4059 assert . throws ( ( ) => http . getServiceMethod ( 'nonsense' , null ) ) ;
4160 } ) ;
42-
43- it ( 'getResponseHeaders' , ( ) => {
44- const responseHeaders = { key : 'value' } ;
45- const headersContext = {
46- http : { responseHeaders }
47- } ;
48-
49- assert . deepStrictEqual ( http . getResponseHeaders ( { } as HookContext ) , { } ) ;
50- assert . deepStrictEqual ( http . getResponseHeaders ( { http : { } } as HookContext ) , { } ) ;
51- assert . strictEqual ( http . getResponseHeaders ( headersContext as any as HookContext ) , responseHeaders ) ;
52- } ) ;
5361} ) ;
0 commit comments