-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package model | ||
|
||
type Team struct { | ||
Activate bool `json:"active"` // チームが利用可能な状態かどうか | ||
ID string `json:"id"` // チームの一意なID | ||
Name string `json:"name"` // チームに設定されている名前を表します。 | ||
Active bool `json:"active"` // チームが利用可能な状態かどうか | ||
ID string `json:"id"` // チームの一意なID | ||
Name string `json:"name"` // チームに設定されている名前を表します。 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package model_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
"github.com/minodisk/qiitactl/api" | ||
"github.com/minodisk/qiitactl/model" | ||
) | ||
|
||
func TestTeams_FetchTeams(t *testing.T) { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/api/v2/teams", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "GET" { | ||
log.Fatalf("wrong method: %s", r.Method) | ||
} | ||
w.Write([]byte(`[ | ||
{ | ||
"active": true, | ||
"id": "increments", | ||
"name": "Increments Inc." | ||
} | ||
]`)) | ||
}) | ||
server := httptest.NewServer(mux) | ||
defer server.Close() | ||
|
||
err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
client, err := api.NewClient(func(subDomain, path string) (url string) { | ||
url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path) | ||
return | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
teams, err := model.FetchTeams(client) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(teams) != 1 { | ||
t.Fatalf("wrong length of teams: expected %d, but actual %d", 1, len(teams)) | ||
} | ||
|
||
if teams[0].Active != true || teams[0].ID != "increments" || teams[0].Name != "Increments Inc." { | ||
t.Errorf("wrong team: %+v", teams[0]) | ||
} | ||
} | ||
|
||
func TestTeams_FetchTeamsError(t *testing.T) { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/api/v2/teams", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(503) | ||
}) | ||
server := httptest.NewServer(mux) | ||
defer server.Close() | ||
|
||
err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
client, err := api.NewClient(func(subDomain, path string) (url string) { | ||
url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path) | ||
return | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = model.FetchTeams(client) | ||
if err == nil { | ||
t.Fatal("should occur error") | ||
} | ||
} |