Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1_developer_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (app *ApiServer) v1DeveloperApps(c *fiber.Ctx) error {
address = "0x" + address
}

// Normalize address to lowercase to ensure case-insensitive matching
// (addresses in the DB are stored as lowercase)
address = strings.ToLower(address)

developerApps, err := app.queries.GetDeveloperApps(c.Context(), dbv1.GetDeveloperAppsParams{
Address: address,
})
Expand Down
78 changes: 76 additions & 2 deletions api/v1_developer_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
"github.com/stretchr/testify/assert"
)

const testDeveloperAppAddress = "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6"

func TestGetDeveloperAppsQueries(t *testing.T) {
app := testAppWithFixtures(t)
developerApps, err := app.queries.GetDeveloperApps(t.Context(), dbv1.GetDeveloperAppsParams{
UserID: 1,
})
assert.NoError(t, err)
assert.Len(t, developerApps, 1)
assert.Equal(t, "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", developerApps[0].Address)
assert.Equal(t, testDeveloperAppAddress, developerApps[0].Address)
// redirect_uris must be an empty slice (not nil) when no URIs are registered
assert.Equal(t, []string{}, developerApps[0].RedirectUris)
}
Expand All @@ -26,11 +28,83 @@
var resp struct {
Data dbv1.GetDeveloperAppsRow
}
status, body := testGet(t, app, "/v1/developer_apps/0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", &resp)
status, body := testGet(t, app, "/v1/developer_apps/"+testDeveloperAppAddress, &resp)
assert.Equal(t, 200, status)
assert.True(t, strings.Contains(string(body), `"user_id":"7eP5n"`))
assert.True(t, strings.Contains(string(body), `"name":"cool app"`))
assert.Equal(t, "cool app", resp.Data.Name)
// redirect_uris must be an empty slice (not nil) when no URIs are registered
assert.Equal(t, []string{}, resp.Data.RedirectUris)
}

func TestGetDeveloperAppUppercaseAddress(t *testing.T) {

Check failure on line 40 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

other declaration of TestGetDeveloperAppUppercaseAddress
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Uppercase address should still find the app (case-insensitive lookup)
status, _ := testGet(t, app, "/v1/developer_apps/0x7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}

func TestGetDeveloperAppMixedCaseAddress(t *testing.T) {

Check failure on line 52 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

other declaration of TestGetDeveloperAppMixedCaseAddress
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Mixed-case address should still find the app (case-insensitive lookup)
status, _ := testGet(t, app, "/v1/developer_apps/0x7d7B6B7A97d1deEFe3A1ccc5A13c48E8F055e0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}

func TestGetDeveloperAppWithoutHexPrefix(t *testing.T) {

Check failure on line 64 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

other declaration of TestGetDeveloperAppWithoutHexPrefix
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Address without 0x prefix should still find the app
status, _ := testGet(t, app, "/v1/developer_apps/7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}

func TestGetDeveloperAppUppercaseAddress(t *testing.T) {

Check failure on line 76 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

TestGetDeveloperAppUppercaseAddress redeclared in this block
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Uppercase address should still find the app (case-insensitive lookup)
status, _ := testGet(t, app, "/v1/developer_apps/0x7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}

func TestGetDeveloperAppMixedCaseAddress(t *testing.T) {

Check failure on line 88 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

TestGetDeveloperAppMixedCaseAddress redeclared in this block
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Mixed-case address should still find the app (case-insensitive lookup)
status, _ := testGet(t, app, "/v1/developer_apps/0x7d7B6B7A97d1deEFe3A1ccc5A13c48E8F055e0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}

func TestGetDeveloperAppWithoutHexPrefix(t *testing.T) {

Check failure on line 100 in api/v1_developer_apps_test.go

View workflow job for this annotation

GitHub Actions / test

TestGetDeveloperAppWithoutHexPrefix redeclared in this block
app := testAppWithFixtures(t)

var resp struct {
Data dbv1.GetDeveloperAppsRow
}
// Address without 0x prefix should still find the app
status, _ := testGet(t, app, "/v1/developer_apps/7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp)
assert.Equal(t, 200, status)
assert.Equal(t, "cool app", resp.Data.Name)
}
Loading