Skip to content

Commit

Permalink
Additional testing of POST /signup
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoodhouse93 committed Nov 4, 2022
1 parent 3b01620 commit 4c90b33
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Required for V1 release:
- [ ] POST /callback
- [ ] GET /authorize
- [ ] POST /invite
- [ ] POST /signup
- [X] POST /signup
- [ ] POST /recover
- [ ] POST /magiclink
- [ ] POST /otp
Expand Down Expand Up @@ -66,6 +66,7 @@ Required for V1 release:
- [ ] GoTrue container - signup enabled, autoconfirm on
- [ ] GoTrue container - signup disabled
- [ ] Mail server
- [ ] Support for Captcha tokens

## Quick start

Expand Down
15 changes: 6 additions & 9 deletions signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"

"github.com/google/uuid"
"github.com/kwoodhouse93/gotrue-go/types"
)

const signupPath = "/signup"

type SignupRequest struct {
Email string `json:"email"`
Password string `json:"password"`
Email string `json:"email"`
Phone string `json:"phone"`
Password string `json:"password"`
Data map[string]interface{} `json:"data"`
}

type SignupResponse struct {
ID uuid.UUID `json:"id"`
Email string `json:"email"`
ConfirmationSentAt time.Time `json:"confirmation_sent_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
types.User
}

// POST /signup
Expand Down
39 changes: 31 additions & 8 deletions signup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,38 @@ func TestSignup(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

// Create a new user
user, err := client.Signup(gotrue.SignupRequest{
Email: "example@test.com",
// Signup with email
email := randomEmail()
userResp, err := client.Signup(gotrue.SignupRequest{
Email: email,
Password: "password",
})
require.NoError(err)
assert.Regexp(uuidRegex, userResp.ID)
assert.Equal(userResp.Email, email)
assert.InDelta(time.Now().Unix(), userResp.ConfirmationSentAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), userResp.CreatedAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), userResp.UpdatedAt.Unix(), float64(time.Second))

// Duplicate signup
dupeUserResp, err := client.Signup(gotrue.SignupRequest{
Email: email,
Password: "password",
})
require.NoError(err)
assert.Regexp(uuidRegex, user.ID)
assert.Equal(user.Email, "example@test.com")
assert.InDelta(time.Now().Unix(), user.ConfirmationSentAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), user.CreatedAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), user.UpdatedAt.Unix(), float64(time.Second))
assert.Regexp(uuidRegex, dupeUserResp.ID)
assert.Equal(dupeUserResp.Email, email)
assert.InDelta(time.Now().Unix(), dupeUserResp.ConfirmationSentAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), dupeUserResp.CreatedAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), dupeUserResp.UpdatedAt.Unix(), float64(time.Second))
assert.Equal(userResp.ID, dupeUserResp.ID)

// Sign up with phone
// Will error because SMS is not configured on the test server.
user, err := client.Signup(gotrue.SignupRequest{
Phone: "+15555555555",
Password: "password",
})
assert.Error(err)
assert.Nil(user)
}

0 comments on commit 4c90b33

Please sign in to comment.