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

Usm 33 single user api #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
54 changes: 54 additions & 0 deletions endpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"testing"
"github.com/microlib/usermanager/lib"
"errors"
"context"
"fmt"
"reflect"
)

type FkUserManagerService struct{}

func (u *FkUserManagerService) FindUser(id string) (usermanager.UserInterface, error) {
if id == "1" {
return usermanager.NewUser("1", "Karl", "[email protected]", "mypassword"), nil
}
return &usermanager.User{}, errors.New("User not found")
}

func TestMakeFindUserEndpoint(t *testing.T) {
testCases := []struct {
findUserReq findUserRequest
expected findUserResponse
}{
{
findUserRequest{Id:"1"},
findUserResponse{
Id:"1",
Name: "Karl",
Email: "[email protected]",
Err: nil,
},
},
{
findUserRequest{Id:"2"},
findUserResponse{
Id:"",
Name: "",
Email: "",
Err: errors.New("User not found"),
},
},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("User with id '%s'", tc.findUserReq.Id), func(t *testing.T) {
res, _ := makeFindUserEndpoint(&FkUserManagerService{})(context.Background(), tc.findUserReq)
if !reflect.DeepEqual(res, tc.expected) {
t.Errorf("got %s; want %s", res, tc.expected)
}
})
}
}
4 changes: 0 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package main

type findUserRequest struct {
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
}

type findUserResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
Err error `json:"err,omitempty"`
}

Expand Down