@@ -633,6 +633,93 @@ describe('API store', () => {
633633 done ( )
634634 } )
635635
636+ it ( 'loads the contents of an embedded collection depending on the avoidNPlusOneQueries flag' , async done => {
637+ // given
638+ const userResponse = {
639+ id : 1 ,
640+ _embedded : {
641+ lastReadBook : {
642+ id : 555 ,
643+ _embedded : {
644+ chapters : [
645+ { _links : { self : { href : '/chapters/1028' } } } ,
646+ { _links : { self : { href : '/chapters/1031' } } } ,
647+ { _links : { self : { href : '/chapters/1038' } } }
648+ ]
649+ } ,
650+ _links : {
651+ self : {
652+ href : '/books/555'
653+ }
654+ }
655+ }
656+ } ,
657+ _links : {
658+ self : {
659+ href : '/users/1'
660+ }
661+ }
662+ }
663+ const chapter1Response = {
664+ id : 1028 ,
665+ name : 'The first chapter' ,
666+ _links : {
667+ self : {
668+ href : '/chapters/1028'
669+ }
670+ }
671+ }
672+ const chapter2Response = {
673+ id : 1028 ,
674+ name : 'The second chapter' ,
675+ _links : {
676+ self : {
677+ href : '/chapters/1031'
678+ }
679+ }
680+ }
681+ const chapter3Response = {
682+ id : 1028 ,
683+ name : 'The final chapter' ,
684+ _links : {
685+ self : {
686+ href : '/chapters/1038'
687+ }
688+ }
689+ }
690+ const bookResponse = {
691+ id : 555 ,
692+ _embedded : {
693+ chapters : [ chapter1Response , chapter2Response , chapter3Response ]
694+ } ,
695+ _links : {
696+ self : {
697+ href : '/books/555'
698+ }
699+ }
700+ }
701+ axiosMock . onGet ( 'http://localhost/users/1' ) . replyOnce ( 200 , userResponse )
702+
703+ const lastReadBookChapters = vm . api . get ( '/users/1' ) . lastReadBook ( ) . chapters ( )
704+ await letNetworkRequestFinish ( )
705+
706+ if ( avoidNPlusOneRequests ) {
707+ axiosMock . onGet ( 'http://localhost/books/555' ) . replyOnce ( 200 , bookResponse )
708+ } else {
709+ axiosMock . onGet ( 'http://localhost/chapters/1028' ) . replyOnce ( 200 , chapter1Response )
710+ axiosMock . onGet ( 'http://localhost/chapters/1031' ) . replyOnce ( 200 , chapter2Response )
711+ axiosMock . onGet ( 'http://localhost/chapters/1038' ) . replyOnce ( 200 , chapter3Response )
712+ }
713+
714+ // when
715+ const result = lastReadBookChapters . items
716+
717+ // then
718+ await letNetworkRequestFinish ( )
719+ // expect no errors
720+ done ( )
721+ } )
722+
636723 it ( 'deletes an URI from the store and reloads all entities referencing it' , async done => {
637724 // given
638725 axiosMock . onGet ( 'http://localhost/groups/99' ) . replyOnce ( 200 , multipleReferencesToUser )
0 commit comments