Version 2.1 #41

Merged
danieljsummers merged 123 commits from version-2.1 into main 2024-03-27 00:13:28 +00:00
8 changed files with 503 additions and 20 deletions
Showing only changes of commit 3f269ed3ba - Show all commits

View File

@ -53,15 +53,18 @@ type PostgresPageData(log: ILogger) =
log.LogTrace "Page.countListed"
Count.byContains Table.Page {| webLogDoc webLogId with IsInPageList = true |}
/// Find a page by its ID (without revisions)
let findById pageId webLogId =
/// Find a page by its ID (without revisions or prior permalinks)
let findById pageId webLogId = backgroundTask {
log.LogTrace "Page.findById"
Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId
match! Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId with
| Some page -> return Some { page with PriorPermalinks = [] }
| None -> return None
}
/// Find a complete page by its ID
let findFullById pageId webLogId = backgroundTask {
log.LogTrace "Page.findFullById"
match! findById pageId webLogId with
match! Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId with
| Some page ->
let! withMore = appendPageRevisions page
return Some withMore

View File

@ -444,20 +444,27 @@ type RethinkDbData(conn: Net.IConnection, config: DataConfig, log: ILogger<Rethi
return result.Deleted > 0UL
}
member _.FindById pageId webLogId =
rethink<Page> {
member _.FindById pageId webLogId = backgroundTask {
let! page =
rethink<Page list> {
withTable Table.Page
get pageId
getAll [ pageId ]
without [ nameof Page.Empty.PriorPermalinks; nameof Page.Empty.Revisions ]
resultOption; withRetryOptionDefault
result; withRetryDefault
}
|> tryFirst <| conn
return
page
|> Option.filter (fun pg -> pg.WebLogId = webLogId)
|> Option.map (fun pg -> { pg with Revisions = []; PriorPermalinks = [] })
}
|> verifyWebLog webLogId (fun it -> it.WebLogId) <| conn
member _.FindByPermalink permalink webLogId =
rethink<Page list> {
withTable Table.Page
getAll [ [| webLogId :> obj; permalink |] ] (nameof Page.Empty.Permalink)
without [ nameof Page.Empty.PriorPermalinks; nameof Page.Empty.Revisions ]
merge (r.HashMap(nameof Page.Empty.PriorPermalinks, [||])
.With(nameof Page.Empty.Revisions, [||]))
limit 1
result; withRetryDefault
}
@ -474,7 +481,7 @@ type RethinkDbData(conn: Net.IConnection, config: DataConfig, log: ILogger<Rethi
result; withRetryDefault
}
|> tryFirst) conn
return result |> Option.map (fun pg -> pg.Permalink)
return result |> Option.map _.Permalink
}
member _.FindFullById pageId webLogId =
@ -483,7 +490,7 @@ type RethinkDbData(conn: Net.IConnection, config: DataConfig, log: ILogger<Rethi
get pageId
resultOption; withRetryOptionDefault
}
|> verifyWebLog webLogId (fun it -> it.WebLogId) <| conn
|> verifyWebLog webLogId _.WebLogId <| conn
member _.FindFullByWebLog webLogId = rethink<Page> {
withTable Table.Page

View File

@ -57,15 +57,18 @@ type SQLitePageData(conn: SqliteConnection, log: ILogger) =
[ webLogParam webLogId ]
(toCount >> int)
/// Find a page by its ID (without revisions)
let findById pageId webLogId =
/// Find a page by its ID (without revisions and prior permalinks)
let findById pageId webLogId = backgroundTask {
log.LogTrace "Page.findById"
Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId conn
match! Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId conn with
| Some page -> return Some { page with PriorPermalinks = [] }
| None -> return None
}
/// Find a complete page by its ID
let findFullById pageId webLogId = backgroundTask {
log.LogTrace "Page.findFullById"
match! findById pageId webLogId with
match! Document.findByIdAndWebLog<PageId, Page> Table.Page pageId webLogId conn with
| Some page ->
let! page = appendPageRevisions page
return Some page

View File

@ -1,5 +1,6 @@
module PageDataTests
open System
open Expecto
open MyWebLog
open MyWebLog.Data
@ -8,6 +9,12 @@ open NodaTime
/// The ID of the root web log
let rootId = WebLogId "uSitJEuD3UyzWC9jgOHc8g"
/// The ID of the "A cool page" page
let coolPageId = PageId "hgc_BLEZ50SoAWLuPNISvA"
/// The published and updated time of the "A cool page" page
let coolPagePublished = Instant.FromDateTimeOffset(DateTimeOffset.Parse "2024-01-20T22:14:28Z")
let ``Add succeeds`` (data: IData) = task {
let page =
{ Id = PageId "added-page"
@ -55,6 +62,8 @@ let ``All succeeds`` (data: IData) = task {
Expect.isEmpty pg.Metadata $"Page {idx} should have had no metadata"
Expect.isEmpty pg.Revisions $"Page {idx} should have had no revisions"
Expect.isEmpty pg.PriorPermalinks $"Page {idx} should have had no prior permalinks")
let! others = data.Page.All (WebLogId "not-there")
Expect.isEmpty others "There should not be pages retrieved"
}
let ``CountAll succeeds`` (data: IData) = task {
@ -66,3 +75,54 @@ let ``CountListed succeeds`` (data: IData) = task {
let! pages = data.Page.CountListed rootId
Expect.equal pages 1 "There should have been 1 page in the page list"
}
let ``FindById succeeds when a page is found`` (data: IData) = task {
let! page = data.Page.FindById coolPageId rootId
Expect.isSome page "A page should have been returned"
let pg = page.Value
Expect.equal pg.Id coolPageId "The wrong page was retrieved"
Expect.equal pg.WebLogId rootId "The page's web log did not match the called parameter"
Expect.equal pg.AuthorId (WebLogUserId "5EM2rimH9kONpmd2zQkiVA") "Author ID is incorrect"
Expect.equal pg.Title "Page Title" "Title is incorrect"
Expect.equal pg.Permalink (Permalink "a-cool-page.html") "Permalink is incorrect"
Expect.equal
pg.PublishedOn (Instant.FromDateTimeOffset(DateTimeOffset.Parse "2024-01-20T22:14:28Z")) "Published On is incorrect"
Expect.equal pg.UpdatedOn (Instant.FromDateTimeOffset(DateTimeOffset.Parse "2024-01-20T22:14:28Z")) "Updated On is incorrect"
Expect.isFalse pg.IsInPageList "Is in page list flag should not have been set"
Expect.equal pg.Text "<h1 id=\"a-cool-page\">A Cool Page</h1>\n<p>It really is cool!</p>\n" "Text is incorrect"
Expect.hasLength pg.Metadata 2 "There should be 2 metadata items on this page"
Expect.equal pg.Metadata[0].Name "Cool" "Meta item 0 name is incorrect"
Expect.equal pg.Metadata[0].Value "true" "Meta item 0 value is incorrect"
Expect.equal pg.Metadata[1].Name "Warm" "Meta item 1 name is incorrect"
Expect.equal pg.Metadata[1].Value "false" "Meta item 1 value is incorrect"
Expect.isEmpty pg.Revisions "Revisions should not have been retrieved"
Expect.isEmpty pg.PriorPermalinks "Prior permalinks should not have been retrieved"
}
let ``FindById succeeds when a page is not found (incorrect weblog)`` (data: IData) = task {
let! page = data.Page.FindById coolPageId (WebLogId "wrong")
Expect.isNone page "The page should not have been retrieved"
}
let ``FindById succeeds when a page is not found (bad page ID)`` (data: IData) = task {
let! page = data.Page.FindById (PageId "missing") rootId
Expect.isNone page "The page should not have been retrieved"
}
let ``FindFullById succeeds when a page is found`` (data: IData) = task {
let! page = data.Page.FindFullById coolPageId rootId
Expect.isSome page "A page should have been returned"
let pg = page.Value
Expect.equal pg.Id coolPageId "The wrong page was retrieved"
Expect.equal pg.WebLogId rootId "The page's web log did not match the called parameter"
Expect.hasLength pg.Revisions 1 "There should be 1 revision"
Expect.equal pg.Revisions[0].AsOf coolPagePublished "Revision 0 as-of is incorrect"
Expect.equal pg.Revisions[0].Text (Markdown "# A Cool Page\n\nIt really is cool!") "Revision 0 text is incorrect"
Expect.hasLength pg.PriorPermalinks 1 "There should be 1 prior permalink"
Expect.equal pg.PriorPermalinks[0] (Permalink "a-cool-pg.html") "Prior permalink 0 is incorrect"
}
let ``FindFullById succeeds when a page is not found`` (data: IData) = task {
let! page = data.Page.FindFullById (PageId "not-there") rootId
Expect.isNone page "A page should not have been retrieved"
}

View File

@ -131,6 +131,25 @@ let pageTests = testList "Page" [
testTask "CountListed succeeds" {
do! PageDataTests.``CountListed succeeds`` (mkData ())
}
testList "FindById" [
testTask "succeeds when a page is found" {
do! PageDataTests.``FindById succeeds when a page is found`` (mkData ())
}
testTask "succeeds when a page is not found (incorrect weblog)" {
do! PageDataTests.``FindById succeeds when a page is not found (incorrect weblog)`` (mkData ())
}
testTask "succeeds when a page is not found (bad page ID)" {
do! PageDataTests.``FindById succeeds when a page is not found (bad page ID)`` (mkData ())
}
]
testList "FindFullById" [
testTask "succeeds when a page is found" {
do! PageDataTests.``FindFullById succeeds when a page is found`` (mkData ())
}
testTask "succeeds when a page is not found" {
do! PageDataTests.``FindFullById succeeds when a page is not found`` (mkData ())
}
]
]
/// Drop the throwaway PostgreSQL database

View File

@ -130,6 +130,25 @@ let pageTests = testList "Page" [
testTask "CountListed succeeds" {
do! PageDataTests.``CountListed succeeds`` data.Value
}
testList "FindById" [
testTask "succeeds when a page is found" {
do! PageDataTests.``FindById succeeds when a page is found`` data.Value
}
testTask "succeeds when a page is not found (incorrect weblog)" {
do! PageDataTests.``FindById succeeds when a page is not found (incorrect weblog)`` data.Value
}
testTask "succeeds when a page is not found (bad page ID)" {
do! PageDataTests.``FindById succeeds when a page is not found (bad page ID)`` data.Value
}
]
testList "FindFullById" [
testTask "succeeds when a page is found" {
do! PageDataTests.``FindFullById succeeds when a page is found`` data.Value
}
testTask "succeeds when a page is not found" {
do! PageDataTests.``FindFullById succeeds when a page is not found`` data.Value
}
]
]
/// Drop the throwaway RethinkDB database

View File

@ -164,6 +164,35 @@ let pageTests = testList "Page" [
try do! PageDataTests.``CountListed succeeds`` data
finally dispose data
}
testList "FindById" [
testTask "succeeds when a page is found" {
let data = mkData ()
try do! PageDataTests.``FindById succeeds when a page is found`` data
finally dispose data
}
testTask "succeeds when a page is not found (incorrect weblog)" {
let data = mkData ()
try do! PageDataTests.``FindById succeeds when a page is not found (incorrect weblog)`` data
finally dispose data
}
testTask "succeeds when a page is not found (bad page ID)" {
let data = mkData ()
try do! PageDataTests.``FindById succeeds when a page is not found (bad page ID)`` data
finally dispose data
}
]
testList "FindFullById" [
testTask "succeeds when a page is found" {
let data = mkData ()
try do! PageDataTests.``FindFullById succeeds when a page is found`` data
finally dispose data
}
testTask "succeeds when a page is not found" {
let data = mkData ()
try do! PageDataTests.``FindFullById succeeds when a page is not found`` data
finally dispose data
}
]
]
/// Delete the SQLite database

File diff suppressed because one or more lines are too long