99 "strings"
1010 "testing"
1111
12+ "bridgerton.audius.co/api/testdata"
1213 "bridgerton.audius.co/config"
1314 "github.com/jackc/pgx/v5"
1415 "github.com/stretchr/testify/assert"
@@ -87,12 +88,10 @@ func TestHome(t *testing.T) {
8788 assert .True (t , strings .Contains (string (body ), "uptime" ))
8889}
8990
90- func Test200 (t * testing.T ) {
91+ func Test200UnAuthed (t * testing.T ) {
9192 urls := []string {
9293 "/v1/full/users?id=7eP5n&id=_some_invalid_hash_id" ,
9394
94- "/v1/full/users/account/0x7d273271690538cf855e5b3002a0dd8c154bb060" ,
95-
9695 "/v1/full/users/7eP5n" ,
9796 "/v1/full/users/7eP5n/followers" ,
9897 "/v1/full/users/7eP5n/following" ,
@@ -148,6 +147,28 @@ func Test200(t *testing.T) {
148147 }
149148}
150149
150+ func Test200Authed (t * testing.T ) {
151+ urls := []string {
152+ "/v1/full/users/account/0x7d273271690538cf855e5b3002a0dd8c154bb060" ,
153+ }
154+
155+ for _ , u := range urls {
156+ status , body := testGetWithWallet (t , u , "0x7d273271690538cf855e5b3002a0dd8c154bb060" )
157+ require .Equal (t , 200 , status , u + " " + string (body ))
158+
159+ // also test as a user
160+ if strings .Contains (u , "?" ) {
161+ u += "&user_id=7eP5n"
162+ } else {
163+ u += "?user_id=7eP5n"
164+ }
165+
166+ status , _ = testGetWithWallet (t , u , "0x7d273271690538cf855e5b3002a0dd8c154bb060" )
167+ require .Equal (t , 200 , status , u + " " + string (body ))
168+ }
169+
170+ }
171+
151172func testGet (t * testing.T , path string , dest ... any ) (int , []byte ) {
152173 req := httptest .NewRequest ("GET" , path , nil )
153174 res , err := app .Test (req , - 1 )
@@ -161,3 +182,28 @@ func testGet(t *testing.T, path string, dest ...any) (int, []byte) {
161182
162183 return res .StatusCode , body
163184}
185+
186+ // testGetWithWallet makes a GET request with authentication headers for the given wallet address
187+ func testGetWithWallet (t * testing.T , path string , walletAddress string , dest ... any ) (int , []byte ) {
188+ req := httptest .NewRequest ("GET" , path , nil )
189+
190+ // Add signature headers if wallet address is provided
191+ if walletAddress != "" {
192+ sigData , exists := testdata .GetSignatureData (walletAddress )
193+ if exists {
194+ req .Header .Set ("Encoded-Data-Message" , sigData .Message )
195+ req .Header .Set ("Encoded-Data-Signature" , sigData .Signature )
196+ }
197+ }
198+
199+ res , err := app .Test (req , - 1 )
200+ assert .NoError (t , err )
201+ body , _ := io .ReadAll (res .Body )
202+
203+ if len (dest ) > 0 {
204+ err = json .Unmarshal (body , & dest [0 ])
205+ assert .NoError (t , err )
206+ }
207+
208+ return res .StatusCode , body
209+ }
0 commit comments