Skip to content

Commit

Permalink
fix(BoxLang): Certify for BoxLang
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 27, 2024
1 parent ecc1e23 commit 0548150
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion models/HyperBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ component singleton {
invoke(
this.defaults,
"set#key#",
{ 1 : arguments[ key ] }
[ arguments[ key ] ]
);
}
return this;
Expand Down
16 changes: 14 additions & 2 deletions models/HyperRequest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,18 @@ component accessors="true" {
return this;
}

/**
* Sets the headers for the request.
*
* @headers The headers for the request.
*
* @returns The HyperRequest instance.
*/
function setHeaders( required struct headers ) {
variables.headers = createObject( "java", "java.util.LinkedHashMap" ).init();
return withHeaders( arguments.headers );
}

/**
* Set a header for the request.
*
Expand All @@ -667,7 +679,7 @@ component accessors="true" {
* @returns The HyperRequest instance.
*/
function setHeader( name, value ) {
variables.headers[ name ] = value;
variables.headers.put( arguments.name, arguments.value );
return this;
}

Expand Down Expand Up @@ -865,7 +877,7 @@ component accessors="true" {
*/
function setProperties( properties = {} ) {
properties.each( function( key, value ) {
invoke( this, "set#key#", { 1 : value } );
invoke( this, "set#key#", [ value ] );
} );
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/app/handlers/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ component {
statusCode = 201,
data = {
"id" : 777,
"smallPhoto" : smallPhoto.serverFile,
"largePhoto" : largePhoto.serverFile,
"smallPhoto" : smallPhoto.serverFileName ?: smallPhoto.serverFile,
"largePhoto" : largePhoto.serverFileName ?: largePhoto.serverFile,
"description" : rc.description
}
);
Expand Down
10 changes: 4 additions & 6 deletions tests/specs/integration/FileUploadsSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
{ "description" : "Chuck Norris doesn't need two different photos." }
);
expect( res.getStatusCode() ).toBe( 201, res.getData() );
expect( res.json() ).toBe( {
"id" : 777, // this is always the id returned
"smallPhoto" : "chuck_norris.jpg",
"largePhoto" : "chuck_norris.jpg",
"description" : "Chuck Norris doesn't need two different photos."
} );
var json = res.json();
expect( json.smallPhoto ).toBe( "chuck_norris.jpg" );
expect( json.largePhoto ).toBe( "chuck_norris.jpg" );
expect( json.description ).toBe( "Chuck Norris doesn't need two different photos." );
} );
} );
}
Expand Down
3 changes: 2 additions & 1 deletion tests/specs/unit/HyperRequestSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ component extends="testbox.system.BaseSpec" {
it( "preserves case in header names", function() {
expect( req.getHeader( "Accept" ) ).toBe( "" );
req.withHeaders( { "accept" : "application/xml" } );
req.setHeader( "accept", "application/xml" );
expect( req.getHeader( "Accept" ) ).toBe( "" );
expect( req.getHeader( "accept" ) ).toBe( "application/xml" );
req.withHeaders( { "Accept" : "application/xml" } );
Expand Down Expand Up @@ -237,7 +238,7 @@ component extends="testbox.system.BaseSpec" {
it( "can handle a JSON body format with a body as an struct", function() {
req.setBodyFormat( "json" );
req.setBody( { "query" : {}, "size" : 0, "from" : 0 } );
expect( req.prepareBody() ).toBe( '{"query":{},"size":0,"from":0}' );
expect( deserializeJSON( req.prepareBody() ) ).toBe( { "query" : {}, "size" : 0, "from" : 0 } );
} );

it( "defaults to no Content-Type", function() {
Expand Down

0 comments on commit 0548150

Please sign in to comment.