Skip to content

Commit b9c971c

Browse files
test(coverage): final pass #3 — env_policy.Get nil-policy + bad-team-id arms
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 23e22b6 commit b9c971c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package handlers_test
2+
3+
// env_policy_get_final3_test.go — FINAL serial pass #3. Covers two
4+
// EnvPolicyHandler.Get arms:
5+
// - nil policy → returns empty object {} (env_policy.go:57)
6+
// - bad team_id in token → 401 (env_policy.go:44)
7+
8+
import (
9+
"net/http"
10+
"net/http/httptest"
11+
"testing"
12+
13+
"github.com/google/uuid"
14+
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
16+
17+
"instant.dev/internal/testhelpers"
18+
)
19+
20+
// TestEnvPolicyGetFinal3_NilPolicy — a team with no env-policy row → Get returns
21+
// 200 with an empty policy object (env_policy.go:57-58).
22+
func TestEnvPolicyGetFinal3_NilPolicy(t *testing.T) {
23+
db, clean := testhelpers.SetupTestDB(t)
24+
defer clean()
25+
teamID := testhelpers.MustCreateTeamDB(t, db, "pro")
26+
jwt := envPolicyJWT(t, teamID, uuid.NewString())
27+
28+
app := envPolicyMinimalApp(t, db)
29+
status, _ := epReq(t, app, http.MethodGet, jwt, "")
30+
require.Equal(t, http.StatusOK, status)
31+
}
32+
33+
// TestEnvPolicyGetFinal3_BadTeamID — a JWT carrying a non-UUID team_id →
34+
// uuid.Parse fails inside Get → 401 (env_policy.go:44-45).
35+
func TestEnvPolicyGetFinal3_BadTeamID(t *testing.T) {
36+
db, clean := testhelpers.SetupTestDB(t)
37+
defer clean()
38+
jwt := testhelpers.MustSignSessionJWT(t, uuid.NewString(), "not-a-uuid", testhelpers.UniqueEmail(t))
39+
app := envPolicyMinimalApp(t, db)
40+
req := httptest.NewRequest(http.MethodGet, "/team/env-policy", nil)
41+
req.Header.Set("Authorization", "Bearer "+jwt)
42+
resp, err := app.Test(req, 5000)
43+
require.NoError(t, err)
44+
defer resp.Body.Close()
45+
// Either RequireAuth rejects (401) or Get's uuid.Parse rejects (401).
46+
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
47+
}

0 commit comments

Comments
 (0)