2021-01-22 21:47:22 +00:00
|
|
|
// Package groupme defines a client capable of executing API commands for the GroupMe chat service
|
2020-07-30 02:20:57 +00:00
|
|
|
package groupme
|
|
|
|
|
|
|
|
import (
|
2021-01-22 21:47:22 +00:00
|
|
|
"context"
|
2020-07-30 02:20:57 +00:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UsersAPISuite struct{ APISuite }
|
|
|
|
|
|
|
|
func (s *UsersAPISuite) SetupSuite() {
|
|
|
|
s.handler = usersTestRouter()
|
|
|
|
s.setupSuite()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UsersAPISuite) TestUsersMe() {
|
2021-01-22 21:47:22 +00:00
|
|
|
user, err := s.client.MyUser(context.Background())
|
2020-07-30 02:20:57 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Assert().NotZero(user)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UsersAPISuite) TestUsersUpdate() {
|
2021-01-22 21:47:22 +00:00
|
|
|
user, err := s.client.UpdateMyUser(context.Background(), UserSettings{})
|
2020-07-30 02:20:57 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Assert().NotZero(user)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUsersAPISuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(UsersAPISuite))
|
|
|
|
}
|
2021-01-22 21:47:22 +00:00
|
|
|
|
|
|
|
// nolint // not duplicate code
|
2020-07-30 02:20:57 +00:00
|
|
|
func usersTestRouter() *mux.Router {
|
2020-07-31 11:29:08 +00:00
|
|
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
2020-07-30 02:20:57 +00:00
|
|
|
|
|
|
|
// Me
|
|
|
|
router.Path("/users/me").
|
|
|
|
Methods("GET").
|
|
|
|
Name("MyUser").
|
|
|
|
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
w.WriteHeader(200)
|
|
|
|
fmt.Fprint(w, `{
|
|
|
|
"response": {
|
|
|
|
"id": "1234567890",
|
|
|
|
"phone_number": "+1 2123001234",
|
|
|
|
"image_url": "https://i.groupme.com/123456789",
|
|
|
|
"name": "Ronald Swanson",
|
|
|
|
"created_at": 1302623328,
|
|
|
|
"updated_at": 1302623328,
|
|
|
|
"email": "me@example.com",
|
|
|
|
"sms": false
|
|
|
|
},
|
|
|
|
"meta": {
|
|
|
|
"code": 200,
|
|
|
|
"errors": []
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Update
|
|
|
|
router.Path("/users/update").
|
|
|
|
Methods("POST").
|
|
|
|
Name("UpdateMyUser").
|
|
|
|
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
w.WriteHeader(200)
|
|
|
|
fmt.Fprint(w, `{
|
|
|
|
"response": {
|
|
|
|
"id": "1234567890",
|
|
|
|
"phone_number": "+1 2123001234",
|
|
|
|
"image_url": "https://i.groupme.com/123456789",
|
|
|
|
"name": "Ronald Swanson",
|
|
|
|
"created_at": 1302623328,
|
|
|
|
"updated_at": 1302623328,
|
|
|
|
"email": "me@example.com",
|
|
|
|
"sms": false
|
|
|
|
},
|
|
|
|
"meta": {
|
|
|
|
"code": 200,
|
|
|
|
"errors": []
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
/*// Return test router //*/
|
|
|
|
return router
|
|
|
|
}
|