Skip to content

Commit ecffc8b

Browse files
committed
update field names and fix tests
1 parent 7c0cade commit ecffc8b

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5685,17 +5685,18 @@ func (q *FakeQuerier) GetUserStatusChanges(_ context.Context, arg database.GetUs
56855685
if change.ChangedAt.Before(arg.StartTime) || change.ChangedAt.After(arg.EndTime) {
56865686
continue
56875687
}
5688+
date := time.Date(change.ChangedAt.Year(), change.ChangedAt.Month(), change.ChangedAt.Day(), 0, 0, 0, 0, time.UTC)
56885689
if !slices.ContainsFunc(result, func(r database.GetUserStatusChangesRow) bool {
5689-
return r.ChangedAt.Equal(change.ChangedAt) && r.NewStatus == change.NewStatus
5690+
return r.Status == change.NewStatus && r.Date.Equal(date)
56905691
}) {
56915692
result = append(result, database.GetUserStatusChangesRow{
5692-
NewStatus: change.NewStatus,
5693-
ChangedAt: change.ChangedAt,
5694-
Count: 1,
5693+
Status: change.NewStatus,
5694+
Date: date,
5695+
Count: 1,
56955696
})
56965697
} else {
56975698
for i, r := range result {
5698-
if r.ChangedAt.Equal(change.ChangedAt) && r.NewStatus == change.NewStatus {
5699+
if r.Status == change.NewStatus && r.Date.Equal(date) {
56995700
result[i].Count++
57005701
break
57015702
}

coderd/database/querier_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ func TestGetUserStatusChanges(t *testing.T) {
23282328
// We should have an entry for each status change
23292329
require.Len(t, userStatusChanges, 5, "should have 1 user * 5 days = 5 rows")
23302330
for _, row := range userStatusChanges {
2331-
require.Equal(t, row.NewStatus, tc.status, "should have the correct status")
2331+
require.Equal(t, row.Status, tc.status, "should have the correct status")
23322332
}
23332333
})
23342334
}
@@ -2422,10 +2422,10 @@ func TestGetUserStatusChanges(t *testing.T) {
24222422
// We should have an entry for each status (active, dormant, suspended) for each day
24232423
require.Len(t, userStatusChanges, 5, "should have 1 user * 5 days = 5 rows")
24242424
for _, row := range userStatusChanges {
2425-
if row.ChangedAt.Before(firstTransitionTime) {
2426-
require.Equal(t, row.NewStatus, tc.initialStatus, "should have the initial status")
2425+
if row.Date.Before(firstTransitionTime) {
2426+
require.Equal(t, row.Status, tc.initialStatus, "should have the initial status")
24272427
} else {
2428-
require.Equal(t, row.NewStatus, tc.targetStatus, "should have the target status")
2428+
require.Equal(t, row.Status, tc.targetStatus, "should have the target status")
24292429
}
24302430
}
24312431
})
@@ -2638,12 +2638,12 @@ func TestGetUserStatusChanges(t *testing.T) {
26382638
// Expected counts before, between and after the transitions should match:
26392639
for _, row := range userStatusChanges {
26402640
switch {
2641-
case row.ChangedAt.Before(firstTransitionTime):
2642-
require.Equal(t, row.Count, tc.expectedCounts["initial"][row.NewStatus], "should have the correct count before the first transition")
2643-
case row.ChangedAt.Before(secondTransitionTime):
2644-
require.Equal(t, row.Count, tc.expectedCounts["between"][row.NewStatus], "should have the correct count between the transitions")
2645-
case row.ChangedAt.Before(now):
2646-
require.Equal(t, row.Count, tc.expectedCounts["final"][row.NewStatus], "should have the correct count after the second transition")
2641+
case row.Date.Before(firstTransitionTime):
2642+
require.Equal(t, row.Count, tc.expectedCounts["initial"][row.Status], "should have the correct count before the first transition")
2643+
case row.Date.Before(secondTransitionTime):
2644+
require.Equal(t, row.Count, tc.expectedCounts["between"][row.Status], "should have the correct count between the transitions")
2645+
case row.Date.Before(now):
2646+
require.Equal(t, row.Count, tc.expectedCounts["final"][row.Status], "should have the correct count after the second transition")
26472647
}
26482648
}
26492649
})

coderd/database/queries.sql.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/insights.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,11 @@ GROUP BY utp.num, utp.template_ids, utp.name, utp.type, utp.display_name, utp.de
774774

775775
-- name: GetUserStatusChanges :many
776776
WITH dates AS (
777-
SELECT (generate_series(
777+
SELECT generate_series(
778778
date_trunc('day', @start_time::timestamptz),
779779
date_trunc('day', @end_time::timestamptz),
780780
'1 day'::interval
781-
) AT TIME ZONE (extract(timezone FROM @start_time::timestamptz)::text || ' minutes'))::timestamptz AS date
781+
)::timestamptz AS date
782782
),
783783
latest_status_before_range AS (
784784
-- Get the last status change for each user before our date range
@@ -826,11 +826,11 @@ daily_counts AS (
826826
GROUP BY d.date, asc1.new_status
827827
)
828828
SELECT
829-
date AS changed_at,
830-
new_status,
829+
date::timestamptz AS date,
830+
new_status AS status,
831831
count
832832
FROM daily_counts
833833
WHERE count > 0
834834
ORDER BY
835-
new_status ASC,
835+
status ASC,
836836
date ASC;

coderd/insights.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ func (api *API) insightsUserStatusCountsOverTime(rw http.ResponseWriter, r *http
341341
}
342342

343343
for _, row := range rows {
344-
status := codersdk.UserStatus(row.NewStatus)
344+
status := codersdk.UserStatus(row.Status)
345345
if _, ok := resp.StatusCounts[status]; !ok {
346346
resp.StatusCounts[status] = make([]codersdk.UserStatusChangeCount, 0)
347347
}
348348
resp.StatusCounts[status] = append(resp.StatusCounts[status], codersdk.UserStatusChangeCount{
349-
Date: row.ChangedAt,
349+
Date: row.Date,
350350
Count: row.Count,
351351
})
352352
}

0 commit comments

Comments
 (0)