diff --git a/src/MyWebLog.Tests/Data/PostgresDataTests.fs b/src/MyWebLog.Tests/Data/PostgresDataTests.fs
index 9e5c11e..87c45fc 100644
--- a/src/MyWebLog.Tests/Data/PostgresDataTests.fs
+++ b/src/MyWebLog.Tests/Data/PostgresDataTests.fs
@@ -549,6 +549,34 @@ let private uploadTests = testList "Upload" [
]
]
+let private webLogUserTests = testList "WebLogUser" [
+ testTask "Add succeeds" {
+ do! WebLogUserDataTests.``Add succeeds`` (mkData ())
+ }
+ testList "FindByEmail" [
+ testTask "succeeds when a user is found" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is found`` (mkData ())
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (incorrect weblog)`` (mkData ())
+ }
+ testTask "succeeds when a user is not found (bad email)" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (bad email)`` (mkData ())
+ }
+ ]
+ testList "FindById" [
+ testTask "succeeds when a user is found" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is found`` (mkData ())
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is not found (incorrect weblog)`` (mkData ())
+ }
+ testTask "succeeds when a user is not found (bad ID)" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is not found (bad ID)`` (mkData ())
+ }
+ ]
+]
+
/// Drop the throwaway PostgreSQL database
let private environmentCleanUp = test "Clean Up" {
if db.IsSome then db.Value.Dispose()
@@ -565,5 +593,6 @@ let all =
themeTests
themeAssetTests
uploadTests
+ webLogUserTests
environmentCleanUp ]
|> testSequenced
diff --git a/src/MyWebLog.Tests/Data/RethinkDbDataTests.fs b/src/MyWebLog.Tests/Data/RethinkDbDataTests.fs
index 2897ea2..ac8195a 100644
--- a/src/MyWebLog.Tests/Data/RethinkDbDataTests.fs
+++ b/src/MyWebLog.Tests/Data/RethinkDbDataTests.fs
@@ -549,6 +549,34 @@ let private uploadTests = testList "Upload" [
]
]
+let private webLogUserTests = testList "WebLogUser" [
+ testTask "Add succeeds" {
+ do! WebLogUserDataTests.``Add succeeds`` data.Value
+ }
+ testList "FindByEmail" [
+ testTask "succeeds when a user is found" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is found`` data.Value
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (incorrect weblog)`` data.Value
+ }
+ testTask "succeeds when a user is not found (bad email)" {
+ do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (bad email)`` data.Value
+ }
+ ]
+ testList "FindById" [
+ testTask "succeeds when a user is found" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is found`` data.Value
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is not found (incorrect weblog)`` data.Value
+ }
+ testTask "succeeds when a user is not found (bad ID)" {
+ do! WebLogUserDataTests.``FindById succeeds when a user is not found (bad ID)`` data.Value
+ }
+ ]
+]
+
/// Drop the throwaway RethinkDB database
let private environmentCleanUp = testTask "Clean Up" {
do! disposeData ()
@@ -565,5 +593,6 @@ let all =
themeTests
themeAssetTests
uploadTests
+ webLogUserTests
environmentCleanUp ]
|> testSequenced
diff --git a/src/MyWebLog.Tests/Data/SQLiteDataTests.fs b/src/MyWebLog.Tests/Data/SQLiteDataTests.fs
index 828a07b..0f800c7 100644
--- a/src/MyWebLog.Tests/Data/SQLiteDataTests.fs
+++ b/src/MyWebLog.Tests/Data/SQLiteDataTests.fs
@@ -812,6 +812,48 @@ let private uploadTests = testList "Upload" [
]
]
+let private webLogUserTests = testList "WebLogUser" [
+ testTask "Add succeeds" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``Add succeeds`` data
+ finally dispose data
+ }
+ testList "FindByEmail" [
+ testTask "succeeds when a user is found" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindByEmail succeeds when a user is found`` data
+ finally dispose data
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (incorrect weblog)`` data
+ finally dispose data
+ }
+ testTask "succeeds when a user is not found (bad email)" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindByEmail succeeds when a user is not found (bad email)`` data
+ finally dispose data
+ }
+ ]
+ testList "FindById" [
+ testTask "succeeds when a user is found" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindById succeeds when a user is found`` data
+ finally dispose data
+ }
+ testTask "succeeds when a user is not found (incorrect weblog)" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindById succeeds when a user is not found (incorrect weblog)`` data
+ finally dispose data
+ }
+ testTask "succeeds when a user is not found (bad ID)" {
+ let data = mkData ()
+ try do! WebLogUserDataTests.``FindById succeeds when a user is not found (bad ID)`` data
+ finally dispose data
+ }
+ ]
+]
+
/// Delete the SQLite database
let private environmentCleanUp = test "Clean Up" {
File.Delete dbName
@@ -829,5 +871,6 @@ let all =
themeTests
themeAssetTests
uploadTests
+ webLogUserTests
environmentCleanUp ]
|> testSequenced
diff --git a/src/MyWebLog.Tests/Data/WebLogUserDataTests.fs b/src/MyWebLog.Tests/Data/WebLogUserDataTests.fs
new file mode 100644
index 0000000..e3deb6b
--- /dev/null
+++ b/src/MyWebLog.Tests/Data/WebLogUserDataTests.fs
@@ -0,0 +1,86 @@
+///
+/// Integration tests for implementations
+///
+module WebLogUserDataTests
+
+open Expecto
+open MyWebLog
+open MyWebLog.Data
+open NodaTime
+
+/// The ID of the root web log
+let private rootId = CategoryDataTests.rootId
+
+/// The ID of the admin user
+let private adminId = WebLogUserId "5EM2rimH9kONpmd2zQkiVA"
+
+/// The ID of the editor user
+let private editorId = WebLogUserId "GPbJaSOwTkKt14ZKYyveKA"
+
+/// The ID of the author user
+let private authorId = WebLogUserId "iIRNLSeY0EanxRPyqGuwVg"
+
+/// The ID of the user added during the run of these tests
+let private newId = WebLogUserId "new-user"
+
+let ``Add succeeds`` (data: IData) = task {
+ do! data.WebLogUser.Add
+ { Id = newId
+ WebLogId = rootId
+ Email = "new@example.com"
+ FirstName = "New"
+ LastName = "User"
+ PreferredName = "n00b"
+ PasswordHash = "hashed-password"
+ Url = Some "https://example.com/~new"
+ AccessLevel = Author
+ CreatedOn = Noda.epoch + Duration.FromDays 365
+ LastSeenOn = None }
+ let! user = data.WebLogUser.FindById newId rootId
+ Expect.isSome user "There should have been a user returned"
+ let it = user.Value
+ Expect.equal it.Id newId "ID is incorrect"
+ Expect.equal it.WebLogId rootId "Web log ID is incorrect"
+ Expect.equal it.Email "new@example.com" "E-mail address is incorrect"
+ Expect.equal it.FirstName "New" "First name is incorrect"
+ Expect.equal it.LastName "User" "Last name is incorrect"
+ Expect.equal it.PreferredName "n00b" "Preferred name is incorrect"
+ Expect.equal it.PasswordHash "hashed-password" "Password hash is incorrect"
+ Expect.equal it.Url (Some "https://example.com/~new") "URL is incorrect"
+ Expect.equal it.AccessLevel Author "Access level is incorrect"
+ Expect.equal it.CreatedOn (Noda.epoch + Duration.FromDays 365) "Created on is incorrect"
+ Expect.isNone it.LastSeenOn "Last seen on should not have had a value"
+}
+
+let ``FindByEmail succeeds when a user is found`` (data: IData) = task {
+ let! user = data.WebLogUser.FindByEmail "root@example.com" rootId
+ Expect.isSome user "There should have been a user returned"
+ Expect.equal user.Value.Id adminId "The wrong user was returned"
+}
+
+let ``FindByEmail succeeds when a user is not found (incorrect weblog)`` (data: IData) = task {
+ let! user = data.WebLogUser.FindByEmail "root@example.com" (WebLogId "other")
+ Expect.isNone user "There should not have been a user returned"
+}
+
+let ``FindByEmail succeeds when a user is not found (bad email)`` (data: IData) = task {
+ let! user = data.WebLogUser.FindByEmail "wwwdata@example.com" rootId
+ Expect.isNone user "There should not have been a user returned"
+}
+
+let ``FindById succeeds when a user is found`` (data: IData) = task {
+ let! user = data.WebLogUser.FindById adminId rootId
+ Expect.isSome user "There should have been a user returned"
+ Expect.equal user.Value.Id adminId "The wrong user was returned"
+ // The remainder of field population is tested in the "Add succeeds" test above
+}
+
+let ``FindById succeeds when a user is not found (incorrect weblog)`` (data: IData) = task {
+ let! user = data.WebLogUser.FindById adminId (WebLogId "not-admin")
+ Expect.isNone user "There should not have been a user returned"
+}
+
+let ``FindById succeeds when a user is not found (bad ID)`` (data: IData) = task {
+ let! user = data.WebLogUser.FindById (WebLogUserId "tom") rootId
+ Expect.isNone user "There should not have been a user returned"
+}
diff --git a/src/MyWebLog.Tests/MyWebLog.Tests.fsproj b/src/MyWebLog.Tests/MyWebLog.Tests.fsproj
index c8a9ef1..407c213 100644
--- a/src/MyWebLog.Tests/MyWebLog.Tests.fsproj
+++ b/src/MyWebLog.Tests/MyWebLog.Tests.fsproj
@@ -16,6 +16,7 @@
+