Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepping for new care team alerting invites #125

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Changes from all 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
71 changes: 53 additions & 18 deletions api/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"fmt"

commonClients "github.com/tidepool-org/go-common/clients"
"github.com/tidepool-org/go-common/clients/highwater"
"github.com/tidepool-org/go-common/clients/shoreline"
Expand Down Expand Up @@ -49,41 +51,74 @@ var (
*/
mock_NoPermsGatekeeper = commonClients.NewGatekeeperMock(commonClients.Permissions{"upload": commonClients.Permission{"userid": "other-id"}}, nil)

mock_uid1Shoreline = newtestingShorelingMock(testing_uid1)
mock_uid1Shoreline = newtestingShorelineMock(testing_uid1)
)

// In an effort to mock shoreline so that we can return the token we wish
type testingShorelingMock struct{ userid string }
type testingShorelineMock struct{ userIDs []string }

func (m *testingShorelingMock) CreateCustodialUserForClinic(clinicId string, userData shoreline.CustodialUserData, token string) (*shoreline.UserData, error) {
func (m *testingShorelineMock) CreateCustodialUserForClinic(clinicId string, userData shoreline.CustodialUserData, token string) (*shoreline.UserData, error) {
panic("Not Implemented")
}

func (m *testingShorelingMock) DeleteUserSessions(userID, token string) error {
func (m *testingShorelineMock) DeleteUserSessions(userID, token string) error {
panic("Not Implemented")
}

func newtestingShorelingMock(userid string) *testingShorelingMock {
return &testingShorelingMock{userid: userid}
func newtestingShorelineMock(userIDs ...string) *testingShorelineMock {
return &testingShorelineMock{userIDs: userIDs}
}

func (m *testingShorelingMock) Start() error { return nil }
func (m *testingShorelingMock) Close() {}
func (m *testingShorelingMock) Login(username, password string) (*shoreline.UserData, string, error) {
return &shoreline.UserData{UserID: m.userid, Emails: []string{m.userid + "@email.org"}, Username: m.userid + "@email.org"}, "", nil
func (m *testingShorelineMock) Start() error { return nil }
func (m *testingShorelineMock) Close() {}
func (m *testingShorelineMock) Login(userID, password string) (*shoreline.UserData, string, error) {
for _, mockedUserID := range m.userIDs {
if mockedUserID == userID {
return m.mockUser(mockedUserID), "", nil
}
}
return nil, "", fmt.Errorf("userID not mocked: %q", userID)
}
func (m *testingShorelingMock) Signup(username, password, email string) (*shoreline.UserData, error) {
return &shoreline.UserData{UserID: m.userid, Emails: []string{m.userid + "@email.org"}, Username: m.userid + "@email.org"}, nil

func (m *testingShorelineMock) mockUser(userID string) *shoreline.UserData {
return &shoreline.UserData{
UserID: userID,
Emails: []string{userID + "@email.org"},
Username: userID + "@email.org",
}
}

func (m *testingShorelineMock) Signup(userID, password, email string) (*shoreline.UserData, error) {
for _, mockedUserID := range m.userIDs {
if mockedUserID == userID {
return m.mockUser(userID), nil
}
}
return nil, fmt.Errorf("userID not mocked: %q", userID)
}
func (m *testingShorelingMock) TokenProvide() string { return testing_token }
func (m *testingShorelingMock) GetUser(userID, token string) (*shoreline.UserData, error) {
return &shoreline.UserData{UserID: m.userid, Emails: []string{m.userid + "@email.org"}, Username: m.userid + "@email.org"}, nil

func (m *testingShorelineMock) TokenProvide() string { return testing_token }

func (m *testingShorelineMock) GetUser(userID, token string) (*shoreline.UserData, error) {
for _, mockedUserID := range m.userIDs {
if mockedUserID == userID {
return m.mockUser(userID), nil
}
}
return nil, fmt.Errorf("userID not mocked: %q", userID)
}
func (m *testingShorelingMock) UpdateUser(userID string, userUpdate shoreline.UserUpdate, token string) error {

func (m *testingShorelineMock) UpdateUser(userID string, userUpdate shoreline.UserUpdate, token string) error {
return nil
}
func (m *testingShorelingMock) CheckToken(token string) *shoreline.TokenData {
return &shoreline.TokenData{UserID: m.userid, IsServer: false}

func (m *testingShorelineMock) CheckToken(token string) *shoreline.TokenData {
for _, mockedUserID := range m.userIDs {
if mockedUserID == token || (token == testing_token_uid1 && mockedUserID == testing_uid1) {
return &shoreline.TokenData{UserID: mockedUserID, IsServer: false}
}
}
return nil
}

type (
Expand Down