From 680f8bf94b22cbdf678b3bf6edb2f29be354121a Mon Sep 17 00:00:00 2001 From: Chris Tran Date: Thu, 19 Dec 2024 17:59:49 -0600 Subject: [PATCH] chore: refactor hand-written code to match codegen updates --- auth.go | 32 ++++++++++++++++---------------- passage_test.go | 2 +- user.go | 14 +++++--------- user_test.go | 26 +++++++++++++------------- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/auth.go b/auth.go index e5e2703..85cd131 100644 --- a/auth.go +++ b/auth.go @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/passage_test.go b/passage_test.go index 001ca70..27c262f 100644 --- a/passage_test.go +++ b/passage_test.go @@ -18,7 +18,7 @@ var ( PassageUserID string PassageAuthToken string RandomEmail = generateRandomEmail(14) - CreatedUser passage.User + CreatedUser passage.PassageUser ) func generateRandomEmail(prefixLength int) string { diff --git a/user.go b/user.go index 8d79cd2..eacecca 100644 --- a/user.go +++ b/user.go @@ -7,10 +7,6 @@ import ( "strings" ) -type PassageUser = User -type CreateUserArgs = CreateUserBody -type UpdateUserOptions = UpdateBody - type user struct { appID string client *ClientWithResponses @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/user_test.go b/user_test.go index 6636266..c43ccec 100644 --- a/user_test.go +++ b/user_test.go @@ -52,7 +52,7 @@ func TestGetInfoByIdentifier(t *testing.T) { }) require.Nil(t, err) - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Email: RandomEmail, } @@ -77,7 +77,7 @@ func TestGetInfoByIdentifier(t *testing.T) { }) require.Nil(t, err) - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Email: RandomEmail, } @@ -98,7 +98,7 @@ func TestGetInfoByIdentifier(t *testing.T) { require.Nil(t, err) phone := "+15005550007" - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Phone: phone, } @@ -219,7 +219,7 @@ func TestUpdate(t *testing.T) { }) require.Nil(t, err) - updateBody := passage.UpdateBody{ + updateBody := passage.UpdateUserOptions{ Email: "updatedemail-gosdk@passage.id", Phone: "+15005550012", UserMetadata: map[string]interface{}{ @@ -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: "updatedemail-gosdk@passage.id", Phone: "+15005550012", UserMetadata: map[string]interface{}{ @@ -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) @@ -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) @@ -282,7 +282,7 @@ func TestUpdate(t *testing.T) { }) require.Nil(t, err) - updateBody := passage.UpdateBody{ + updateBody := passage.UpdateUserOptions{ Email: "updatedemail-gosdk@passage.id", Phone: "+15005550012", UserMetadata: map[string]interface{}{ @@ -301,7 +301,7 @@ func TestUpdate(t *testing.T) { }) require.Nil(t, err) - updateBody := passage.UpdateBody{ + updateBody := passage.UpdateUserOptions{ Email: "updatedemail-gosdk@passage.id", Phone: "+15005550012", UserMetadata: map[string]interface{}{ @@ -322,7 +322,7 @@ func TestCreate(t *testing.T) { }) require.Nil(t, err) - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Email: RandomEmail, } @@ -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", @@ -360,7 +360,7 @@ func TestCreate(t *testing.T) { }) require.Nil(t, err) - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Email: "", Phone: "", } @@ -376,7 +376,7 @@ func TestCreate(t *testing.T) { }) require.Nil(t, err) - createUserBody := passage.CreateUserBody{ + createUserBody := passage.CreateUserArgs{ Email: RandomEmail, }