Skip to content

Commit

Permalink
add tests for Doc instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Mar 5, 2016
1 parent f9fe4ca commit ab5492e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -17,6 +17,6 @@ install:
- box server start
before_script:
# Startup the app
- curl http://localhost:49616/
- curl http://localhost:50680/
script:
- ant -f workbench/build.xml
5 changes: 2 additions & 3 deletions modules/relax/models/OpenAPI/Document.cfc
Expand Up @@ -35,8 +35,7 @@ component name="OpenAPIDocument" accessors="true" {

}

private void function setResourceIds(){
var resourceDoc = getDocument();
private void function setResourceIds(required struct resourceDoc=getDocument(), string hashPrefix="" ){
var appendableNodes = [ "paths","responses" ];

for ( var resourceKey in appendableNodes ){
Expand All @@ -48,7 +47,7 @@ component name="OpenAPIDocument" accessors="true" {
} );
//recurse, if necessary
for( var subKey in resourceDoc[ resourceKey ][ pathKey ] ){
if( arrayFind( appendableNodes, subKey ) ) setResourceIds( resourceDoc[ resourceKey ][ pathKey ] );
if( arrayFind( appendableNodes, subKey ) ) setResourceIds( resourceDoc[ resourceKey ][ pathKey ], pathKey );
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion tests/specs/unit/OpenAPI/DocumentSpec.cfc
Expand Up @@ -7,6 +7,7 @@ component extends="BaseOpenAPISpec"{

function beforeAll(){
super.beforeAll();
VARIABLES.testDocument = deserializeJSON(fileRead( VARIABLES.TestJSONFile ));

};

Expand All @@ -17,7 +18,30 @@ component extends="BaseOpenAPISpec"{
/*********************************** BDD SUITES ***********************************/

function run(){
// all your suites go here.

describe( "Performs tests on document instantiation", function(){
it( "Tests the ability to instantiate an OpenAPI Document Object", function( ){
var DocumentObject = Wirebox.getInstance( "OpenAPIDocument@relax" ).init( VARIABLES.testDocument );
expect( DocumentObject ).toBeComponent();
expect( DocumentObject ).toBeInstanceOf( "modules.relax.models.OpenAPI.Document" );
expect( DocumentObject ).toHaveKey( "getDocument" );

//test that path items have resource IDs
var instanceDoc = DocumentObject.getDocument();

for( var pathKey in instanceDoc[ "paths" ] ){

expect( instanceDoc[ "paths" ][ pathKey ] ).toHaveKey( "x-resourceId" );

if( structKeyExists( instanceDoc[ "paths" ][ pathKey ], "methods" ) ){
for( var methodKey in instanceDoc[ "paths" ][ pathKey ][ "methods" ] ){
expect( instanceDoc[ "paths" ][ pathKey ][ "methods" ][ methodKey ] ).toHaveKey( "x-resourceId" );
}
}
}

} );
} );
}

}

0 comments on commit ab5492e

Please sign in to comment.