Add tag mapping tests

This commit is contained in:
Daniel J. Summers 2024-02-03 11:09:03 -05:00
parent 05d49e6ce9
commit 8183da7d5f
5 changed files with 317 additions and 0 deletions

View File

@ -358,6 +358,64 @@ let postTests = testList "Post" [
]
]
let tagMapTests = testList "TagMap" [
testList "FindById" [
testTask "succeeds when a tag mapping is found" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is found`` (mkData ())
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (incorrect weblog)`` (mkData ())
}
testTask "succeeds when a tag mapping is not found (bad tag map ID)" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (bad tag map ID)`` (mkData ())
}
]
testList "FindByUrlValue" [
testTask "succeeds when a tag mapping is found" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is found`` (mkData ())
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (incorrect weblog)``
(mkData ())
}
testTask "succeeds when a tag mapping is not found (no such value)" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (no such value)`` (mkData ())
}
]
testList "FindByWebLog" [
testTask "succeeds when tag mappings are found" {
do! TagMapDataTests.``FindByWebLog succeeds when tag mappings are found`` (mkData ())
}
testTask "succeeds when no tag mappings are found" {
do! TagMapDataTests.``FindByWebLog succeeds when no tag mappings are found`` (mkData ())
}
]
testList "FindMappingForTags" [
testTask "succeeds when mappings exist" {
do! TagMapDataTests.``FindMappingForTags succeeds when mappings exist`` (mkData ())
}
testTask "succeeds when no mappings exist" {
do! TagMapDataTests.``FindMappingForTags succeeds when no mappings exist`` (mkData ())
}
]
testList "Save" [
testTask "succeeds when adding a tag mapping" {
do! TagMapDataTests.``Save succeeds when adding a tag mapping`` (mkData ())
}
testTask "succeeds when updating a tag mapping" {
do! TagMapDataTests.``Save succeeds when updating a tag mapping`` (mkData ())
}
]
testList "Delete" [
testTask "succeeds when a tag mapping is deleted" {
do! TagMapDataTests.``Delete succeeds when a tag mapping is deleted`` (mkData ())
}
testTask "succeeds when a tag mapping is not deleted" {
do! TagMapDataTests.``Delete succeeds when a tag mapping is not deleted`` (mkData ())
}
]
]
/// Drop the throwaway PostgreSQL database
let environmentCleanUp = test "Clean Up" {
if db.IsSome then db.Value.Dispose()
@ -370,5 +428,6 @@ let all =
categoryTests
pageTests
postTests
tagMapTests
environmentCleanUp ]
|> testSequenced

View File

@ -358,6 +358,64 @@ let postTests = testList "Post" [
]
]
let tagMapTests = testList "TagMap" [
testList "FindById" [
testTask "succeeds when a tag mapping is found" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is found`` data.Value
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (incorrect weblog)`` data.Value
}
testTask "succeeds when a tag mapping is not found (bad tag map ID)" {
do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (bad tag map ID)`` data.Value
}
]
testList "FindByUrlValue" [
testTask "succeeds when a tag mapping is found" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is found`` data.Value
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (incorrect weblog)``
data.Value
}
testTask "succeeds when a tag mapping is not found (no such value)" {
do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (no such value)`` data.Value
}
]
testList "FindByWebLog" [
testTask "succeeds when tag mappings are found" {
do! TagMapDataTests.``FindByWebLog succeeds when tag mappings are found`` data.Value
}
testTask "succeeds when no tag mappings are found" {
do! TagMapDataTests.``FindByWebLog succeeds when no tag mappings are found`` data.Value
}
]
testList "FindMappingForTags" [
testTask "succeeds when mappings exist" {
do! TagMapDataTests.``FindMappingForTags succeeds when mappings exist`` data.Value
}
testTask "succeeds when no mappings exist" {
do! TagMapDataTests.``FindMappingForTags succeeds when no mappings exist`` data.Value
}
]
testList "Save" [
testTask "succeeds when adding a tag mapping" {
do! TagMapDataTests.``Save succeeds when adding a tag mapping`` data.Value
}
testTask "succeeds when updating a tag mapping" {
do! TagMapDataTests.``Save succeeds when updating a tag mapping`` data.Value
}
]
testList "Delete" [
testTask "succeeds when a tag mapping is deleted" {
do! TagMapDataTests.``Delete succeeds when a tag mapping is deleted`` data.Value
}
testTask "succeeds when a tag mapping is not deleted" {
do! TagMapDataTests.``Delete succeeds when a tag mapping is not deleted`` data.Value
}
]
]
/// Drop the throwaway RethinkDB database
let environmentCleanUp = testTask "Clean Up" {
do! disposeData ()
@ -370,5 +428,6 @@ let all =
categoryTests
pageTests
postTests
tagMapTests
environmentCleanUp ]
|> testSequenced

