Add tests for OpenGraph view model properties

This commit is contained in:
Daniel J. Summers 2025-07-26 20:33:30 -04:00
parent e33966b3df
commit 8b190a6c23
4 changed files with 267 additions and 41 deletions

View File

@ -442,6 +442,7 @@ type EditCommonModel() =
/// <param name="og">The existing OpenGraph property set</param> /// <param name="og">The existing OpenGraph property set</param>
member private this.PopulateOpenGraph(og: OpenGraphProperties) = member private this.PopulateOpenGraph(og: OpenGraphProperties) =
this.AssignOpenGraph <- true this.AssignOpenGraph <- true
this.OpenGraphType <- string og.Type
this.OpenGraphImageUrl <- og.Image.Url this.OpenGraphImageUrl <- og.Image.Url
this.OpenGraphImageType <- defaultArg og.Image.Type "" this.OpenGraphImageType <- defaultArg og.Image.Type ""
this.OpenGraphImageWidth <- defaultArg (og.Image.Width |> Option.map string) "" this.OpenGraphImageWidth <- defaultArg (og.Image.Width |> Option.map string) ""
@ -748,9 +749,10 @@ type EditPageModel() =
/// <summary>Update a page with values from this model</summary> /// <summary>Update a page with values from this model</summary>
/// <param name="page">The page to be updated</param> /// <param name="page">The page to be updated</param>
/// <param name="webLog">The web log to which this page belongs</param>
/// <param name="now">The <c>Instant</c> to use for this particular update</param> /// <param name="now">The <c>Instant</c> to use for this particular update</param>
/// <returns>The page, updated with the values from this model</returns> /// <returns>The page, updated with the values from this model</returns>
member this.UpdatePage (page: Page) now = member this.UpdatePage (page: Page) webLog now =
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" } let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
// Detect a permalink change, and add the prior one to the prior list // Detect a permalink change, and add the prior one to the prior list
match string page.Permalink with match string page.Permalink with
@ -766,6 +768,7 @@ type EditPageModel() =
IsInPageList = this.IsShownInPageList IsInPageList = this.IsShownInPageList
Template = match this.Template with "" -> None | tmpl -> Some tmpl Template = match this.Template with "" -> None | tmpl -> Some tmpl
Text = revision.Text.AsHtml() Text = revision.Text.AsHtml()
OpenGraph = this.ToOpenGraph webLog
Metadata = Seq.zip this.MetaNames this.MetaValues Metadata = Seq.zip this.MetaNames this.MetaValues
|> Seq.filter (fun it -> fst it > "") |> Seq.filter (fun it -> fst it > "")
|> Seq.map (fun it -> { Name = fst it; Value = snd it }) |> Seq.map (fun it -> { Name = fst it; Value = snd it })
@ -905,9 +908,10 @@ type EditPostModel() =
/// <summary>Update a post with values from the submitted form</summary> /// <summary>Update a post with values from the submitted form</summary>
/// <param name="post">The post which should be updated</param> /// <param name="post">The post which should be updated</param>
/// <param name="webLog">The web log to which this post belongs</param>
/// <param name="now">The <c>Instant</c> to use for this particular update</param> /// <param name="now">The <c>Instant</c> to use for this particular update</param>
/// <returns>The post, updated with the values from this model</returns> /// <returns>The post, updated with the values from this model</returns>
member this.UpdatePost (post: Post) now = member this.UpdatePost (post: Post) (webLog: WebLog) now =
let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" } let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" }
// Detect a permalink change, and add the prior one to the prior list // Detect a permalink change, and add the prior one to the prior list
match string post.Permalink with match string post.Permalink with
@ -931,6 +935,7 @@ type EditPostModel() =
Template = match this.Template.Trim() with "" -> None | tmpl -> Some tmpl Template = match this.Template.Trim() with "" -> None | tmpl -> Some tmpl
CategoryIds = this.CategoryIds |> Array.map CategoryId |> List.ofArray CategoryIds = this.CategoryIds |> Array.map CategoryId |> List.ofArray
Status = if this.DoPublish then Published else post.Status Status = if this.DoPublish then Published else post.Status
OpenGraph = this.ToOpenGraph webLog
Metadata = Seq.zip this.MetaNames this.MetaValues Metadata = Seq.zip this.MetaNames this.MetaValues
|> Seq.filter (fun it -> fst it > "") |> Seq.filter (fun it -> fst it > "")
|> Seq.map (fun it -> { Name = fst it; Value = snd it }) |> Seq.map (fun it -> { Name = fst it; Value = snd it })

View File

