@@ -40,6 +40,50 @@ describe("the resources property", function () {
4040 this . httpBackend . flush ( ) ;
4141 } ) ;
4242
43+ it ( "must call the correct href url with parameters if a resource object with parameters is passed to the $resource method" , function ( ) {
44+
45+ // define the resource object and the correct link href url
46+ var resourceObject = {
47+ 'name' : 'self' ,
48+ 'parameters' : {
49+ 'parameter1' : '1' ,
50+ 'parameter2' : '2'
51+ }
52+ } ;
53+ var resourceHref = "http://localhost:8080/categories?parameter1=1¶meter2=2" ;
54+
55+ // check if the underlying $resource method is called with the correct href url
56+ var expectedResult = { categoryId : '123' } ;
57+ this . httpBackend . whenGET ( resourceHref ) . respond ( 200 , expectedResult ) ;
58+ this . httpBackend . expectGET ( resourceHref ) ;
59+ var result = this . response [ this . config . resourcesKey ] ( resourceObject ) . get ( function ( ) {
60+ expect ( result . categoryId ) . toEqual ( expectedResult . categoryId ) ;
61+ } ) ;
62+ this . httpBackend . flush ( ) ;
63+ } ) ;
64+
65+ it ( "must call the correct href url without parameters if a resource object with empty parameters is passed to the $resource method" , function ( ) {
66+
67+ // define the resource object and the correct link href url
68+ var resourceObject = {
69+ 'name' : 'self' ,
70+ 'parameters' : {
71+ 'parameter1' : "" ,
72+ 'parameter2' : ""
73+ }
74+ } ;
75+ var resourceHref = "http://localhost:8080/categories" ;
76+
77+ // check if the underlying $resource method is called with the correct href url
78+ var expectedResult = { categoryId : '123' } ;
79+ this . httpBackend . whenGET ( resourceHref ) . respond ( 200 , expectedResult ) ;
80+ this . httpBackend . expectGET ( resourceHref ) ;
81+ var result = this . response [ this . config . resourcesKey ] ( resourceObject ) . get ( function ( ) {
82+ expect ( result . categoryId ) . toEqual ( expectedResult . categoryId ) ;
83+ } ) ;
84+ this . httpBackend . flush ( ) ;
85+ } ) ;
86+
4387 it ( "it must call the overridden resource function with the given resource name" , function ( ) {
4488 var url = undefined , paramDefaults = undefined , actions = undefined , options = undefined ;
4589 var resourcesFunctionConfiguration = {
@@ -184,9 +228,9 @@ describe("the resources property", function () {
184228 {
185229 name : 'self' ,
186230 parameters : {
187- page : undefined ,
188- size : undefined ,
189- sort : undefined
231+ page : "" ,
232+ size : "" ,
233+ sort : ""
190234 }
191235 } ,
192236 {
@@ -227,25 +271,25 @@ describe("the resources property", function () {
227271 {
228272 name : 'users' ,
229273 parameters : {
230- page : undefined ,
231- size : undefined ,
232- sort : undefined
274+ page : "" ,
275+ size : "" ,
276+ sort : ""
233277 }
234278 } ,
235279 {
236280 name : 'categories' ,
237281 parameters : {
238- page : undefined ,
239- size : undefined ,
240- sort : undefined
282+ page : "" ,
283+ size : "" ,
284+ sort : ""
241285 }
242286 } ,
243287 {
244288 name : 'accounts' ,
245289 parameters : {
246- page : undefined ,
247- size : undefined ,
248- sort : undefined
290+ page : "" ,
291+ size : "" ,
292+ sort : ""
249293 }
250294 }
251295 ]
0 commit comments