Skip to content

Commit

Permalink
fix(ResultsMapSerializer): Add meta back to serializer output
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jan 4, 2019
1 parent b631189 commit d9594d0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
5 changes: 3 additions & 2 deletions models/serializers/ResultsMapSerializer.cfc
Expand Up @@ -90,8 +90,9 @@ component singleton {
*
* @response The metadata nested under a "meta" key.
*/
function meta( resource, scope ) {
return { "#variables.metaKey#" = resource.getMeta() };
function meta( resource, scope, data ) {
structAppend( data, { "#variables.metaKey#" = resource.getMeta() }, true );
return data;
}

}
51 changes: 51 additions & 0 deletions tests/specs/integration/FractalBuilderTest.cfc
Expand Up @@ -314,6 +314,57 @@ component extends="testbox.system.BaseSpec" {
}
} );
} );

it( "returns pagination data in a meta field for the results map serializer", function() {
var books = [
new tests.resources.Book( {
id = 1,
title = "To Kill a Mockingbird",
year = "1960"
} ),
new tests.resources.Book( {
id = 2,
title = "A Tale of Two Cities",
year = "1859"
} )
];

var result = fractal.builder()
.collection( books )
.withSerializer( new cffractal.models.serializers.ResultsMapSerializer() )
.withTransformer( new tests.resources.BookTransformer().setManager( fractal ) )
.withPagination( {
"maxrows": 50,
"page": 2,
"pages": 3,
"totalRecords": 112
} )
.convert();

expect( result ).toBe( {
"results": [ 1, 2 ],
"resultsMap": {
"1": {
"id": 1,
"title": "To Kill a Mockingbird",
"year": 1960
},
"2": {
"id": 2,
"title": "A Tale of Two Cities",
"year": 1859
}
},
"meta": {
"pagination": {
"maxrows": 50,
"page": 2,
"pages": 3,
"totalRecords": 112
}
}
} );
} );
} );

describe( "postTransformationCallbacks", function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/unit/serializers/ResultsMapSerializerTest.cfc
Expand Up @@ -34,7 +34,7 @@ component extends="testbox.system.BaseSpec" {
var mockItem = getMockBox().createMock( "cffractal.models.resources.Item" );
mockItem.$( "getMeta", pagingData, false );
var serializer = new cffractal.models.serializers.ResultsMapSerializer();
expect( serializer.meta( mockItem, mockScope ) )
expect( serializer.meta( mockItem, mockScope, {} ) )
.toBe( { "meta" = pagingData } );
} );
} );
Expand Down

0 comments on commit d9594d0

Please sign in to comment.