@@ -2154,6 +2154,95 @@ describe('datasets and entities', () => {
2154
2154
} ) ;
2155
2155
} ) ;
2156
2156
2157
+ describe ( 'form schemas and dataset properties' , ( ) => {
2158
+ it ( 'should populate entity properties based on correct form schema' , testService ( async ( service , container ) => {
2159
+ const asAlice = await service . login ( 'alice' ) ;
2160
+
2161
+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
2162
+ . set ( 'Content-Type' , 'application/xml' )
2163
+ . send ( testData . forms . simpleEntity )
2164
+ . expect ( 200 ) ;
2165
+
2166
+ // Submission to old (and only) version of form should have only age filled in
2167
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
2168
+ . send ( testData . instances . simpleEntity . one )
2169
+ . set ( 'Content-Type' , 'application/xml' )
2170
+ . expect ( 200 ) ;
2171
+
2172
+ await exhaust ( container ) ;
2173
+
2174
+ // Upload a new version of the form with saveto added to hometown
2175
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/draft' )
2176
+ . set ( 'Content-Type' , 'application/xml' )
2177
+ . send ( testData . forms . simpleEntity
2178
+ . replace ( '<bind nodeset="/data/hometown" type="string"/>' , '<bind nodeset="/data/hometown" type="string" entities:saveto="hometown"/>' ) )
2179
+ . expect ( 200 ) ;
2180
+
2181
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/draft/publish?version=2.0' )
2182
+ . expect ( 200 ) ;
2183
+
2184
+ // Submission to old version of form should make entity with age filled in
2185
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
2186
+ . send ( testData . instances . simpleEntity . two )
2187
+ . set ( 'Content-Type' , 'application/xml' )
2188
+ . expect ( 200 ) ;
2189
+
2190
+ // Submission to new version of form should make entity with hometown filled in
2191
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
2192
+ . send ( testData . instances . simpleEntity . three . replace ( 'version="1.0"' , 'version="2.0"' ) )
2193
+ . set ( 'Content-Type' , 'application/xml' )
2194
+ . expect ( 200 ) ;
2195
+
2196
+ await exhaust ( container ) ;
2197
+
2198
+ // Upload a new version of the form with saveto removed from age
2199
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/draft' )
2200
+ . set ( 'Content-Type' , 'application/xml' )
2201
+ . send ( testData . forms . simpleEntity
2202
+ . replace ( '<bind nodeset="/data/age" type="int" entities:saveto="age"/>' , '<bind nodeset="/data/age" type="int"/>' )
2203
+ . replace ( '<bind nodeset="/data/hometown" type="string"/>' , '<bind nodeset="/data/hometown" type="string" entities:saveto="hometown"/>' ) )
2204
+ . expect ( 200 ) ;
2205
+
2206
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/draft/publish?version=3.0' )
2207
+ . expect ( 200 ) ;
2208
+
2209
+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
2210
+ . send ( testData . instances . simpleEntity . four . replace ( 'version="1.0"' , 'version="3.0"' ) )
2211
+ . set ( 'Content-Type' , 'application/xml' )
2212
+ . expect ( 200 ) ;
2213
+
2214
+ await exhaust ( container ) ;
2215
+
2216
+ // Submission 1 - should just have name and age
2217
+ await asAlice . get ( '/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc' )
2218
+ . expect ( 200 )
2219
+ . then ( ( { body : person } ) => {
2220
+ person . currentVersion . should . have . property ( 'data' ) . which . is . eql ( { age : '88' , first_name : 'Alice' } ) ;
2221
+ } ) ;
2222
+
2223
+ // Submission 2 - should also just have name and age
2224
+ await asAlice . get ( '/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789aaa' )
2225
+ . expect ( 200 )
2226
+ . then ( ( { body : person } ) => {
2227
+ person . currentVersion . should . have . property ( 'data' ) . which . is . eql ( { age : '30' , first_name : 'Jane' } ) ;
2228
+ } ) ;
2229
+
2230
+ // Submission 3 - should have name, age and hometown filled in
2231
+ await asAlice . get ( '/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789bbb' )
2232
+ . expect ( 200 )
2233
+ . then ( ( { body : person } ) => {
2234
+ person . currentVersion . should . have . property ( 'data' ) . which . is . eql ( { age : '40' , hometown : 'Toronto' , first_name : 'John' } ) ;
2235
+ } ) ;
2236
+
2237
+ // Submission 4 - should have name and hometown filled in, NO age
2238
+ await asAlice . get ( '/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789ccc' )
2239
+ . expect ( 200 )
2240
+ . then ( ( { body : person } ) => {
2241
+ person . currentVersion . should . have . property ( 'data' ) . which . is . eql ( { first_name : 'Robert' , hometown : 'Seattle' } ) ;
2242
+ } ) ;
2243
+ } ) ) ;
2244
+ } ) ;
2245
+
2157
2246
describe ( 'dataset and entities should have isolated lifecycle' , ( ) => {
2158
2247
it ( 'should allow a form that has created an entity to be purged' , testService ( async ( service , container ) => {
2159
2248
const asAlice = await service . login ( 'alice' ) ;
0 commit comments