Add notification unread count endpoint
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9f140e3f4f
commit
c1b7e25bfd
2 changed files with 31 additions and 0 deletions
|
|
@ -32,6 +32,15 @@ func (s *NotificationService) Iter(ctx context.Context) iter.Seq2[types.Notifica
|
|||
return ListIter[types.NotificationThread](ctx, s.client, "/api/v1/notifications", nil)
|
||||
}
|
||||
|
||||
// NewAvailable returns the count of unread notifications for the authenticated user.
|
||||
func (s *NotificationService) NewAvailable(ctx context.Context) (*types.NotificationCount, error) {
|
||||
var out types.NotificationCount
|
||||
if err := s.client.Get(ctx, "/api/v1/notifications/new", &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// ListRepo returns all notifications for a specific repository.
|
||||
func (s *NotificationService) ListRepo(ctx context.Context, owner, repo string) ([]types.NotificationThread, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/notifications", pathParams("owner", owner, "repo", repo))
|
||||
|
|
|
|||
|
|
@ -73,6 +73,28 @@ func TestNotificationService_ListRepo_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNotificationService_NewAvailable_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/notifications/new" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
}
|
||||
json.NewEncoder(w).Encode(types.NotificationCount{New: 3})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
count, err := f.Notifications.NewAvailable(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count.New != 3 {
|
||||
t.Fatalf("got new=%d, want 3", count.New)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationService_GetThread_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue