@@ -200,6 +200,8 @@ func TestCollection_ComputedValues(t *testing.T) {
200200 // Check if the computed value is in the list of computed values
201201 require .Len (t , prop .ComputedValues , 1 )
202202 require .Equal (t , computedValue .Name , prop .ComputedValues [0 ].Name )
203+ require .Len (t , prop .ComputedValues [0 ].ComputeOn , 1 )
204+ require .Equal (t , computedValue .ComputeOn [0 ], prop .ComputedValues [0 ].ComputeOn [0 ])
203205 require .Equal (t , computedValue .Expression , prop .ComputedValues [0 ].Expression )
204206
205207 // Create a document
@@ -222,7 +224,20 @@ func TestCollection_ComputedValues(t *testing.T) {
222224 require .True (t , createdAtIsPresent )
223225
224226 // Verify that the computed value is a valid date
225- tm := time .Unix (int64 (createdAtValue .(float64 )), 0 )
227+ var createdAtValueInt64 int64
228+
229+ switch cav := createdAtValue .(type ) {
230+ case int64 :
231+ createdAtValueInt64 = cav
232+ case float64 :
233+ createdAtValueInt64 = int64 (cav )
234+ case uint64 :
235+ createdAtValueInt64 = int64 (cav )
236+ default :
237+ t .Fatalf ("Unexpected type of createdAt value: %T" , createdAtValue )
238+ }
239+
240+ tm := time .Unix (createdAtValueInt64 , 0 )
226241 require .True (t , tm .After (time .Now ().Add (- time .Second )))
227242 })
228243
@@ -263,6 +278,45 @@ func TestCollection_ComputedValues(t *testing.T) {
263278
264279 require .Len (t , prop .ComputedValues , 1 )
265280 })
281+
282+ t .Run ("Use default ComputeOn values in ComputedValues" , func (t * testing.T ) {
283+ name := "test_default_computeon_computed_values"
284+
285+ // Add an attribute with the creation timestamp to new documents
286+ computedValue := driver.ComputedValue {
287+ Name : "createdAt" ,
288+ Expression : "RETURN DATE_NOW()" ,
289+ Overwrite : true ,
290+ }
291+
292+ _ , err := db .CreateCollection (nil , name , nil )
293+ require .NoError (t , err )
294+
295+ // Collection must exist now
296+ col , err := db .Collection (nil , name )
297+ require .NoError (t , err )
298+
299+ prop , err := col .Properties (nil )
300+ require .NoError (t , err )
301+
302+ require .Len (t , prop .ComputedValues , 0 )
303+
304+ err = col .SetProperties (nil , driver.SetCollectionPropertiesOptions {
305+ ComputedValues : []driver.ComputedValue {computedValue },
306+ })
307+ require .NoError (t , err )
308+
309+ // Check if the computed value is in the list of computed values
310+ col , err = db .Collection (nil , name )
311+ require .NoError (t , err )
312+
313+ prop , err = col .Properties (nil )
314+ require .NoError (t , err )
315+
316+ require .Len (t , prop .ComputedValues , 1 )
317+ // we should get the default value for ComputeOn - ["insert", "update", "replace"]
318+ require .Len (t , prop .ComputedValues [0 ].ComputeOn , 3 )
319+ })
266320}
267321
268322// TestCreateSatelliteCollection create a satellite collection
0 commit comments