@@ -98,7 +98,7 @@ func TestNoErrorOnCreatingDuplicateRecords(t *testing.T) {
98
98
}
99
99
100
100
func TestCreateUsageRecords_Updates (t * testing.T ) {
101
- conn := dbtest .ConnectForTests (t ). Debug ()
101
+ conn := dbtest .ConnectForTests (t )
102
102
103
103
instanceID := uuid .New ()
104
104
teamID := uuid .New ().String ()
@@ -149,3 +149,43 @@ func TestCreateUsageRecords_Updates(t *testing.T) {
149
149
require .Len (t , list , 1 )
150
150
require .Equal (t , update , list [0 ])
151
151
}
152
+
153
+ func TestListUsage_Ordering (t * testing.T ) {
154
+ conn := dbtest .ConnectForTests (t )
155
+ teamAttributionID := db .NewTeamAttributionID (uuid .New ().String ())
156
+ newest := db.WorkspaceInstanceUsage {
157
+ InstanceID : uuid .New (),
158
+ AttributionID : teamAttributionID ,
159
+ UserID : uuid .New (),
160
+ WorkspaceID : dbtest .GenerateWorkspaceID (),
161
+ ProjectID : uuid .New ().String (),
162
+ WorkspaceType : db .WorkspaceType_Prebuild ,
163
+ WorkspaceClass : db .WorkspaceClass_Default ,
164
+ CreditsUsed : 4.505 ,
165
+ StartedAt : time .Date (2022 , 7 , 15 , 10 , 30 , 30 , 5000 , time .UTC ),
166
+ // not stopped
167
+ }
168
+
169
+ oldest := db.WorkspaceInstanceUsage {
170
+ InstanceID : uuid .New (),
171
+ AttributionID : teamAttributionID ,
172
+ UserID : uuid .New (),
173
+ WorkspaceID : dbtest .GenerateWorkspaceID (),
174
+ ProjectID : uuid .New ().String (),
175
+ WorkspaceType : db .WorkspaceType_Prebuild ,
176
+ WorkspaceClass : db .WorkspaceClass_Default ,
177
+ CreditsUsed : 4.505 ,
178
+ StartedAt : time .Date (2022 , 7 , 14 , 10 , 30 , 30 , 5000 , time .UTC ),
179
+ StoppedAt : sql.NullTime {
180
+ Time : time .Date (2022 , 7 , 15 , 15 , 30 , 30 , 5000 , time .UTC ),
181
+ Valid : true ,
182
+ },
183
+ }
184
+
185
+ require .NoError (t , db .CreateUsageRecords (context .Background (), conn , []db.WorkspaceInstanceUsage {newest , oldest }))
186
+
187
+ listed , err := db .ListUsage (context .Background (), conn , teamAttributionID )
188
+ require .NoError (t , err )
189
+
190
+ require .Equal (t , []db.WorkspaceInstanceUsage {oldest , newest }, listed )
191
+ }
0 commit comments