@@ -92,6 +92,41 @@ func TestDBFunctions(t *testing.T) {
9292 },
9393 },
9494 },
95+ {
96+ Key : "proj-to-test-override-deletion-on-update" ,
97+ SourceEnvironmentKey : "env-3" ,
98+ Context : ldContext ,
99+ LastSyncTime : now ,
100+ AllFlagsState : model.FlagsState {
101+ "flag-1" : model.FlagState {Value : ldvalue .Int (123 ), Version : 2 },
102+ "flag-2" : model.FlagState {Value : ldvalue .Float64 (99.99 ), Version : 2 },
103+ },
104+ AvailableVariations : []model.FlagVariation {
105+ {
106+ FlagKey : "flag-1" ,
107+ Variation : model.Variation {
108+ Id : "1" ,
109+ Value : ldvalue .Bool (true ),
110+ },
111+ },
112+ {
113+ FlagKey : "flag-1" ,
114+ Variation : model.Variation {
115+ Id : "2" ,
116+ Value : ldvalue .Bool (false ),
117+ },
118+ },
119+ {
120+ FlagKey : "flag-2" ,
121+ Variation : model.Variation {
122+ Id : "3" ,
123+ Description : lo .ToPtr ("cool description" ),
124+ Name : lo .ToPtr ("cool name" ),
125+ Value : ldvalue .String ("Cool" ),
126+ },
127+ },
128+ },
129+ },
95130 }
96131 actualProjectKeys := make (map [string ]bool , len (projects ))
97132
@@ -328,4 +363,39 @@ func TestDBFunctions(t *testing.T) {
328363
329364 assert .True (t , found )
330365 })
366+
367+ t .Run ("UpdateProject deletes overrides for flags that are no longer in the project" , func (t * testing.T ) {
368+ project := projects [2 ]
369+
370+ // create a new override for flag-1
371+ override , err := store .UpsertOverride (ctx , model.Override {
372+ ProjectKey : project .Key ,
373+ FlagKey : "flag-1" ,
374+ Value : ldvalue .Bool (false ),
375+ Active : true ,
376+ Version : 1 ,
377+ })
378+ require .NoError (t , err )
379+
380+ // verify the override was created
381+ overrides , err := store .GetOverridesForProject (ctx , project .Key )
382+ require .NoError (t , err )
383+ require .Len (t , overrides , 1 )
384+ assert .Equal (t , override , overrides [0 ])
385+
386+ // update the project to remove flag-1
387+ project .AvailableVariations = []model.FlagVariation {
388+ {
389+ FlagKey : "flag-2" ,
390+ },
391+ }
392+ updated , err := store .UpdateProject (ctx , project )
393+ assert .NoError (t , err )
394+ assert .True (t , updated )
395+
396+ // verify the override for flag-1 was deleted
397+ overrides , err = store .GetOverridesForProject (ctx , project .Key )
398+ require .NoError (t , err )
399+ require .Len (t , overrides , 0 )
400+ })
331401}
0 commit comments