feat(users): add following check
All checks were successful
Security Scan / security (push) Successful in 13s
Test / test (push) Successful in 1m23s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 00:36:52 +00:00
parent e9faaabc8a
commit 7862054999
3 changed files with 59 additions and 0 deletions

View file

@ -220,6 +220,7 @@ Coverage notes: rows list direct tests when a symbol is named in test names or r
| method | TeamService.RemoveMember | `func (s *TeamService) RemoveMember(ctx context.Context, teamID int64, username string) error` | RemoveMember removes a user from a team. | No direct tests. |
| method | TeamService.RemoveRepo | `func (s *TeamService) RemoveRepo(ctx context.Context, teamID int64, org, repo string) error` | RemoveRepo removes a repository from a team. | No direct tests. |
| method | UserService.Follow | `func (s *UserService) Follow(ctx context.Context, username string) error` | Follow follows a user as the authenticated user. | No direct tests. |
| method | UserService.CheckFollowing | `func (s *UserService) CheckFollowing(ctx context.Context, username, target string) (bool, error)` | CheckFollowing reports whether one user is following another user. | `TestUserService_CheckFollowing_Good`, `TestUserService_CheckFollowing_Bad_NotFound` |
| method | UserService.GetCurrent | `func (s *UserService) GetCurrent(ctx context.Context) (*types.User, error)` | GetCurrent returns the authenticated user. | `TestUserService_Good_GetCurrent` |
| method | UserService.GetQuota | `func (s *UserService) GetQuota(ctx context.Context) (*types.QuotaInfo, error)` | GetQuota returns the authenticated user's quota information. | `TestUserService_GetQuota_Good` |
| method | UserService.ListStopwatches | `func (s *UserService) ListStopwatches(ctx context.Context) ([]types.StopWatch, error)` | ListStopwatches returns all existing stopwatches for the authenticated user. | `TestUserService_ListStopwatches_Good` |

View file

@ -3,6 +3,7 @@ package forge
import (
"context"
"iter"
"net/http"
"dappco.re/go/core/forge/types"
)
@ -179,6 +180,19 @@ func (s *UserService) Follow(ctx context.Context, username string) error {
return s.client.Put(ctx, path, nil, nil)
}
// CheckFollowing reports whether one user is following another user.
func (s *UserService) CheckFollowing(ctx context.Context, username, target string) (bool, error) {
path := ResolvePath("/api/v1/users/{username}/following/{target}", pathParams("username", username, "target", target))
resp, err := s.client.doJSON(ctx, http.MethodGet, path, nil, nil)
if err != nil {
if IsNotFound(err) {
return false, nil
}
return false, err
}
return resp.StatusCode == http.StatusNoContent, nil
}
// Unfollow unfollows a user as the authenticated user.
func (s *UserService) Unfollow(ctx context.Context, username string) error {
path := ResolvePath("/api/v1/user/following/{username}", pathParams("username", username))

View file

@ -268,6 +268,50 @@ func TestUserService_Block_Good(t *testing.T) {
}
}
func TestUserService_CheckFollowing_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/users/alice/following/bob" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
following, err := f.Users.CheckFollowing(context.Background(), "alice", "bob")
if err != nil {
t.Fatal(err)
}
if !following {
t.Fatal("got following=false, want true")
}
}
func TestUserService_CheckFollowing_Bad_NotFound(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/users/alice/following/bob" {
t.Errorf("wrong path: %s", r.URL.Path)
}
http.Error(w, "not found", http.StatusNotFound)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
following, err := f.Users.CheckFollowing(context.Background(), "alice", "bob")
if err != nil {
t.Fatal(err)
}
if following {
t.Fatal("got following=true, want false")
}
}
func TestUserService_Unblock_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut {