Skip to content

Commit

Permalink
Add email address to the report
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrzaszcz-form3 committed Oct 4, 2023
1 parent af53118 commit 4c05fec
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion cmd/generate_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"errors"
"github.com/form3tech-oss/go-pagerduty-oncall-report/api"
"testing"
"time"

"github.com/form3tech-oss/go-pagerduty-oncall-report/api"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -148,6 +149,85 @@ func Test_pagerDutyClient_getUserTimezone(t *testing.T) {
}
}

func Test_pagerDutyClient_getUserEmailAddress(t *testing.T) {
tests := []struct {
name string
cachedUsers []*api.User
defaultUserTimezone string
mockSetup func(mock *clientMock)
want string
wantErr bool
}{
{
name: "Successfully find the user email address",
cachedUsers: []*api.User{
{
ID: "USER_ID",
Email: "[email protected]",
},
},
want: "[email protected]",
wantErr: false,
},
{
name: "User with empty email address will receive empty string",
cachedUsers: []*api.User{
{
ID: "USER_ID",
},
},
want: "",
wantErr: false,
},
{
name: "User not cached will receive empty email address",
cachedUsers: []*api.User{
{
ID: "NOT_THE_USER_ID",
},
},
want: "",
wantErr: false,
},
{
name: "If user not cached it will load users in cache and successfully return email address",
mockSetup: func(mock *clientMock) {
mock.On("ListUsers").Once().Return([]*api.User{
{ID: "USER_ID", Email: "[email protected]"},
}, nil)
},
want: "[email protected]",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockedClient := &clientMock{}
if tt.mockSetup != nil {
tt.mockSetup(mockedClient)
}

pd := pagerDutyClient{
client: mockedClient,
cachedUsers: tt.cachedUsers,
defaultUserTimezone: tt.defaultUserTimezone,
}

got, err := pd.getUserEmail("USER_ID")
mockedClient.AssertExpectations(t)

if tt.wantErr == true {
require.Error(t, err)
return
}

require.NoError(t, err)

assert.Equal(t, tt.want, got)
})
}
}

func Test_pagerDutyClient_convertToUserLocalTimezone(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 4c05fec

Please sign in to comment.