mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-15 02:15:55 -07:00
fix: ensure listen activity correctly sums listen activity in step (#139)
* remove impossible nil check * fix listen activity not correctly aggregating step * remove stray log * fix test
This commit is contained in:
parent
3305ad269e
commit
d87ed2eb97
4 changed files with 43 additions and 24 deletions
|
|
@ -97,20 +97,19 @@ func TestListenActivity(t *testing.T) {
|
|||
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO listens (user_id, track_id, listened_at)
|
||||
VALUES (1, 1, NOW() - INTERVAL '1 month'),
|
||||
(1, 1, NOW() - INTERVAL '2 months'),
|
||||
(1, 1, NOW() - INTERVAL '3 months'),
|
||||
(1, 2, NOW() - INTERVAL '1 month'),
|
||||
(1, 2, NOW() - INTERVAL '2 months')`)
|
||||
VALUES (1, 1, NOW() - INTERVAL '1 month 1 day'),
|
||||
(1, 1, NOW() - INTERVAL '2 months 1 day'),
|
||||
(1, 1, NOW() - INTERVAL '3 months 1 day'),
|
||||
(1, 2, NOW() - INTERVAL '1 month 1 day'),
|
||||
(1, 2, NOW() - INTERVAL '1 hour'),
|
||||
(1, 2, NOW() - INTERVAL '1 minute'),
|
||||
(1, 2, NOW() - INTERVAL '2 months 1 day')`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// This test is bad, and I think it's because of daylight savings.
|
||||
// I need to find a better test.
|
||||
|
||||
activity, err = store.GetListenActivity(ctx, db.ListenActivityOpts{Step: db.StepMonth, Range: 8})
|
||||
require.NoError(t, err)
|
||||
// require.Len(t, activity, 8)
|
||||
// assert.Equal(t, []int64{0, 0, 0, 0, 1, 2, 2, 0}, flattenListenCounts(activity))
|
||||
require.Len(t, activity, 4)
|
||||
assert.Equal(t, []int64{1, 2, 2, 2}, flattenListenCounts(activity))
|
||||
|
||||
// Truncate listens table and insert specific dates for testing opts.Step = db.StepYear
|
||||
err = store.Exec(context.Background(), `TRUNCATE TABLE listens RESTART IDENTITY`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue