package handlers import ( "net/http" "net/http/httptest" "testing" "time" "golang.org/x/crypto/bcrypt" ) func TestCreateCustomerInternalSecret(t *testing.T) { testDB, cleanup := SetupTestDB(t) defer cleanup() DB = testDB hashedPassword, _ := bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost) testDB.Exec( "INSERT INTO accounts (email, name, password, created_at) VALUES (?, ?, ?, ?)", "test@example.com", "Test Account", string(hashedPassword), time.Now().Unix(), ) var accountID int64 testDB.QueryRow("SELECT account_id FROM accounts WHERE email = ?", "test@example.com").Scan(&accountID) var clientID int64 testDB.QueryRow( "INSERT INTO clients (account_id, name, phone, created_at) VALUES (?, ?, ?, ?) RETURNING client_id", accountID, "Test Client", "+5521987654321", time.Now().Unix(), ).Scan(&clientID) req := httptest.NewRequest(http.MethodPost, "/customers", nil) req.PostForm = map[string][]string{ "name": {"+5521987654321"}, "phone": {"+5521987654321"}, "client_id": {string(rune(clientID))}, } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("X-Internal-Secret", "internal-secret") w := httptest.NewRecorder() CreateCustomer(w, req) if w.Code != http.StatusOK && w.Code != http.StatusFound { t.Fatalf("expected success with internal secret, got %d", w.Code) } }