Created
August 5, 2020 01:14
-
-
Save justinpage/38559d8640cd32c6a2bd4006830835ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package service | |
| import ( | |
| "testing" | |
| ) | |
| type preCheckMock struct { | |
| userExistsMock func(email string) bool | |
| } | |
| func (p preCheckMock) UserExists(email string) bool { | |
| return p.userExistsMock(email) | |
| } | |
| func TestCheckUserExist(t *testing.T) { | |
| user := User{ | |
| Name: "John Doe", | |
| Email: "[email protected]", | |
| UserName: "john", | |
| } | |
| err := RegisterUser(user, NewRegistrationPreChecker()) | |
| if err == nil { | |
| t.Error("Expected Register User to throw an error, got nil") | |
| } | |
| } | |
| func TestRegisterUser(t *testing.T) { | |
| user := User{ | |
| Name: "John Doe", | |
| Email: "[email protected]", | |
| UserName: "john", | |
| } | |
| regPreCond := preCheckMock{func(email string) bool { return false }} | |
| err := RegisterUser(user, regPreCond) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| regPreCond = preCheckMock{func(email string) bool { return true }} | |
| err = RegisterUser(user, regPreCond) | |
| if err == nil { | |
| t.Error("Expected Register User to throw an error, got nil") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment