Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
branches:
- main
pull_request:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should run the tests on every PR, not just to main.

branches:
- main
workflow_dispatch:
inputs:
command:
Expand Down
71 changes: 71 additions & 0 deletions pkg/fusionauth/Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7008,6 +7008,36 @@ func (c *FusionAuthClient) RetrieveUserByLoginIdWithContext(ctx context.Context,
return &resp, &errors, err
}

// RetrieveUserByLoginIdWithLoginIdTypes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go doesn't support function overloading or optional params, so letting it create a separate function here.

// Retrieves the user for the loginId, using specific loginIdTypes.
//
// string loginId The email or username of the user.
// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. Defaults to [email, username]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as java about optional, but not sure how much we want to care about that

func (c *FusionAuthClient) RetrieveUserByLoginIdWithLoginIdTypes(loginId string, loginIdTypes []string) (*UserResponse, *Errors, error) {
return c.RetrieveUserByLoginIdWithLoginIdTypesWithContext(context.TODO(), loginId, loginIdTypes)
}

// RetrieveUserByLoginIdWithLoginIdTypesWithContext
// Retrieves the user for the loginId, using specific loginIdTypes.
//
// string loginId The email or username of the user.
// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. Defaults to [email, username]
func (c *FusionAuthClient) RetrieveUserByLoginIdWithLoginIdTypesWithContext(ctx context.Context, loginId string, loginIdTypes []string) (*UserResponse, *Errors, error) {
var resp UserResponse
var errors Errors

restClient := c.Start(&resp, &errors)
err := restClient.WithUri("/api/user").
WithParameter("loginId", loginId).
WithParameter("loginIdTypes", loginIdTypes).
WithMethod(http.MethodGet).
Do(ctx)
if restClient.ErrorRef == nil {
return &resp, nil, err
}
return &resp, &errors, err
}

// RetrieveUserByUsername
// Retrieves the user for the given username.
//
Expand Down Expand Up @@ -7344,6 +7374,47 @@ func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdWithContext(ctx conte
return &resp, &errors, err
}

// RetrieveUserLoginReportByLoginIdAndLoginIdTypes
// Retrieves the login report between the two instants for a particular user by login Id, using specific loginIdTypes. If you specify an application id, it will only return the
// login counts for that application.
//
// string applicationId (Optional) The application id.
// string loginId The userId id.
// int64 start The start instant as UTC milliseconds since Epoch.
// int64 end The end instant as UTC milliseconds since Epoch.
// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. Defaults to [email, username]
func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdAndLoginIdTypes(applicationId string, loginId string, start int64, end int64, loginIdTypes []string) (*LoginReportResponse, *Errors, error) {
return c.RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext(context.TODO(), applicationId, loginId, start, end, loginIdTypes)
}

// RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext
// Retrieves the login report between the two instants for a particular user by login Id, using specific loginIdTypes. If you specify an application id, it will only return the
// login counts for that application.
//
// string applicationId (Optional) The application id.
// string loginId The userId id.
// int64 start The start instant as UTC milliseconds since Epoch.
// int64 end The end instant as UTC milliseconds since Epoch.
// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. Defaults to [email, username]
func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext(ctx context.Context, applicationId string, loginId string, start int64, end int64, loginIdTypes []string) (*LoginReportResponse, *Errors, error) {
var resp LoginReportResponse
var errors Errors

restClient := c.Start(&resp, &errors)
err := restClient.WithUri("/api/report/login").
WithParameter("applicationId", applicationId).
WithParameter("loginId", loginId).
WithParameter("start", strconv.FormatInt(start, 10)).
WithParameter("end", strconv.FormatInt(end, 10)).
WithParameter("loginIdTypes", loginIdTypes).
WithMethod(http.MethodGet).
Do(ctx)
if restClient.ErrorRef == nil {
return &resp, nil, err
}
return &resp, &errors, err
}

// RetrieveUserRecentLogins
// Retrieves the last number of login records for a user.
//
Expand Down
22 changes: 22 additions & 0 deletions pkg/fusionauth/Client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ func TestRetrieveUserSuccess(t *testing.T) {
assert.Equal(t, 200, userResponse.StatusCode)
}

func TestRetrieveUserByLoginIdSuccess(t *testing.T) {
loginIdTypes := []string{"email"}

userResponse, errors, _ := faClient.RetrieveUserByLoginIdWithLoginIdTypes("richard@example.com", loginIdTypes)
errJson, _ := json.Marshal(errors)
fmt.Println(string(errJson))

assert.Equal(t, (*Errors)(nil), errors)
assert.Equal(t, 200, userResponse.StatusCode)
}

// TODO: Will pass when issue 1 is released
// func TestRetrieveUserByLoginIdWrongIdentityType(t *testing.T) {
// loginIdTypes := []string{"phoneNumber"}
//
// userResponse, errors, _ := faClient.RetrieveUserByLoginIdWithLoginIdTypes("richard@example.com", loginIdTypes)
// errJson, _ := json.Marshal(errors)
// fmt.Println(string(errJson))
//
// assert.Equal(t, 404, userResponse.StatusCode)
// }

func TestMain(m *testing.M) {
os.Exit(m.Run())
}