View File

@ -518,6 +518,91 @@ let postTests = testList "Post" [
]
]
let tagMapTests = testList "TagMap" [
testList "FindById" [
testTask "succeeds when a tag mapping is found" {
let data = mkData ()
try do! TagMapDataTests.``FindById succeeds when a tag mapping is found`` data
finally dispose data
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
let data = mkData ()
try do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (incorrect weblog)`` data
finally dispose data
}
testTask "succeeds when a tag mapping is not found (bad tag map ID)" {
let data = mkData ()
try do! TagMapDataTests.``FindById succeeds when a tag mapping is not found (bad tag map ID)`` data
finally dispose data
}
]
testList "FindByUrlValue" [
testTask "succeeds when a tag mapping is found" {
let data = mkData ()
try do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is found`` data
finally dispose data
}
testTask "succeeds when a tag mapping is not found (incorrect weblog)" {
let data = mkData ()
try do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (incorrect weblog)`` data
finally dispose data
}
testTask "succeeds when a tag mapping is not found (no such value)" {
let data = mkData ()
try do! TagMapDataTests.``FindByUrlValue succeeds when a tag mapping is not found (no such value)`` data
finally dispose data
}
]
testList "FindByWebLog" [
testTask "succeeds when tag mappings are found" {
let data = mkData ()
try do! TagMapDataTests.``FindByWebLog succeeds when tag mappings are found`` data
finally dispose data
}
testTask "succeeds when no tag mappings are found" {
let data = mkData ()
try do! TagMapDataTests.``FindByWebLog succeeds when no tag mappings are found`` data
finally dispose data
}
]
testList "FindMappingForTags" [
testTask "succeeds when mappings exist" {
let data = mkData ()
try do! TagMapDataTests.``FindMappingForTags succeeds when mappings exist`` data
finally dispose data
}
testTask "succeeds when no mappings exist" {
let data = mkData ()
try do! TagMapDataTests.``FindMappingForTags succeeds when no mappings exist`` data
finally dispose data
}
]
testList "Save" [
testTask "succeeds when adding a tag mapping" {
let data = mkData ()
try do! TagMapDataTests.``Save succeeds when adding a tag mapping`` data
finally dispose data
}
testTask "succeeds when updating a tag mapping" {
let data = mkData ()
try do! TagMapDataTests.``Save succeeds when updating a tag mapping`` data
finally dispose data
}
]
testList "Delete" [
testTask "succeeds when a tag mapping is deleted" {
let data = mkData ()
try do! TagMapDataTests.``Delete succeeds when a tag mapping is deleted`` data
finally dispose data
}
testTask "succeeds when a tag mapping is not deleted" {
let data = mkData ()
try do! TagMapDataTests.``Delete succeeds when a tag mapping is not deleted`` data
finally dispose data
}
]
]
/// Delete the SQLite database
let environmentCleanUp = test "Clean Up" {
File.Delete dbName
@ -531,5 +616,6 @@ let all =
categoryTests
pageTests
postTests
tagMapTests
environmentCleanUp ]
|> testSequenced

View File

