From 96a94f011801b28a35a203eb14eab458ce225001 Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Tue, 16 Jun 2026 13:26:24 -0700 Subject: [PATCH 1/2] test: add integration tests for POST /v1/users/me/ping Covers authenticated 200, missing user_id 400, and unauthenticated 403 cases. Seeds the blocks table before users to satisfy the foreign key constraint. Co-Authored-By: Claude Opus 4.6 --- api/v1_users_ping_test.go | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 api/v1_users_ping_test.go diff --git a/api/v1_users_ping_test.go b/api/v1_users_ping_test.go new file mode 100644 index 00000000..1b90ea82 --- /dev/null +++ b/api/v1_users_ping_test.go @@ -0,0 +1,41 @@ +package api + +import ( + "context" + "testing" + + "api.audius.co/api/testdata" + "api.audius.co/database" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPostV1UsersPing(t *testing.T) { + app := emptyTestApp(t) + + _, err := app.pool.Exec(context.Background(), ` + INSERT INTO public.blocks (blockhash, parenthash, number) + VALUES ('block1', 'block0', 101) + ON CONFLICT DO NOTHING;`) + require.NoError(t, err) + + database.SeedTable(app.pool.Replicas[0], "users", testdata.UserFixtures) + + // user 1 = wallet 0x7d273271690538cf855e5b3002a0dd8c154bb060, encoded = 7eP5n + wallet := "0x7d273271690538cf855e5b3002a0dd8c154bb060" + + t.Run("authenticated request returns 200", func(t *testing.T) { + status, body := testPostWithWallet(t, app, "/v1/users/me/ping?user_id=7eP5n", wallet, nil, nil) + assert.Equal(t, 200, status, "body: %s", string(body)) + }) + + t.Run("missing user_id returns 400", func(t *testing.T) { + status, _ := testPostWithWallet(t, app, "/v1/users/me/ping", wallet, nil, nil) + assert.Equal(t, 400, status) + }) + + t.Run("unauthenticated request with user_id returns 403", func(t *testing.T) { + status, _ := testPost(t, app, "/v1/users/me/ping?user_id=7eP5n", nil, nil) + assert.Equal(t, 403, status) + }) +} From c7a34fa18fd920fac4ceb8a3f4ca9996709fdabe Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Tue, 16 Jun 2026 13:32:38 -0700 Subject: [PATCH 2/2] fix: add last_active_at column to test schema and seed blocks in test The users table was missing the last_active_at column in the base schema (01_schema.sql), and the test needed to seed the blocks table to satisfy the users.blocknumber foreign key constraint. Co-Authored-By: Claude Opus 4.6 --- api/v1_users_ping_test.go | 5 ++++- sql/01_schema.sql | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/v1_users_ping_test.go b/api/v1_users_ping_test.go index 1b90ea82..2845e072 100644 --- a/api/v1_users_ping_test.go +++ b/api/v1_users_ping_test.go @@ -13,11 +13,14 @@ import ( func TestPostV1UsersPing(t *testing.T) { app := emptyTestApp(t) - _, err := app.pool.Exec(context.Background(), ` + ctx := context.Background() + _, err := app.pool.Exec(ctx, ` INSERT INTO public.blocks (blockhash, parenthash, number) VALUES ('block1', 'block0', 101) ON CONFLICT DO NOTHING;`) require.NoError(t, err) + _, err = app.pool.Exec(ctx, `ALTER TABLE users ADD COLUMN IF NOT EXISTS last_active_at TIMESTAMPTZ DEFAULT NULL;`) + require.NoError(t, err) database.SeedTable(app.pool.Replicas[0], "users", testdata.UserFixtures) diff --git a/sql/01_schema.sql b/sql/01_schema.sql index ea499a65..c701ea6f 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -10286,7 +10286,8 @@ CREATE TABLE public.users ( website character varying, donation character varying, profile_type public.profile_type_enum, - coin_flair_mint text + coin_flair_mint text, + last_active_at timestamp with time zone );