@@ -107,5 +107,51 @@ describe("the spring data rest adapter", function () {
107107 this . rootScope . $apply ( ) ;
108108 } ) ;
109109
110+ it ( "must only fetch link once to avoid infinite loop" , function ( ) {
111+ var allLinks = this . config . fetchAllKey ;
112+ var accidentHref = 'http://localhost:8080/api/reports/00001/accident' ;
113+ var reportHref = 'http://localhost:8080/api/accidents/00001/report' ;
114+
115+ this . httpBackend . whenGET ( accidentHref ) . respond ( 200 , mockDataAccident ( ) ) ;
116+ this . httpBackend . expectGET ( accidentHref ) ;
117+
118+ this . httpBackend . whenGET ( reportHref ) . respond ( 200 , mockDataReport ( ) ) ;
119+ this . httpBackend . expectGET ( reportHref ) ;
120+
121+ this . rawResponse = mockDataReport ( ) ;
122+ SpringDataRestAdapter . process ( this . rawResponse , allLinks , true ) . then ( function ( processedData ) {
123+ // expect that accident will not fetched twice
124+ expect ( processedData . accident ) . toBeDefined ( ) ;
125+ expect ( processedData . accident . report ) . toBeDefined ( ) ;
126+ expect ( processedData . accident . report . accident ) . not . toBeDefined ( ) ;
127+ } ) ;
128+
129+ this . httpBackend . flush ( ) ;
130+ this . rootScope . $apply ( ) ;
131+ } ) ;
132+
133+ it ( "must only reinitialized the map when process called twice or more" , function ( ) {
134+ var allLinks = this . config . fetchAllKey ;
135+ var accidentHref = 'http://localhost:8080/api/reports/00001/accident' ;
136+ var reportHref = 'http://localhost:8080/api/accidents/00001/report' ;
137+
138+ this . httpBackend . whenGET ( accidentHref ) . respond ( 200 , mockDataAccident ( ) ) ;
139+ this . httpBackend . expectGET ( accidentHref ) ;
140+
141+ this . httpBackend . whenGET ( reportHref ) . respond ( 200 , mockDataReport ( ) ) ;
142+ this . httpBackend . expectGET ( reportHref ) ;
143+
144+ this . rawResponse = mockDataReport ( ) ;
145+ SpringDataRestAdapter . process ( this . rawResponse , allLinks , true ) . then ( function ( processedData ) {
146+ SpringDataRestAdapter . process ( mockDataReport ( ) , allLinks , true ) . then ( function ( processedData2 ) {
147+ // expect linkMap to be reinitialized after process method called twice
148+ expect ( JSON . stringify ( processedData ) ) . toEqual ( JSON . stringify ( processedData2 ) ) ;
149+ } ) ;
150+ } ) ;
151+
152+ this . httpBackend . flush ( ) ;
153+ this . rootScope . $apply ( ) ;
154+ } ) ;
155+
110156} ) ;
111157
0 commit comments