-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build errors from adding the new method to the store interface
- Loading branch information
1 parent
8936336
commit c93f3da
Showing
4 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,4 +254,70 @@ func TestFileSystemStoreUsers(t *testing.T) { | |
assert.HasNoError(t, err) | ||
assert.Equals(t, users, initialUsers) | ||
}) | ||
|
||
t.Run("ValidateUserCredentials", func(t *testing.T) { | ||
createUserDTO := models.NewCreateUserDTO( | ||
"Claude Aldric", | ||
"[email protected]", | ||
"Caput Draconis", | ||
) | ||
hashedPassword, err := bcrypt.GenerateFromPassword( | ||
[]byte(createUserDTO.Password), | ||
bcrypt.DefaultCost, | ||
) | ||
assert.HasNoError(t, err) | ||
|
||
initialUsers := []models.User{ | ||
models.User{ | ||
Id: 1, | ||
Name: "Claude Aldric", | ||
Email: "[email protected]", | ||
Password: string(hashedPassword), | ||
}, | ||
} | ||
jsonUsers, err := utils.ConvertToJSON(initialUsers) | ||
assert.HasNoError(t, err) | ||
|
||
database, cleanDatabase := testutils.CreateTempFile(t, string(jsonUsers)) | ||
defer cleanDatabase() | ||
|
||
store, err := data.NewFileSystemStore(database) | ||
assert.HasNoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
email string | ||
password string | ||
want bool | ||
}{ | ||
{ | ||
name: "when provided valid credentials", | ||
email: "[email protected]", | ||
password: "Caput Draconis", | ||
want: true, | ||
}, | ||
{ | ||
name: "when provided an invalid password", | ||
email: "[email protected]", | ||
password: "password", | ||
want: false, | ||
}, | ||
{ | ||
name: "when provided an invalid email", | ||
email: "[email protected]", | ||
password: "Caput Draconis", | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
assert.Equals( | ||
t, | ||
store.ValidateUserCredentials(test.email, test.password), | ||
test.want, | ||
) | ||
}) | ||
} | ||
}) | ||
} |
This file contains 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
This file contains 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