@ -0,0 +1,112 @@
/// <summary>
/// Integration tests for <see cref="ITagMapData" /> implementations
/// </summary>
module TagMapDataTests
open Expecto
open MyWebLog
open MyWebLog.Data
/// The ID of the root web log
let rootId = CategoryDataTests.rootId
/// The ID of the f# tag
let fSharpId = TagMapId "Icm027noqE-rPHKZA98vAw"
/// The ID of the ghoti tag
let fishId = TagMapId "GdryXh-S0kGsNBs2RIacGA"
let ``FindById succeeds when a tag mapping is found`` (data: IData) = task {
let! tagMap = data.TagMap.FindById fSharpId rootId
Expect.isSome tagMap "There should have been a tag mapping returned"
let tag = tagMap.Value
Expect.equal tag.Id fSharpId "ID is incorrect"
Expect.equal tag.WebLogId rootId "Web log ID is incorrect"
Expect.equal tag.Tag "f#" "Tag is incorrect"
Expect.equal tag.UrlValue "f-sharp" "URL value is incorrect"
}
let ``FindById succeeds when a tag mapping is not found (incorrect weblog)`` (data: IData) = task {
let! tagMap = data.TagMap.FindById fSharpId (WebLogId "wrong")
Expect.isNone tagMap "There should not have been a tag mapping returned"
}
let ``FindById succeeds when a tag mapping is not found (bad tag map ID)`` (data: IData) = task {
let! tagMap = data.TagMap.FindById (TagMapId "out") rootId
Expect.isNone tagMap "There should not have been a tag mapping returned"
}
let ``FindByUrlValue succeeds when a tag mapping is found`` (data: IData) = task {
let! tagMap = data.TagMap.FindByUrlValue "f-sharp" rootId
Expect.isSome tagMap "There should have been a tag mapping returned"
Expect.equal tagMap.Value.Id fSharpId "ID is incorrect"
}
let ``FindByUrlValue succeeds when a tag mapping is not found (incorrect weblog)`` (data: IData) = task {
let! tagMap = data.TagMap.FindByUrlValue "f-sharp" (WebLogId "incorrect")
Expect.isNone tagMap "There should not have been a tag mapping returned"
}
let ``FindByUrlValue succeeds when a tag mapping is not found (no such value)`` (data: IData) = task {
let! tagMap = data.TagMap.FindByUrlValue "c-sharp" rootId
Expect.isNone tagMap "There should not have been a tag mapping returned"
}
let ``FindByWebLog succeeds when tag mappings are found`` (data: IData) = task {
let! mappings = data.TagMap.FindByWebLog rootId
Expect.hasLength mappings 2 "There should have been 2 tag mappings returned"
for mapping in mappings do
Expect.contains [ fSharpId; fishId ] mapping.Id $"Unexpected mapping ID ({mapping.Id})"
Expect.equal mapping.WebLogId rootId "Web log ID is incorrect"
Expect.isNotEmpty mapping.Tag "Tag should not have been blank"
Expect.isNotEmpty mapping.UrlValue "URL value should not have been blank"
}
let ``FindByWebLog succeeds when no tag mappings are found`` (data: IData) = task {
let! mappings = data.TagMap.FindByWebLog (WebLogId "no-maps")
Expect.isEmpty mappings "There should have been no tag mappings returned"
}
let ``FindMappingForTags succeeds when mappings exist`` (data: IData) = task {
let! mappings = data.TagMap.FindMappingForTags [ "f#"; "testing"; "unit" ] rootId
Expect.hasLength mappings 1 "There should have been one mapping returned"
Expect.equal mappings[0].Id fSharpId "The wrong mapping was returned"
}
let ``FindMappingForTags succeeds when no mappings exist`` (data: IData) = task {
let! mappings = data.TagMap.FindMappingForTags [ "c#"; "turkey"; "ham" ] rootId
Expect.isEmpty mappings "There should have been no tag mappings returned"
}
let ``Save succeeds when adding a tag mapping`` (data: IData) = task {
let mapId = TagMapId "test"
do! data.TagMap.Save { Id = mapId; WebLogId = rootId; Tag = "c#"; UrlValue = "c-sharp" }
let! mapping = data.TagMap.FindById mapId rootId
Expect.isSome mapping "The mapping should have been retrieved"
let tag = mapping.Value
Expect.equal tag.Id mapId "ID is incorrect"
Expect.equal tag.WebLogId rootId "Web log ID is incorrect"
Expect.equal tag.Tag "c#" "Tag is incorrect"
Expect.equal tag.UrlValue "c-sharp" "URL value is incorrect"
}
let ``Save succeeds when updating a tag mapping`` (data: IData) = task {
do! data.TagMap.Save { Id = fishId; WebLogId = rootId; Tag = "halibut"; UrlValue = "mackerel" }
let! mapping = data.TagMap.FindById fishId rootId
Expect.isSome mapping "The mapping should have been retrieved"
let tag = mapping.Value
Expect.equal tag.Id fishId "ID is incorrect"
Expect.equal tag.WebLogId rootId "Web log ID is incorrect"
Expect.equal tag.Tag "halibut" "Tag is incorrect"
Expect.equal tag.UrlValue "mackerel" "URL value is incorrect"
}
let ``Delete succeeds when a tag mapping is deleted`` (data: IData) = task {
let! deleted = data.TagMap.Delete fSharpId rootId
Expect.isTrue deleted "The tag mapping should have been deleted"
}
let ``Delete succeeds when a tag mapping is not deleted`` (data: IData) = task {
let! deleted = data.TagMap.Delete fSharpId rootId // this was deleted above
Expect.isFalse deleted "A tag mapping should not have been deleted"
}

View File

@ -13,6 +13,7 @@
<Compile Include="Data\CategoryDataTests.fs" />
<Compile Include="Data\PageDataTests.fs" />
<Compile Include="Data\PostDataTests.fs" />
<Compile Include="Data\TagMapDataTests.fs" />
<Compile Include="Data\RethinkDbDataTests.fs" />
<Compile Include="Data\SQLiteDataTests.fs" />
<Compile Include="Data\PostgresDataTests.fs" />