mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
refactor: migrate auth routes to v1 package (#1841)
* feat: add api v1 packages * chore: migrate auth to v1 * chore: update test
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/usememos/memos/api"
|
||||
apiv1 "github.com/usememos/memos/api/v1"
|
||||
)
|
||||
|
||||
func TestAuthServer(t *testing.T) {
|
||||
@ -17,7 +18,7 @@ func TestAuthServer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer s.Shutdown(ctx)
|
||||
|
||||
signup := &api.SignUp{
|
||||
signup := &apiv1.SignUp{
|
||||
Username: "testuser",
|
||||
Password: "testpassword",
|
||||
}
|
||||
@ -26,15 +27,15 @@ func TestAuthServer(t *testing.T) {
|
||||
require.Equal(t, signup.Username, user.Username)
|
||||
}
|
||||
|
||||
func (s *TestingServer) postAuthSignup(signup *api.SignUp) (*api.User, error) {
|
||||
func (s *TestingServer) postAuthSignup(signup *apiv1.SignUp) (*api.User, error) {
|
||||
rawData, err := json.Marshal(&signup)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal signup")
|
||||
}
|
||||
reader := bytes.NewReader(rawData)
|
||||
body, err := s.post("/api/auth/signup", reader, nil)
|
||||
body, err := s.post("/api/v1/auth/signup", reader, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "fail to post request")
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
@ -43,12 +44,9 @@ func (s *TestingServer) postAuthSignup(signup *api.SignUp) (*api.User, error) {
|
||||
return nil, errors.Wrap(err, "fail to read response body")
|
||||
}
|
||||
|
||||
type AuthSignupResponse struct {
|
||||
Data *api.User `json:"data"`
|
||||
}
|
||||
res := new(AuthSignupResponse)
|
||||
if err = json.Unmarshal(buf.Bytes(), res); err != nil {
|
||||
user := &api.User{}
|
||||
if err = json.Unmarshal(buf.Bytes(), user); err != nil {
|
||||
return nil, errors.Wrap(err, "fail to unmarshal post signup response")
|
||||
}
|
||||
return res.Data, nil
|
||||
return user, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user