@@ -9,13 +9,16 @@ import { cloneDeep } from 'lodash'
99import embeddedSingleEntity from './resources/embedded-single-entity'
1010import referenceToSingleEntity from './resources/reference-to-single-entity'
1111import embeddedCollection from './resources/embedded-collection'
12+ import embeddedLinkedCollection from './resources/embedded-linked-collection'
1213import linkedSingleEntity from './resources/linked-single-entity'
1314import linkedCollection from './resources/linked-collection'
1415import collectionFirstPage from './resources/collection-firstPage'
1516import collectionPage1 from './resources/collection-page1'
1617import circularReference from './resources/circular-reference'
1718import multipleReferencesToUser from './resources/multiple-references-to-user'
1819import templatedLink from './resources/templated-link'
20+ import objectProperty from './resources/object-property'
21+ import arrayProperty from './resources/array-property'
1922import root from './resources/root'
2023
2124import LoadingStoreValue from '../src/LoadingStoreValue'
@@ -143,6 +146,26 @@ describe('API store', () => {
143146 expect ( vm . api . get ( '/periods/128' ) . camp ( ) . _meta . self ) . toEqual ( 'http://localhost/camps/1' )
144147 } )
145148
149+ it ( 'imports embedded collection with link' , async ( ) => {
150+ // given
151+ axiosMock . onGet ( 'http://localhost/camps/1' ) . reply ( 200 , embeddedLinkedCollection . serverResponse )
152+
153+ // when
154+ vm . api . get ( '/camps/1' )
155+
156+ // then
157+ expect ( vm . $store . state . api ) . toMatchObject ( { '/camps/1' : { _meta : { self : '/camps/1' , loading : true } } } )
158+ await letNetworkRequestFinish ( )
159+ expect ( vm . $store . state . api ) . toMatchObject ( embeddedLinkedCollection . storeState )
160+ expect ( vm . api . get ( '/camps/1' ) . _meta . self ) . toEqual ( 'http://localhost/camps/1' )
161+ expect ( vm . api . get ( '/camps/1' ) . periods ( ) . items [ 0 ] . _meta . self ) . toEqual ( 'http://localhost/periods/104' )
162+ expect ( vm . api . get ( '/camps/1' ) . periods ( ) . items [ 1 ] . _meta . self ) . toEqual ( 'http://localhost/periods/128' )
163+ expect ( vm . api . get ( '/periods/104' ) . _meta . self ) . toEqual ( 'http://localhost/periods/104' )
164+ expect ( vm . api . get ( '/periods/104' ) . camp ( ) . _meta . self ) . toEqual ( 'http://localhost/camps/1' )
165+ expect ( vm . api . get ( '/periods/128' ) . _meta . self ) . toEqual ( 'http://localhost/periods/128' )
166+ expect ( vm . api . get ( '/periods/128' ) . camp ( ) . _meta . self ) . toEqual ( 'http://localhost/camps/1' )
167+ } )
168+
146169 it ( 'imports linked single entity' , async ( ) => {
147170 // given
148171 axiosMock . onGet ( 'http://localhost/camps/1' ) . reply ( 200 , linkedSingleEntity . serverResponse )
@@ -1404,6 +1427,46 @@ describe('API store', () => {
14041427 // then
14051428 await expect ( load ) . rejects . toThrow ( 'Error trying to patch \"/camps/1\" (status 422): Request failed with status code 422' )
14061429 } )
1430+
1431+ it ( 'can handle object property' , async done => {
1432+ // given
1433+ axiosMock . onGet ( 'http://localhost/camps/1' ) . reply ( 200 , objectProperty . serverResponse )
1434+
1435+ // when
1436+ vm . api . get ( '/camps/1' )
1437+ await letNetworkRequestFinish ( )
1438+
1439+ // then
1440+ expect ( vm . $store . state . api ) . toMatchObject ( objectProperty . storeState )
1441+
1442+ expect ( vm . api . get ( '/camps/1' ) . objectProperty ) . toBeInstanceOf ( Object )
1443+ expect ( vm . api . get ( '/camps/1' ) . objectProperty . a ) . toEqual ( 1 )
1444+ expect ( vm . api . get ( '/camps/1' ) . objectProperty . nested . b ) . toEqual ( 2 )
1445+
1446+ expect ( vm . api . get ( '/camps/1' ) . emptyObject ) . toBeInstanceOf ( Object )
1447+ expect ( vm . api . get ( '/camps/1' ) . emptyObject ) . toEqual ( { } )
1448+ done ( )
1449+ } )
1450+
1451+ it ( 'can handle array property' , async done => {
1452+ // given
1453+ axiosMock . onGet ( 'http://localhost/camps/1' ) . reply ( 200 , arrayProperty . serverResponse )
1454+
1455+ // when
1456+ vm . api . get ( '/camps/1' )
1457+ await letNetworkRequestFinish ( )
1458+
1459+ // then
1460+ expect ( vm . $store . state . api ) . toMatchObject ( arrayProperty . storeState )
1461+
1462+ expect ( vm . api . get ( '/camps/1' ) . arrayProperty ) . toBeInstanceOf ( Array )
1463+ expect ( vm . api . get ( '/camps/1' ) . arrayProperty [ 0 ] . a ) . toEqual ( 1 )
1464+ expect ( vm . api . get ( '/camps/1' ) . arrayProperty [ 0 ] . nested [ 0 ] . b ) . toEqual ( 2 )
1465+
1466+ expect ( vm . api . get ( '/camps/1' ) . emptyArray ) . toBeInstanceOf ( Array )
1467+ expect ( vm . api . get ( '/camps/1' ) . emptyArray ) . toEqual ( [ ] )
1468+ done ( )
1469+ } )
14071470 } )
14081471 } )
14091472} )
0 commit comments