@ -206,6 +206,25 @@ let private testFullPage =
Revisions = Revisions =
[ { AsOf = Noda.epoch + Duration.FromHours 1; Text = Markdown "# Howdy!" } [ { AsOf = Noda.epoch + Duration.FromHours 1; Text = Markdown "# Howdy!" }
{ AsOf = Noda.epoch; Text = Html "<h1>howdy</h1>" } ] { AsOf = Noda.epoch; Text = Html "<h1>howdy</h1>" } ]
OpenGraph =
Some { Type = Book
Image =
{ Url = "https://unit.test/it.png"
Type = Some "test/png"
Width = Some 1
Height = Some 2
Alt = Some "huh" }
Audio = Some { Url = "https://unit.test/it.mp3"; Type = Some "test/mpeg-3" }
Description = Some "This is cool"
Determiner = Some "the"
Locale = Some "en-US"
LocaleAlternate = Some [ "es-MX"; "es-ES" ]
Video =
Some { Url = "https://unit.test/it.mp4"
Type = Some "test/mpeg-4"
Width = Some 5
Height = Some 6 }
Other = Some [ { Name = "the-other"; Value = "the-value" } ] }
Metadata = [ { Name = "Test"; Value = "me" }; { Name = "Two"; Value = "2" } ] } Metadata = [ { Name = "Test"; Value = "me" }; { Name = "Two"; Value = "2" } ] }
/// A full post used to test various models /// A full post used to test various models
@ -221,6 +240,25 @@ let testFullPost =
Text = "<p>A post!</p>" Text = "<p>A post!</p>"
CategoryIds = [ CategoryId "cat-a"; CategoryId "cat-b"; CategoryId "cat-n" ] CategoryIds = [ CategoryId "cat-a"; CategoryId "cat-b"; CategoryId "cat-n" ]
Tags = [ "demo"; "post" ] Tags = [ "demo"; "post" ]
OpenGraph =
Some { Type = MusicAlbum
Image =
{ Url = "https://unit.test/it.jpg"
Type = Some "test/jpg"
Width = Some 100
Height = Some 200
Alt = Some "it is a jpeg" }
Audio = Some { Url = "https://unit.test/that.mp3"; Type = Some "test/mp3" }
Description = Some "Just a post"
Determiner = Some "a"
Locale = Some "es-MX"
LocaleAlternate = Some [ "es-ES"; "en-EN" ]
Video =
Some { Url = "https://unit.test/that.mp4"
Type = Some "test/mp4"
Width = Some 50
Height = Some 60 }
Other = Some [ { Name = "an-other"; Value = "a-value" } ] }
Metadata = [ { Name = "A Meta"; Value = "A Value" } ] Metadata = [ { Name = "A Meta"; Value = "A Value" } ]
Revisions = Revisions =
[ { AsOf = Noda.epoch + Duration.FromDays 365; Text = Html "<p>A post!</p>" } [ { AsOf = Noda.epoch + Duration.FromDays 365; Text = Html "<p>A post!</p>" }
@ -266,9 +304,28 @@ let editCommonModelTests = testList "EditCommonModel" [
Expect.equal model.Template "" "Template not filled properly" Expect.equal model.Template "" "Template not filled properly"
Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Source "HTML" "Source not filled properly"
Expect.equal model.Text "" "Text not set properly" Expect.equal model.Text "" "Text not set properly"
Expect.equal model.MetaNames.Length 1 "MetaNames should have one entry" Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not have been assigned"
Expect.equal model.OpenGraphType "" "OpenGraph type not filled properly"
Expect.equal model.OpenGraphImageUrl "" "OpenGraph image URL not filled properly"
Expect.equal model.OpenGraphImageType "" "OpenGraph image type not filled properly"
Expect.equal model.OpenGraphImageWidth "" "OpenGraph image width not filled properly"
Expect.equal model.OpenGraphImageHeight "" "OpenGraph image height not filled properly"
Expect.equal model.OpenGraphImageAlt "" "OpenGraph image alt text not filled properly"
Expect.equal model.OpenGraphAudioUrl "" "OpenGraph audio URL not filled properly"
Expect.equal model.OpenGraphAudioType "" "OpenGraph audio type not filled properly"
Expect.equal model.OpenGraphDescription "" "OpenGraph description not filled properly"
Expect.equal model.OpenGraphDeterminer "" "OpenGraph determiner not filled properly"
Expect.equal model.OpenGraphLocale "" "OpenGraph locale not filled properly"
Expect.equal model.OpenGraphAlternateLocales "" "OpenGraph alt locales not filled properly"
Expect.equal model.OpenGraphVideoUrl "" "OpenGraph video URL not filled properly"
Expect.equal model.OpenGraphVideoType "" "OpenGraph video type not filled properly"
Expect.equal model.OpenGraphVideoWidth "" "OpenGraph video width not filled properly"
Expect.equal model.OpenGraphVideoHeight "" "OpenGraph video height not filled properly"
Expect.isEmpty model.OpenGraphExtraNames "OpenGraph extra names not filled properly"
Expect.isEmpty model.OpenGraphExtraValues "OpenGraph extra values not filled properly"
Expect.hasLength model.MetaNames 1 "MetaNames should have one entry"
Expect.equal model.MetaNames[0] "" "Meta name not set properly" Expect.equal model.MetaNames[0] "" "Meta name not set properly"
Expect.equal model.MetaValues.Length 1 "MetaValues should have one entry" Expect.hasLength model.MetaValues 1 "MetaValues should have one entry"
Expect.equal model.MetaValues[0] "" "Meta value not set properly" Expect.equal model.MetaValues[0] "" "Meta value not set properly"
} }
test "succeeds for filled page" { test "succeeds for filled page" {
@ -280,10 +337,31 @@ let editCommonModelTests = testList "EditCommonModel" [
Expect.equal model.Template "bork" "Template not filled properly" Expect.equal model.Template "bork" "Template not filled properly"
Expect.equal model.Source "Markdown" "Source not filled properly" Expect.equal model.Source "Markdown" "Source not filled properly"
Expect.equal model.Text "# Howdy!" "Text not filled properly" Expect.equal model.Text "# Howdy!" "Text not filled properly"
Expect.equal model.MetaNames.Length 2 "MetaNames should have two entries" Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned"
Expect.equal model.OpenGraphType "book" "OpenGraph type not filled properly"
Expect.equal model.OpenGraphImageUrl "https://unit.test/it.png" "OpenGraph image URL not filled properly"
Expect.equal model.OpenGraphImageType "test/png" "OpenGraph image type not filled properly"
Expect.equal model.OpenGraphImageWidth "1" "OpenGraph image width not filled properly"
Expect.equal model.OpenGraphImageHeight "2" "OpenGraph image height not filled properly"
Expect.equal model.OpenGraphImageAlt "huh" "OpenGraph image alt text not filled properly"
Expect.equal model.OpenGraphAudioUrl "https://unit.test/it.mp3" "OpenGraph audio URL not filled properly"
Expect.equal model.OpenGraphAudioType "test/mpeg-3" "OpenGraph audio type not filled properly"
Expect.equal model.OpenGraphDescription "This is cool" "OpenGraph description not filled properly"
Expect.equal model.OpenGraphDeterminer "the" "OpenGraph determiner not filled properly"
Expect.equal model.OpenGraphLocale "en-US" "OpenGraph locale not filled properly"
Expect.equal model.OpenGraphAlternateLocales "es-MX, es-ES" "OpenGraph alt locales not filled properly"
Expect.equal model.OpenGraphVideoUrl "https://unit.test/it.mp4" "OpenGraph video URL not filled properly"
Expect.equal model.OpenGraphVideoType "test/mpeg-4" "OpenGraph video type not filled properly"
Expect.equal model.OpenGraphVideoWidth "5" "OpenGraph video width not filled properly"
Expect.equal model.OpenGraphVideoHeight "6" "OpenGraph video height not filled properly"
Expect.hasLength model.OpenGraphExtraNames 1 "OpenGraph extra names should have had 1 entry"
Expect.equal model.OpenGraphExtraNames[0] "the-other" "OpenGraph extra names not filled properly"
Expect.hasLength model.OpenGraphExtraValues 1 "OpenGraph extra values should have had 1 entry"
Expect.equal model.OpenGraphExtraValues[0] "the-value" "OpenGraph extra values not filled properly"
Expect.hasLength model.MetaNames 2 "MetaNames should have two entries"
Expect.equal model.MetaNames[0] "Test" "Meta name 0 not set properly" Expect.equal model.MetaNames[0] "Test" "Meta name 0 not set properly"
Expect.equal model.MetaNames[1] "Two" "Meta name 1 not set properly" Expect.equal model.MetaNames[1] "Two" "Meta name 1 not set properly"
Expect.equal model.MetaValues.Length 2 "MetaValues should have two entries" Expect.hasLength model.MetaValues 2 "MetaValues should have two entries"
Expect.equal model.MetaValues[0] "me" "Meta value 0 not set properly" Expect.equal model.MetaValues[0] "me" "Meta value 0 not set properly"
Expect.equal model.MetaValues[1] "2" "Meta value 1 not set properly" Expect.equal model.MetaValues[1] "2" "Meta value 1 not set properly"
} }
@ -298,9 +376,28 @@ let editCommonModelTests = testList "EditCommonModel" [
Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Source "HTML" "Source not filled properly"
Expect.equal model.Text "" "Text not filled properly" Expect.equal model.Text "" "Text not filled properly"
Expect.equal model.Template "" "Template not filled properly" Expect.equal model.Template "" "Template not filled properly"
Expect.equal model.MetaNames.Length 1 "MetaNames not filled properly" Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not have been assigned"
Expect.equal model.OpenGraphType "" "OpenGraph type not filled properly"
Expect.equal model.OpenGraphImageUrl "" "OpenGraph image URL not filled properly"
Expect.equal model.OpenGraphImageType "" "OpenGraph image type not filled properly"
Expect.equal model.OpenGraphImageWidth "" "OpenGraph image width not filled properly"
Expect.equal model.OpenGraphImageHeight "" "OpenGraph image height not filled properly"
Expect.equal model.OpenGraphImageAlt "" "OpenGraph image alt text not filled properly"
Expect.equal model.OpenGraphAudioUrl "" "OpenGraph audio URL not filled properly"
Expect.equal model.OpenGraphAudioType "" "OpenGraph audio type not filled properly"
Expect.equal model.OpenGraphDescription "" "OpenGraph description not filled properly"
Expect.equal model.OpenGraphDeterminer "" "OpenGraph determiner not filled properly"
Expect.equal model.OpenGraphLocale "" "OpenGraph locale not filled properly"
Expect.equal model.OpenGraphAlternateLocales "" "OpenGraph alt locales not filled properly"
Expect.equal model.OpenGraphVideoUrl "" "OpenGraph video URL not filled properly"
Expect.equal model.OpenGraphVideoType "" "OpenGraph video type not filled properly"
Expect.equal model.OpenGraphVideoWidth "" "OpenGraph video width not filled properly"
Expect.equal model.OpenGraphVideoHeight "" "OpenGraph video height not filled properly"
Expect.isEmpty model.OpenGraphExtraNames "OpenGraph extra names not filled properly"
Expect.isEmpty model.OpenGraphExtraValues "OpenGraph extra values not filled properly"
Expect.hasLength model.MetaNames 1 "MetaNames not filled properly"
Expect.equal model.MetaNames[0] "" "Meta name 0 not filled properly" Expect.equal model.MetaNames[0] "" "Meta name 0 not filled properly"
Expect.equal model.MetaValues.Length 1 "MetaValues not filled properly" Expect.hasLength model.MetaValues 1 "MetaValues not filled properly"
Expect.equal model.MetaValues[0] "" "Meta value 0 not filled properly" Expect.equal model.MetaValues[0] "" "Meta value 0 not filled properly"
} }
test "succeeds for full post with external chapters" { test "succeeds for full post with external chapters" {
@ -312,12 +409,130 @@ let editCommonModelTests = testList "EditCommonModel" [
Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Source "HTML" "Source not filled properly"
Expect.equal model.Text "<p>A post!</p>" "Text not filled properly" Expect.equal model.Text "<p>A post!</p>" "Text not filled properly"
Expect.equal model.Template "demo" "Template not filled properly" Expect.equal model.Template "demo" "Template not filled properly"
Expect.equal model.MetaNames.Length 1 "MetaNames not filled properly" Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned"
Expect.equal model.OpenGraphType "music.album" "OpenGraph type not filled properly"
Expect.equal model.OpenGraphImageUrl "https://unit.test/it.jpg" "OpenGraph image URL not filled properly"
Expect.equal model.OpenGraphImageType "test/jpg" "OpenGraph image type not filled properly"
Expect.equal model.OpenGraphImageWidth "100" "OpenGraph image width not filled properly"
Expect.equal model.OpenGraphImageHeight "200" "OpenGraph image height not filled properly"
Expect.equal model.OpenGraphImageAlt "it is a jpeg" "OpenGraph image alt text not filled properly"
Expect.equal model.OpenGraphAudioUrl "https://unit.test/that.mp3" "OpenGraph audio URL not filled properly"
Expect.equal model.OpenGraphAudioType "test/mp3" "OpenGraph audio type not filled properly"
Expect.equal model.OpenGraphDescription "Just a post" "OpenGraph description not filled properly"
Expect.equal model.OpenGraphDeterminer "a" "OpenGraph determiner not filled properly"
Expect.equal model.OpenGraphLocale "es-MX" "OpenGraph locale not filled properly"
Expect.equal model.OpenGraphAlternateLocales "es-ES, en-EN" "OpenGraph alt locales not filled properly"
Expect.equal model.OpenGraphVideoUrl "https://unit.test/that.mp4" "OpenGraph video URL not filled properly"
Expect.equal model.OpenGraphVideoType "test/mp4" "OpenGraph video type not filled properly"
Expect.equal model.OpenGraphVideoWidth "50" "OpenGraph video width not filled properly"
Expect.equal model.OpenGraphVideoHeight "60" "OpenGraph video height not filled properly"
Expect.hasLength model.OpenGraphExtraNames 1 "OpenGraph extra names should have had 1 entry"
Expect.equal model.OpenGraphExtraNames[0] "an-other" "OpenGraph extra names not filled properly"
Expect.hasLength model.OpenGraphExtraValues 1 "OpenGraph extra values should have had 1 entry"
Expect.equal model.OpenGraphExtraValues[0] "a-value" "OpenGraph extra values not filled properly"
Expect.hasLength model.MetaNames 1 "MetaNames not filled properly"
Expect.equal model.MetaNames[0] "A Meta" "Meta name 0 not filled properly" Expect.equal model.MetaNames[0] "A Meta" "Meta name 0 not filled properly"
Expect.equal model.MetaValues.Length 1 "MetaValues not filled properly" Expect.hasLength model.MetaValues 1 "MetaValues not filled properly"
Expect.equal model.MetaValues[0] "A Value" "Meta value 0 not filled properly" Expect.equal model.MetaValues[0] "A Value" "Meta value 0 not filled properly"
} }
] ]
testList "ToOpenGraph" [
test "succeeds when OpenGraph properties are not assigned" {
Expect.isNone
(EditCommonModel().ToOpenGraph WebLog.Empty) "No OpenGraph properties should have returned None"
}
test "succeeds when minimal OpenGraph properties are assigned" {
let model = EditCommonModel()
model.AssignOpenGraph <- true
model.OpenGraphType <- string Article
model.OpenGraphImageUrl <- "https://unit.test/img.tiff"
let tryOg = model.ToOpenGraph WebLog.Empty
Expect.isSome tryOg "There should have been a set of OpenGraph properties returned"
let og = tryOg.Value
Expect.equal og.Type Article "OpenGraph type not filled correctly"
Expect.equal og.Image.Url "https://unit.test/img.tiff" "OpenGraph image URL not filled properly"
Expect.isNone og.Image.Type "OpenGraph image type should have been None"
Expect.isNone og.Image.Width "OpenGraph image width should have been None"
Expect.isNone og.Image.Height "OpenGraph image height should have been None"
Expect.isNone og.Image.Alt "OpenGraph image alt text should have been None"
Expect.isNone og.Audio "OpenGraph audio should have been None"
Expect.isNone og.Description "OpenGraph description should have been None"
Expect.isNone og.Determiner "OpenGraph determiner should have been None"
Expect.isNone og.Locale "OpenGraph locale should have been None"
Expect.isNone og.LocaleAlternate "OpenGraph alt locales should have been None"
Expect.isNone og.Video "OpenGraph video should have been None"
Expect.isNone og.Other "OpenGraph other properties should have been None"
}
test "succeeds when all OpenGraph properties are assigned" {
let model = EditCommonModel()
model.AssignOpenGraph <- true
model.OpenGraphType <- string VideoMovie
model.OpenGraphImageUrl <- "https://unit.test/still.jpg"
model.OpenGraphImageType <- "still/jpg"
model.OpenGraphImageWidth <- "17"
model.OpenGraphImageHeight <- "24"
model.OpenGraphImageAlt <- "a still from the film"
model.OpenGraphAudioUrl <- "https://unit.test/movie.mp3"
model.OpenGraphAudioType <- "audio/mp-three"
model.OpenGraphDescription <- "Powerful. Stunning."
model.OpenGraphDeterminer <- "the"
model.OpenGraphLocale <- "en-EN"
model.OpenGraphAlternateLocales <- "es-ES, pt-PT"
model.OpenGraphVideoUrl <- "https://unit.test/movie.avi"
model.OpenGraphVideoType <- "video/outdated"
model.OpenGraphVideoWidth <- "1024"
model.OpenGraphVideoHeight <- "768"
model.OpenGraphExtraNames <- [| "og:duration"; "og:rating" |]
model.OpenGraphExtraValues <- [| "1:30:27"; "G" |]
let tryOg = model.ToOpenGraph WebLog.Empty
Expect.isSome tryOg "There should have been a set of OpenGraph properties returned"
let og = tryOg.Value
Expect.equal og.Type VideoMovie "OpenGraph type not filled correctly"
Expect.equal og.Image.Url "https://unit.test/still.jpg" "OpenGraph image URL not filled properly"
Expect.equal og.Image.Type (Some "still/jpg") "OpenGraph image type not filled properly"
Expect.equal og.Image.Width (Some 17) "OpenGraph image width not filled properly"
Expect.equal og.Image.Height (Some 24) "OpenGraph image height not filled properly"
Expect.equal og.Image.Alt (Some "a still from the film") "OpenGraph image alt text not filled properly"
Expect.isSome og.Audio "OpenGraph audio should have been filled"
Expect.equal og.Audio.Value.Url "https://unit.test/movie.mp3" "OpenGraph audio URL not filled properly"
Expect.equal og.Audio.Value.Type (Some "audio/mp-three") "OpenGraph audio type not filled properly"
Expect.equal og.Description (Some "Powerful. Stunning.") "OpenGraph description not filled properly"
Expect.equal og.Determiner (Some "the") "OpenGraph determiner not filled properly"
Expect.equal og.Locale (Some "en-EN") "OpenGraph locale not filled properly"
Expect.isSome og.LocaleAlternate "OpenGraph alt locales not filled properly"
Expect.hasLength og.LocaleAlternate.Value 2 "There should have been 2 alternate locales"
Expect.equal og.LocaleAlternate.Value [ "es-ES"; "pt-PT" ] "OpenGraph alt locales are incorrect"
Expect.isSome og.Video "OpenGraph video should have been filled"
Expect.equal og.Video.Value.Url "https://unit.test/movie.avi" "OpenGraph video URL not filled properly"
Expect.equal og.Video.Value.Type (Some "video/outdated") "OpenGraph video type not filled properly"
Expect.equal og.Video.Value.Width (Some 1024) "OpenGraph video width not filled properly"
Expect.equal og.Video.Value.Height (Some 768) "OpenGraph video height not filled properly"
Expect.isSome og.Other "OpenGraph other properties should have been filled"
Expect.hasLength og.Other.Value 2 "There should have been 2 extra properties"
Expect.equal
og.Other.Value
[ { Name = "og:duration"; Value = "1:30:27" }; { Name = "og:rating"; Value = "G" } ]
"OpenGraph extra properties not filled properly"
}
test "succeeds when relative URLs are assigned" {
let model = EditCommonModel()
model.AssignOpenGraph <- true
model.OpenGraphType <- string Article
model.OpenGraphImageUrl <- "image.jpg"
model.OpenGraphAudioUrl <- "tunes/sound.ogg"
model.OpenGraphVideoUrl <- "teaser.mp4"
let tryOg = model.ToOpenGraph { WebLog.Empty with UrlBase = "https://test.units/verify" }
Expect.isSome tryOg "There should have been a set of OpenGraph properties returned"
let og = tryOg.Value
Expect.equal og.Image.Url "https://test.units/verify/image.jpg" "OpenGraph image URL not filled properly"
Expect.isSome og.Audio "OpenGraph audio should have been filled"
Expect.equal
og.Audio.Value.Url "https://test.units/verify/tunes/sound.ogg" "OpenGraph audio URL not filled properly"
Expect.isSome og.Video "OpenGraph video should have been filled"
Expect.equal
og.Video.Value.Url "https://test.units/verify/teaser.mp4" "OpenGraph video URL not filled properly"
}
]
] ]
/// Unit tests for the EditCustomFeedModel type /// Unit tests for the EditCustomFeedModel type
@ -514,11 +729,13 @@ let editPageModelTests = testList "EditPageModel" [
let model = EditPageModel.FromPage { Page.Empty with Id = PageId "abc" } let model = EditPageModel.FromPage { Page.Empty with Id = PageId "abc" }
Expect.equal model.Id "abc" "Parent fields not filled properly" Expect.equal model.Id "abc" "Parent fields not filled properly"
Expect.isFalse model.IsShownInPageList "IsShownInPageList should not have been set" Expect.isFalse model.IsShownInPageList "IsShownInPageList should not have been set"
Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not be assigned"
} }
test "succeeds for filled page" { test "succeeds for filled page" {
let model = EditPageModel.FromPage testFullPage let model = EditPageModel.FromPage testFullPage
Expect.equal model.Id "the-page" "Parent fields not filled properly" Expect.equal model.Id "the-page" "Parent fields not filled properly"
Expect.isTrue model.IsShownInPageList "IsShownInPageList should have been set" Expect.isTrue model.IsShownInPageList "IsShownInPageList should have been set"
Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned"
} }
] ]
testList "UpdatePage" [ testList "UpdatePage" [
@ -526,7 +743,7 @@ let editPageModelTests = testList "EditPageModel" [
let model = EditPageModel.FromPage testFullPage let model = EditPageModel.FromPage testFullPage
model.Title <- "Updated Page" model.Title <- "Updated Page"
model.IsShownInPageList <- false model.IsShownInPageList <- false
let page = model.UpdatePage testFullPage (Noda.epoch + Duration.FromHours 4) let page = model.UpdatePage testFullPage WebLog.Empty (Noda.epoch + Duration.FromHours 4)
Expect.equal page.Title "Updated Page" "Title not filled properly" Expect.equal page.Title "Updated Page" "Title not filled properly"
Expect.equal page.Permalink (Permalink "blog/page.html") "Permalink not filled properly" Expect.equal page.Permalink (Permalink "blog/page.html") "Permalink not filled properly"
Expect.isEmpty page.PriorPermalinks "PriorPermalinks should be empty" Expect.isEmpty page.PriorPermalinks "PriorPermalinks should be empty"
@ -534,13 +751,12 @@ let editPageModelTests = testList "EditPageModel" [
Expect.isFalse page.IsInPageList "IsInPageList should have been unset" Expect.isFalse page.IsInPageList "IsInPageList should have been unset"
Expect.equal page.Template (Some "bork") "Template not filled properly" Expect.equal page.Template (Some "bork") "Template not filled properly"
Expect.equal page.Text "<h1 id=\"howdy\">Howdy!</h1>\n" "Text not filled properly" Expect.equal page.Text "<h1 id=\"howdy\">Howdy!</h1>\n" "Text not filled properly"
Expect.equal page.Metadata.Length 2 "There should be 2 metadata items" Expect.equal page.OpenGraph testFullPage.OpenGraph "OpenGraph properties should be unchanged"
let item1 = List.item 0 page.Metadata Expect.hasLength page.Metadata 2 "There should be 2 metadata items"
Expect.equal item1.Name "Test" "Meta item 0 name not filled properly" Expect.equal
Expect.equal item1.Value "me" "Meta item 0 value not filled properly" page.Metadata
let item2 = List.item 1 page.Metadata [ { Name = "Test"; Value = "me" }; { Name = "Two"; Value = "2" } ]
Expect.equal item2.Name "Two" "Meta item 1 name not filled properly" "Metadata not filled properly"
Expect.equal item2.Value "2" "Meta item 1 value not filled properly"
Expect.equal page.Revisions.Length 2 "There should be 2 revisions" Expect.equal page.Revisions.Length 2 "There should be 2 revisions"
let rev1 = List.item 0 page.Revisions let rev1 = List.item 0 page.Revisions
Expect.equal rev1.AsOf (Noda.epoch + Duration.FromHours 1) "Revision 0 as-of not filled properly" Expect.equal rev1.AsOf (Noda.epoch + Duration.FromHours 1) "Revision 0 as-of not filled properly"
@ -558,10 +774,11 @@ let editPageModelTests = testList "EditPageModel" [
model.IsShownInPageList <- false model.IsShownInPageList <- false
model.Source <- "HTML" model.Source <- "HTML"
model.Text <- "<h1>Howdy, partners!</h1>" model.Text <- "<h1>Howdy, partners!</h1>"
model.AssignOpenGraph <- false
model.MetaNames <- [| "banana"; "apple"; "grape" |] model.MetaNames <- [| "banana"; "apple"; "grape" |]
model.MetaValues <- [| "monkey"; "zebra"; "ape" |] model.MetaValues <- [| "monkey"; "zebra"; "ape" |]
let now = Noda.epoch + Duration.FromDays 7 let now = Noda.epoch + Duration.FromDays 7
let page = model.UpdatePage testFullPage now let page = model.UpdatePage testFullPage WebLog.Empty now
Expect.equal page.Title "My Updated Page" "Title not filled properly" Expect.equal page.Title "My Updated Page" "Title not filled properly"
Expect.equal page.Permalink (Permalink "blog/updated.html") "Permalink not filled properly" Expect.equal page.Permalink (Permalink "blog/updated.html") "Permalink not filled properly"
Expect.equal page.PriorPermalinks [ Permalink "blog/page.html" ] "PriorPermalinks not filled properly" Expect.equal page.PriorPermalinks [ Permalink "blog/page.html" ] "PriorPermalinks not filled properly"
@ -569,16 +786,14 @@ let editPageModelTests = testList "EditPageModel" [
Expect.isFalse page.IsInPageList "IsInPageList should not have been set" Expect.isFalse page.IsInPageList "IsInPageList should not have been set"
Expect.isNone page.Template "Template not filled properly" Expect.isNone page.Template "Template not filled properly"
Expect.equal page.Text "<h1>Howdy, partners!</h1>" "Text not filled properly" Expect.equal page.Text "<h1>Howdy, partners!</h1>" "Text not filled properly"
Expect.isNone page.OpenGraph "OpenGraph properties not cleared properly"
Expect.equal page.Metadata.Length 3 "There should be 3 metadata items" Expect.equal page.Metadata.Length 3 "There should be 3 metadata items"
let item1 = List.item 0 page.Metadata Expect.equal
Expect.equal item1.Name "apple" "Meta item 0 name not filled properly" page.Metadata
Expect.equal item1.Value "zebra" "Meta item 0 value not filled properly" [ { Name = "apple"; Value = "zebra" }
let item2 = List.item 1 page.Metadata { Name = "banana"; Value = "monkey" }
Expect.equal item2.Name "banana" "Meta item 1 name not filled properly" { Name = "grape"; Value = "ape" } ]
Expect.equal item2.Value "monkey" "Meta item 1 value not filled properly" "Metadata not filled properly"
let item3 = List.item 2 page.Metadata
Expect.equal item3.Name "grape" "Meta item 2 name not filled properly"
Expect.equal item3.Value "ape" "Meta item 2 value not filled properly"
Expect.equal page.Revisions.Length 3 "There should be 3 revisions" Expect.equal page.Revisions.Length 3 "There should be 3 revisions"
Expect.equal page.Revisions.Head.AsOf now "Head revision as-of not filled properly" Expect.equal page.Revisions.Head.AsOf now "Head revision as-of not filled properly"
Expect.equal Expect.equal
@ -593,6 +808,7 @@ let editPostModelTests = testList "EditPostModel" [
test "succeeds for empty post" { test "succeeds for empty post" {
let model = EditPostModel.FromPost WebLog.Empty { Post.Empty with Id = PostId "la-la-la" } let model = EditPostModel.FromPost WebLog.Empty { Post.Empty with Id = PostId "la-la-la" }
Expect.equal model.Id "la-la-la" "Parent fields not filled properly" Expect.equal model.Id "la-la-la" "Parent fields not filled properly"
Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not be assigned"
Expect.equal model.Tags "" "Tags not filled properly" Expect.equal model.Tags "" "Tags not filled properly"
Expect.isEmpty model.CategoryIds "CategoryIds not filled properly" Expect.isEmpty model.CategoryIds "CategoryIds not filled properly"
Expect.equal model.Status (string Draft) "Status not filled properly" Expect.equal model.Status (string Draft) "Status not filled properly"
@ -624,6 +840,7 @@ let editPostModelTests = testList "EditPostModel" [
test "succeeds for full post with external chapters" { test "succeeds for full post with external chapters" {
let model = EditPostModel.FromPost { WebLog.Empty with TimeZone = "Etc/GMT+1" } testFullPost let model = EditPostModel.FromPost { WebLog.Empty with TimeZone = "Etc/GMT+1" } testFullPost
Expect.equal model.Id "a-post" "Parent fields not filled properly" Expect.equal model.Id "a-post" "Parent fields not filled properly"
Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned"
Expect.equal model.Tags "demo, post" "Tags not filled properly" Expect.equal model.Tags "demo, post" "Tags not filled properly"
Expect.equal model.CategoryIds [| "cat-a"; "cat-b"; "cat-n" |] "CategoryIds not filled properly" Expect.equal model.CategoryIds [| "cat-a"; "cat-b"; "cat-n" |] "CategoryIds not filled properly"
Expect.equal model.Status (string Published) "Status not filled properly" Expect.equal model.Status (string Published) "Status not filled properly"
@ -679,6 +896,7 @@ let editPostModelTests = testList "EditPostModel" [
model.Tags <- "Zebras, Aardvarks, , Turkeys" model.Tags <- "Zebras, Aardvarks, , Turkeys"
model.Template <- "updated" model.Template <- "updated"
model.CategoryIds <- [| "cat-x"; "cat-y" |] model.CategoryIds <- [| "cat-x"; "cat-y" |]
model.AssignOpenGraph <- false
model.MetaNames <- [| "Zed Meta"; "A Meta" |] model.MetaNames <- [| "Zed Meta"; "A Meta" |]
model.MetaValues <- [| "A Value"; "Zed Value" |] model.MetaValues <- [| "A Value"; "Zed Value" |]
model.Media <- "an-updated-ep.mp3" model.Media <- "an-updated-ep.mp3"
@ -701,7 +919,7 @@ let editPostModelTests = testList "EditPostModel" [
model model
testList "UpdatePost" [ testList "UpdatePost" [
test "succeeds for a full podcast episode" { test "succeeds for a full podcast episode" {
let post = (updatedModel ()).UpdatePost testFullPost (Noda.epoch + Duration.FromDays 400) let post = (updatedModel ()).UpdatePost testFullPost WebLog.Empty (Noda.epoch + Duration.FromDays 400)
Expect.equal post.Title "An Updated Post" "Title not filled properly" Expect.equal post.Title "An Updated Post" "Title not filled properly"
Expect.equal post.Permalink (Permalink "1970/01/updated-post.html") "Permalink not filled properly" Expect.equal post.Permalink (Permalink "1970/01/updated-post.html") "Permalink not filled properly"
Expect.equal post.PriorPermalinks [ Permalink "1970/01/a-post.html" ] "PriorPermalinks not filled properly" Expect.equal post.PriorPermalinks [ Permalink "1970/01/a-post.html" ] "PriorPermalinks not filled properly"
@ -711,11 +929,12 @@ let editPostModelTests = testList "EditPostModel" [
Expect.equal post.Tags [ "aardvarks"; "turkeys"; "zebras" ] "Tags not filled properly" Expect.equal post.Tags [ "aardvarks"; "turkeys"; "zebras" ] "Tags not filled properly"
Expect.equal post.Template (Some "updated") "Template not filled properly" Expect.equal post.Template (Some "updated") "Template not filled properly"
Expect.equal post.CategoryIds [ CategoryId "cat-x"; CategoryId "cat-y" ] "Categories not filled properly" Expect.equal post.CategoryIds [ CategoryId "cat-x"; CategoryId "cat-y" ] "Categories not filled properly"
Expect.equal post.Metadata.Length 2 "There should have been 2 meta items" Expect.isNone post.OpenGraph "OpenGraph properties should have been cleared"
Expect.equal post.Metadata[0].Name "A Meta" "Meta item 0 name not filled properly" Expect.hasLength post.Metadata 2 "There should have been 2 meta items"
Expect.equal post.Metadata[0].Value "Zed Value" "Meta item 0 value not filled properly" Expect.equal
Expect.equal post.Metadata[1].Name "Zed Meta" "Meta item 1 name not filled properly" post.Metadata
Expect.equal post.Metadata[1].Value "A Value" "Meta item 1 value not filled properly" [ { Name = "A Meta"; Value = "Zed Value" }; { Name = "Zed Meta"; Value = "A Value" } ]
"Metadata not filled properly"
Expect.equal post.Revisions.Length 3 "There should have been 3 revisions" Expect.equal post.Revisions.Length 3 "There should have been 3 revisions"
Expect.equal Expect.equal
post.Revisions[0].AsOf (Noda.epoch + Duration.FromDays 400) "Revision 0 AsOf not filled properly" post.Revisions[0].AsOf (Noda.epoch + Duration.FromDays 400) "Revision 0 AsOf not filled properly"
@ -761,7 +980,7 @@ let editPostModelTests = testList "EditPostModel" [
minModel.SeasonDescription <- "" minModel.SeasonDescription <- ""
minModel.EpisodeNumber <- "" minModel.EpisodeNumber <- ""
minModel.EpisodeDescription <- "" minModel.EpisodeDescription <- ""
let post = minModel.UpdatePost testFullPost (Noda.epoch + Duration.FromDays 500) let post = minModel.UpdatePost testFullPost WebLog.Empty (Noda.epoch + Duration.FromDays 500)
Expect.isSome post.Episode "There should have been a podcast episode" Expect.isSome post.Episode "There should have been a podcast episode"
let ep = post.Episode.Value let ep = post.Episode.Value
Expect.equal ep.Media "an-updated-ep.mp3" "Media not filled properly" Expect.equal ep.Media "an-updated-ep.mp3" "Media not filled properly"
@ -788,7 +1007,7 @@ let editPostModelTests = testList "EditPostModel" [
minModel.ChapterSource <- "internal" minModel.ChapterSource <- "internal"
minModel.ChapterFile <- "" minModel.ChapterFile <- ""
minModel.ChapterType <- "" minModel.ChapterType <- ""
let post = minModel.UpdatePost testFullPost (Noda.epoch + Duration.FromDays 500) let post = minModel.UpdatePost testFullPost WebLog.Empty (Noda.epoch + Duration.FromDays 500)
Expect.isSome post.Episode "There should have been a podcast episode" Expect.isSome post.Episode "There should have been a podcast episode"
let ep = post.Episode.Value let ep = post.Episode.Value
Expect.equal ep.Chapters (Some []) "Chapters not filled properly" Expect.equal ep.Chapters (Some []) "Chapters not filled properly"
@ -801,6 +1020,7 @@ let editPostModelTests = testList "EditPostModel" [
let post = let post =
minModel.UpdatePost minModel.UpdatePost
{ testFullPost with Episode = Some { testFullPost.Episode.Value with Chapters = Some [] } } { testFullPost with Episode = Some { testFullPost.Episode.Value with Chapters = Some [] } }
WebLog.Empty
(Noda.epoch + Duration.FromDays 500) (Noda.epoch + Duration.FromDays 500)
Expect.isSome post.Episode "There should have been a podcast episode" Expect.isSome post.Episode "There should have been a podcast episode"
let ep = post.Episode.Value let ep = post.Episode.Value
@ -813,14 +1033,15 @@ let editPostModelTests = testList "EditPostModel" [
let model = updatedModel () let model = updatedModel ()
model.IsEpisode <- false model.IsEpisode <- false
model.Template <- "" model.Template <- ""
let post = model.UpdatePost testFullPost Noda.epoch let post = model.UpdatePost testFullPost WebLog.Empty Noda.epoch
Expect.isNone post.Template "Template not filled properly" Expect.isNone post.Template "Template not filled properly"
Expect.isNone post.Episode "Episode not filled properly" Expect.isNone post.Episode "Episode not filled properly"
} }
test "succeeds when publishing a draft" { test "succeeds when publishing a draft" {
let model = updatedModel () let model = updatedModel ()
model.DoPublish <- true model.DoPublish <- true
let post = model.UpdatePost { testFullPost with Status = Draft } (Noda.epoch + Duration.FromDays 375) let post =
model.UpdatePost { testFullPost with Status = Draft } WebLog.Empty (Noda.epoch + Duration.FromDays 375)
Expect.equal post.Status Published "Status not set properly" Expect.equal post.Status Published "Status not set properly"
Expect.equal post.PublishedOn (Some (Noda.epoch + Duration.FromDays 375)) "PublishedOn not set properly" Expect.equal post.PublishedOn (Some (Noda.epoch + Duration.FromDays 375)) "PublishedOn not set properly"
} }

View File

@ -164,7 +164,7 @@ let save : HttpHandler = requireAccess Author >=> fun next ctx -> task {
match! tryPage with match! tryPage with
| Some page when canEdit page.AuthorId ctx -> | Some page when canEdit page.AuthorId ctx ->
let updateList = page.IsInPageList <> model.IsShownInPageList let updateList = page.IsInPageList <> model.IsShownInPageList
let updatedPage = model.UpdatePage page now let updatedPage = model.UpdatePage page ctx.WebLog now
do! (if model.IsNew then data.Page.Add else data.Page.Update) updatedPage do! (if model.IsNew then data.Page.Add else data.Page.Update) updatedPage
if updateList then do! PageListCache.update ctx if updateList then do! PageListCache.update ctx
do! addMessage ctx { UserMessage.Success with Message = "Page saved successfully" } do! addMessage ctx { UserMessage.Success with Message = "Page saved successfully" }

View File

@ -157,7 +157,7 @@ let pageOfTaggedPosts slugAndPage : HttpHandler = fun next ctx -> task {
let webLog = ctx.WebLog let webLog = ctx.WebLog
let data = ctx.Data let data = ctx.Data
match parseSlugAndPage webLog slugAndPage with match parseSlugAndPage webLog slugAndPage with
| Some pageNbr, rawTag, isFeed -> | Some pageNbr, rawTag, isFeed ->
let urlTag = HttpUtility.UrlDecode rawTag let urlTag = HttpUtility.UrlDecode rawTag
let! tag = backgroundTask { let! tag = backgroundTask {
match! data.TagMap.FindByUrlValue urlTag webLog.Id with match! data.TagMap.FindByUrlValue urlTag webLog.Id with
@ -495,7 +495,7 @@ let save : HttpHandler = requireAccess Author >=> fun next ctx -> task {
| Some post when canEdit post.AuthorId ctx -> | Some post when canEdit post.AuthorId ctx ->
let priorCats = post.CategoryIds let priorCats = post.CategoryIds
let updatedPost = let updatedPost =
model.UpdatePost post (Noda.now ()) model.UpdatePost post ctx.WebLog (Noda.now ())
|> function |> function
| post -> | post ->
if model.SetPublished then if model.SetPublished then