-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorgs_extra_test.go
More file actions
63 lines (57 loc) · 1.58 KB
/
orgs_extra_test.go
File metadata and controls
63 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package forge
import (
"context"
json "github.com/goccy/go-json"
"net/http"
"net/http/httptest"
"testing"
"dappco.re/go/core/forge/types"
)
func TestOrgService_ListOrgs_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/orgs" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.Header().Set("X-Total-Count", "1")
json.NewEncoder(w).Encode([]types.Organization{{ID: 1, Name: "core"}})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
orgs, err := f.Orgs.ListOrgs(context.Background())
if err != nil {
t.Fatal(err)
}
if len(orgs) != 1 || orgs[0].Name != "core" {
t.Fatalf("got %#v", orgs)
}
}
func TestOrgService_CreateOrg_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Errorf("expected POST, got %s", r.Method)
}
if r.URL.Path != "/api/v1/orgs" {
t.Errorf("wrong path: %s", r.URL.Path)
}
var body types.CreateOrgOption
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatal(err)
}
if body.UserName != "core" {
t.Fatalf("unexpected body: %+v", body)
}
json.NewEncoder(w).Encode(types.Organization{ID: 1, Name: body.UserName})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
org, err := f.Orgs.CreateOrg(context.Background(), &types.CreateOrgOption{UserName: "core"})
if err != nil {
t.Fatal(err)
}
if org.Name != "core" {
t.Fatalf("got name=%q", org.Name)
}
}