Skip to content

Commit

Permalink
chore: refactor hand-written code to match codegen updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 committed Dec 23, 2024
1 parent ad5ba71 commit 680f8bf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
32 changes: 16 additions & 16 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func (a *auth) CreateMagicLinkWithEmail(
send bool,
opts *MagicLinkOptions,
) (*MagicLink, error) {
args := CreateMagicLinkBody{
Email: email,
Channel: EmailChannel,
Type: magicLinkType,
Send: send,
args := magicLinkArgs{
Email: email,
ChannelType: EmailChannel,
Type: magicLinkType,
Send: send,
}

return a.createMagicLink(args, opts)
Expand All @@ -67,11 +67,11 @@ func (a *auth) CreateMagicLinkWithPhone(
send bool,
opts *MagicLinkOptions,
) (*MagicLink, error) {
args := CreateMagicLinkBody{
Phone: phone,
Channel: PhoneChannel,
Type: magicLinkType,
Send: send,
args := magicLinkArgs{
Phone: phone,
ChannelType: PhoneChannel,
Type: magicLinkType,
Send: send,
}

return a.createMagicLink(args, opts)
Expand All @@ -85,11 +85,11 @@ func (a *auth) CreateMagicLinkWithUser(
send bool,
opts *MagicLinkOptions,
) (*MagicLink, error) {
args := CreateMagicLinkBody{
UserID: userID,
Channel: channel,
Type: magicLinkType,
Send: send,
args := magicLinkArgs{
UserID: userID,
ChannelType: channel,
Type: magicLinkType,
Send: send,
}

return a.createMagicLink(args, opts)
Expand Down Expand Up @@ -123,7 +123,7 @@ func (a *auth) ValidateJWT(jwt string) (string, error) {
return userID, nil
}

func (a *auth) createMagicLink(args CreateMagicLinkBody, opts *MagicLinkOptions) (*MagicLink, error) {
func (a *auth) createMagicLink(args magicLinkArgs, opts *MagicLinkOptions) (*MagicLink, error) {
if opts != nil {
args.Language = opts.Language
args.MagicLinkPath = opts.MagicLinkPath
Expand Down
2 changes: 1 addition & 1 deletion passage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
PassageUserID string
PassageAuthToken string
RandomEmail = generateRandomEmail(14)
CreatedUser passage.User
CreatedUser passage.PassageUser
)

func generateRandomEmail(prefixLength int) string {
Expand Down
14 changes: 5 additions & 9 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"strings"
)

type PassageUser = User
type CreateUserArgs = CreateUserBody
type UpdateUserOptions = UpdateBody

type user struct {
appID string
client *ClientWithResponses
Expand All @@ -35,7 +31,7 @@ func (u *user) Get(userID string) (*PassageUser, error) {
}

if res.JSON200 != nil {
return &res.JSON200.User, nil
return &res.JSON200.PassageUser, nil
}

return nil, errorFromResponse(res.Body, res.StatusCode())
Expand Down Expand Up @@ -91,7 +87,7 @@ func (u *user) Activate(userID string) (*PassageUser, error) {
}

if res.JSON200 != nil {
return &res.JSON200.User, nil
return &res.JSON200.PassageUser, nil
}

return nil, errorFromResponse(res.Body, res.StatusCode())
Expand All @@ -109,7 +105,7 @@ func (u *user) Deactivate(userID string) (*PassageUser, error) {
}

if res.JSON200 != nil {
return &res.JSON200.User, nil
return &res.JSON200.PassageUser, nil
}

return nil, errorFromResponse(res.Body, res.StatusCode())
Expand All @@ -127,7 +123,7 @@ func (u *user) Update(userID string, options UpdateUserOptions) (*PassageUser, e
}

if res.JSON200 != nil {
return &res.JSON200.User, nil
return &res.JSON200.PassageUser, nil
}

return nil, errorFromResponse(res.Body, res.StatusCode())
Expand All @@ -145,7 +141,7 @@ func (u *user) Create(args CreateUserArgs) (*PassageUser, error) {
}

if res.JSON201 != nil {
return &res.JSON201.User, nil
return &res.JSON201.PassageUser, nil
}

return nil, errorFromResponse(res.Body, res.StatusCode())
Expand Down
26 changes: 13 additions & 13 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetInfoByIdentifier(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: RandomEmail,
}

Expand All @@ -77,7 +77,7 @@ func TestGetInfoByIdentifier(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: RandomEmail,
}

Expand All @@ -98,7 +98,7 @@ func TestGetInfoByIdentifier(t *testing.T) {
require.Nil(t, err)

phone := "+15005550007"
createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Phone: phone,
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func TestUpdate(t *testing.T) {
})
require.Nil(t, err)

updateBody := passage.UpdateBody{
updateBody := passage.UpdateUserOptions{
Email: "[email protected]",
Phone: "+15005550012",
UserMetadata: map[string]interface{}{
Expand All @@ -232,7 +232,7 @@ func TestUpdate(t *testing.T) {
assert.Equal(t, "+15005550012", user.Phone)
assert.Equal(t, "123", user.UserMetadata["example1"])

secondUpdateBody := passage.UpdateBody{
secondUpdateBody := passage.UpdateUserOptions{
Email: "[email protected]",
Phone: "+15005550012",
UserMetadata: map[string]interface{}{
Expand All @@ -252,7 +252,7 @@ func TestUpdate(t *testing.T) {
})
require.Nil(t, err)

updateBody := passage.UpdateBody{
updateBody := passage.UpdateUserOptions{
Phone: " ",
}
_, err = psg.User.Update(PassageUserID, updateBody)
Expand All @@ -267,7 +267,7 @@ func TestUpdate(t *testing.T) {
})
require.Nil(t, err)

updateBody := passage.UpdateBody{
updateBody := passage.UpdateUserOptions{
Email: " ",
}
_, err = psg.User.Update(PassageUserID, updateBody)
Expand All @@ -282,7 +282,7 @@ func TestUpdate(t *testing.T) {
})
require.Nil(t, err)

updateBody := passage.UpdateBody{
updateBody := passage.UpdateUserOptions{
Email: "[email protected]",
Phone: "+15005550012",
UserMetadata: map[string]interface{}{
Expand All @@ -301,7 +301,7 @@ func TestUpdate(t *testing.T) {
})
require.Nil(t, err)

updateBody := passage.UpdateBody{
updateBody := passage.UpdateUserOptions{
Email: "[email protected]",
Phone: "+15005550012",
UserMetadata: map[string]interface{}{
Expand All @@ -322,7 +322,7 @@ func TestCreate(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: RandomEmail,
}

Expand All @@ -339,7 +339,7 @@ func TestCreate(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: fmt.Sprintf("1%v", RandomEmail),
UserMetadata: map[string]interface{}{
"example1": "test",
Expand All @@ -360,7 +360,7 @@ func TestCreate(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: "",
Phone: "",
}
Expand All @@ -376,7 +376,7 @@ func TestCreate(t *testing.T) {
})
require.Nil(t, err)

createUserBody := passage.CreateUserBody{
createUserBody := passage.CreateUserArgs{
Email: RandomEmail,
}

Expand Down

0 comments on commit 680f8bf

Please sign in to comment.