@@ -955,6 +955,79 @@ describe('Tandy', () => {
955955 expect ( result ) . to . be . an . array ( ) ;
956956 expect ( result . length ) . to . equal ( 4 ) ;
957957 } ) ;
958+ it ( 'Fetches all users and includes total count' , async ( ) => {
959+
960+ const server = await getServer ( getOptions ( {
961+ tandy : {
962+ includeTotalCount : true
963+ }
964+ } ) ) ;
965+ server . registerModel ( [
966+ TestModels . Users ,
967+ TestModels . Tokens
968+ ] ) ;
969+
970+ await server . initialize ( ) ;
971+ const knex = server . knex ( ) ;
972+ // const data = await knex.seed.run({ directory: 'test/seeds' });
973+ await knex . seed . run ( { directory : 'test/seeds' } ) ;
974+
975+ server . route ( {
976+ method : 'GET' ,
977+ path : '/users' ,
978+ handler : { tandy : { } }
979+ } ) ;
980+
981+ const options = {
982+ method : 'GET' ,
983+ url : '/users'
984+ } ;
985+
986+ const response = await server . inject ( options ) ;
987+ const result = response . result ;
988+
989+ expect ( response . statusCode ) . to . equal ( 200 ) ;
990+ expect ( result ) . to . be . an . array ( ) ;
991+ expect ( result . length ) . to . equal ( 4 ) ;
992+ expect ( response . headers [ 'content-range' ] ) . to . equal ( 'users 0-4/4' ) ;
993+ } ) ;
994+ it ( 'Fetches all users and includes total count, custom header name' , async ( ) => {
995+
996+ const server = await getServer ( getOptions ( {
997+ tandy : {
998+ includeTotalCount : true ,
999+ totalCountHeader : 'x-count'
1000+ }
1001+ } ) ) ;
1002+ server . registerModel ( [
1003+ TestModels . Users ,
1004+ TestModels . Tokens
1005+ ] ) ;
1006+
1007+ await server . initialize ( ) ;
1008+ const knex = server . knex ( ) ;
1009+ // const data = await knex.seed.run({ directory: 'test/seeds' });
1010+ await knex . seed . run ( { directory : 'test/seeds' } ) ;
1011+
1012+ server . route ( {
1013+ method : 'GET' ,
1014+ path : '/users' ,
1015+ handler : { tandy : { } }
1016+ } ) ;
1017+
1018+ const options = {
1019+ method : 'GET' ,
1020+ url : '/users'
1021+ } ;
1022+
1023+ const response = await server . inject ( options ) ;
1024+ const result = response . result ;
1025+
1026+ expect ( response . statusCode ) . to . equal ( 200 ) ;
1027+ expect ( result ) . to . be . an . array ( ) ;
1028+ expect ( result . length ) . to . equal ( 4 ) ;
1029+ expect ( response . headers [ 'x-count' ] ) . to . equal ( '4' ) ;
1030+ } ) ;
9581031 it ( 'Fetches all users without actAsUser' , async ( ) => {
9591032
9601033 const config = getOptions ( {
0 commit comments