11import {
2+ fileResourceWithNoDistribution ,
23 resourceWithDistributionArray ,
34 resourceWithDistributionObject ,
45 resourceWithoutDistrition ,
@@ -11,9 +12,16 @@ describe('ToLocalStorageResources', () => {
1112 resourceWithoutDistrition ,
1213 'studios'
1314 ) ;
15+ const expectedParentDistributionValue = {
16+ hasDistribution : false ,
17+ contentSize : 0 ,
18+ encodingFormat : 'json' ,
19+ label : 'metadata.json' ,
20+ } ;
1421
1522 expect ( actualLSResources . length ) . toEqual ( 1 ) ;
16- expect ( actualLSResources [ 0 ] . distribution ) . not . toBeDefined ( ) ;
23+
24+ expect ( actualLSResources [ 0 ] . localStorageType ) . toEqual ( 'resource' ) ;
1725 expect ( actualLSResources [ 0 ] . _self ) . toEqual ( resourceWithoutDistrition . _self ) ;
1826 expect ( actualLSResources [ 0 ] . key ) . toEqual ( resourceWithoutDistrition . _self ) ;
1927 expect ( actualLSResources [ 0 ] . project ) . toEqual (
@@ -23,6 +31,27 @@ describe('ToLocalStorageResources', () => {
2331 resourceWithoutDistrition [ '@type' ] ,
2432 ] ) ;
2533 expect ( actualLSResources [ 0 ] . source ) . toEqual ( 'studios' ) ;
34+ expect ( actualLSResources [ 0 ] . distribution ) . toEqual (
35+ expectedParentDistributionValue
36+ ) ;
37+ } ) ;
38+
39+ it ( 'serializes resource of type file with no distribution correctly' , ( ) => {
40+ const actualLSResources = toLocalStorageResources (
41+ fileResourceWithNoDistribution ,
42+ 'my-data'
43+ ) ;
44+ expect ( actualLSResources . length ) . toEqual ( 1 ) ;
45+ const expectedParentDistributionValue = {
46+ hasDistribution : false ,
47+ contentSize : fileResourceWithNoDistribution . _bytes ,
48+ encodingFormat : fileResourceWithNoDistribution . _mediaType ,
49+ label : fileResourceWithNoDistribution . _filename ,
50+ } ;
51+ expect ( actualLSResources [ 0 ] . distribution ) . toEqual (
52+ expectedParentDistributionValue
53+ ) ;
54+ expect ( actualLSResources [ 0 ] . source ) . toEqual ( 'my-data' ) ;
2655 } ) ;
2756
2857 it ( 'serializes resources with distribution array correctly to local storage object' , ( ) => {
@@ -34,8 +63,8 @@ describe('ToLocalStorageResources', () => {
3463 const expectedParentDistributionValue = {
3564 hasDistribution : true ,
3665 contentSize : 0 ,
37- encodingFormat : '' ,
38- label : '' ,
66+ encodingFormat : 'json ' ,
67+ label : 'metadata.json ' ,
3968 } ;
4069
4170 expect ( actualParentDistributionValue ) . toEqual (
@@ -59,6 +88,7 @@ describe('ToLocalStorageResources', () => {
5988 encodingFormat : originalDistItems [ index ] . encodingFormat ,
6089 label : originalDistItems [ index ] . name ,
6190 } ;
91+ expect ( actualDistItem . localStorageType ) . toEqual ( 'distribution' ) ;
6292 expect ( actualDistItem . distribution ) . toEqual ( expectedDistributionValue ) ;
6393 expect ( actualDistItem . _self ) . toEqual ( resource . _self ) ;
6494 expect ( actualDistItem . key ) . toEqual ( `${ resource . _self } -${ index } ` ) ;
@@ -69,19 +99,32 @@ describe('ToLocalStorageResources', () => {
6999 const resource = resourceWithDistributionObject ;
70100 const actualSerializedItems = toLocalStorageResources ( resource , 'studios' ) ;
71101
72- expect ( actualSerializedItems . length ) . toEqual ( 1 ) ;
73- const expectedDistributionValue = {
102+ expect ( actualSerializedItems . length ) . toEqual ( 2 ) ;
103+
104+ const expectedDistributionValueForParent = {
105+ hasDistribution : true ,
106+ contentSize : 0 ,
107+ encodingFormat : 'json' ,
108+ label : 'metadata.json' ,
109+ } ;
110+ expect ( actualSerializedItems [ 0 ] . distribution ) . toEqual (
111+ expectedDistributionValueForParent
112+ ) ;
113+ expect ( actualSerializedItems [ 0 ] . localStorageType ) . toEqual ( 'resource' ) ;
114+
115+ const expectedDistributionValueForChild = {
74116 hasDistribution : true ,
75117 contentSize : 15135 ,
76118 encodingFormat : 'text/turtle' ,
77119 label : 'molecular-systems.ttl' ,
78120 } ;
79- expect ( actualSerializedItems [ 0 ] . distribution ) . toEqual (
80- expectedDistributionValue
121+ expect ( actualSerializedItems [ 1 ] . distribution ) . toEqual (
122+ expectedDistributionValueForChild
81123 ) ;
82- expect ( actualSerializedItems [ 0 ] . _self ) . toEqual ( resource . _self ) ;
83- expect ( actualSerializedItems [ 0 ] . key ) . toEqual ( resource . _self ) ;
84- expect ( actualSerializedItems [ 0 ] . project ) . toEqual ( resource . _project ) ;
124+ expect ( actualSerializedItems [ 1 ] . _self ) . toEqual ( resource . _self ) ;
125+ expect ( actualSerializedItems [ 1 ] . key ) . toEqual ( resource . _self ) ;
126+ expect ( actualSerializedItems [ 1 ] . project ) . toEqual ( resource . _project ) ;
127+ expect ( actualSerializedItems [ 1 ] . localStorageType ) . toEqual ( 'distribution' ) ;
85128 } ) ;
86129
87130 it ( 'serializes resources with distribution object when content size is number' , ( ) => {
@@ -94,10 +137,10 @@ describe('ToLocalStorageResources', () => {
94137 } ;
95138 const actualSerializedItems = toLocalStorageResources ( resource , 'studios' ) ;
96139
97- expect ( actualSerializedItems [ 0 ] . distribution ?. contentSize ) . toEqual ( 123 ) ;
140+ expect ( actualSerializedItems [ 1 ] . distribution ?. contentSize ) . toEqual ( 123 ) ;
98141 } ) ;
99142
100- it ( 'serializes resources with distribution object when content size is array' , ( ) => {
143+ it ( 'sums up content size for distribution item when it is an array' , ( ) => {
101144 const resource = {
102145 ...resourceWithDistributionObject ,
103146 distribution : {
@@ -107,7 +150,7 @@ describe('ToLocalStorageResources', () => {
107150 } ;
108151 const actualSerializedItems = toLocalStorageResources ( resource , 'studios' ) ;
109152
110- expect ( actualSerializedItems [ 0 ] . distribution ?. contentSize ) . toEqual ( 30 ) ;
153+ expect ( actualSerializedItems [ 1 ] . distribution ?. contentSize ) . toEqual ( 30 ) ;
111154 } ) ;
112155
113156 it ( 'serializes resources when distribution is empty array' , ( ) => {
@@ -118,8 +161,8 @@ describe('ToLocalStorageResources', () => {
118161 const expectedDistributionValue = {
119162 hasDistribution : true ,
120163 contentSize : 0 ,
121- encodingFormat : '' ,
122- label : '' ,
164+ encodingFormat : 'json ' ,
165+ label : 'metadata.json ' ,
123166 } ;
124167
125168 expect ( actualSerializedItems [ 0 ] . distribution ) . toEqual (
@@ -131,7 +174,7 @@ describe('ToLocalStorageResources', () => {
131174 const resource = { ...resourceWithoutDistrition , distribution : { } } ;
132175 const actualSerializedItems = toLocalStorageResources ( resource , 'studios' ) ;
133176
134- expect ( actualSerializedItems . length ) . toEqual ( 1 ) ;
177+ expect ( actualSerializedItems . length ) . toEqual ( 2 ) ;
135178 expect ( actualSerializedItems [ 0 ] . distribution ) . toBeDefined ( ) ;
136179 } ) ;
137180} ) ;
0 commit comments