@@ -2,8 +2,11 @@ package api
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67
8+ "api.audius.co/trashid"
9+
710 "github.com/stretchr/testify/assert"
811 "github.com/stretchr/testify/require"
912 "github.com/tidwall/gjson"
@@ -55,3 +58,24 @@ func TestV1TracksDownloadCounts(t *testing.T) {
5558 assert .Equal (t , int64 (2 ), byID ["eYJyn" ], "eYJyn download_count" )
5659 assert .Equal (t , int64 (0 ), byID ["eYZmn" ], "eYZmn download_count" )
5760}
61+
62+ func TestV1UserTracksDownloadCount (t * testing.T ) {
63+ app := testAppWithFixtures (t )
64+ ctx := context .Background ()
65+ require .NotNil (t , app .writePool , "test requires write pool" )
66+
67+ // Track 200 (eYJyn) is owned by user 2. Insert two download rows.
68+ _ , err := app .writePool .Exec (ctx , `
69+ INSERT INTO track_downloads (txhash, blocknumber, parent_track_id, track_id, user_id)
70+ VALUES ('tx-user-total-1', 101, 200, 200, 1), ('tx-user-total-2', 101, 200, 200, 2)
71+ ` )
72+ require .NoError (t , err )
73+
74+ user2Hash := trashid .MustEncodeHashID (2 )
75+ url := fmt .Sprintf ("/v1/full/users/%s/tracks/download_count" , user2Hash )
76+ status , body := testGet (t , app , url , nil )
77+ assert .Equal (t , 200 , status )
78+ jsonAssert (t , body , map [string ]any {
79+ "data" : 2 ,
80+ })
81+ }
0 commit comments