diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index 20f631e..423f190 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -442,6 +442,7 @@ type EditCommonModel() = /// The existing OpenGraph property set member private this.PopulateOpenGraph(og: OpenGraphProperties) = this.AssignOpenGraph <- true + this.OpenGraphType <- string og.Type this.OpenGraphImageUrl <- og.Image.Url this.OpenGraphImageType <- defaultArg og.Image.Type "" this.OpenGraphImageWidth <- defaultArg (og.Image.Width |> Option.map string) "" @@ -748,9 +749,10 @@ type EditPageModel() = /// Update a page with values from this model /// The page to be updated + /// The web log to which this page belongs /// The Instant to use for this particular update /// The page, updated with the values from this model - member this.UpdatePage (page: Page) now = + member this.UpdatePage (page: Page) webLog now = let revision = { AsOf = now; Text = MarkupText.Parse $"{this.Source}: {this.Text}" } // Detect a permalink change, and add the prior one to the prior list match string page.Permalink with @@ -766,6 +768,7 @@ type EditPageModel() = IsInPageList = this.IsShownInPageList Template = match this.Template with "" -> None | tmpl -> Some tmpl Text = revision.Text.AsHtml() + OpenGraph = this.ToOpenGraph webLog Metadata = Seq.zip this.MetaNames this.MetaValues |> Seq.filter (fun it -> fst it > "") |> Seq.map (fun it -> { Name = fst it; Value = snd it }) @@ -905,9 +908,10 @@ type EditPostModel() = /// Update a post with values from the submitted form /// The post which should be updated + /// The web log to which this post belongs /// The Instant to use for this particular update /// The post, updated with the values from this model - 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}" } // Detect a permalink change, and add the prior one to the prior list match string post.Permalink with @@ -931,6 +935,7 @@ type EditPostModel() = Template = match this.Template.Trim() with "" -> None | tmpl -> Some tmpl CategoryIds = this.CategoryIds |> Array.map CategoryId |> List.ofArray Status = if this.DoPublish then Published else post.Status + OpenGraph = this.ToOpenGraph webLog Metadata = Seq.zip this.MetaNames this.MetaValues |> Seq.filter (fun it -> fst it > "") |> Seq.map (fun it -> { Name = fst it; Value = snd it }) diff --git a/src/MyWebLog.Tests/Domain/ViewModelsTests.fs b/src/MyWebLog.Tests/Domain/ViewModelsTests.fs index 0de011b..b2e4a33 100644 --- a/src/MyWebLog.Tests/Domain/ViewModelsTests.fs +++ b/src/MyWebLog.Tests/Domain/ViewModelsTests.fs @@ -206,6 +206,25 @@ let private testFullPage = Revisions = [ { AsOf = Noda.epoch + Duration.FromHours 1; Text = Markdown "# Howdy!" } { AsOf = Noda.epoch; Text = Html "

howdy

" } ] + 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" } ] } /// A full post used to test various models @@ -221,6 +240,25 @@ let testFullPost = Text = "

A post!

" CategoryIds = [ CategoryId "cat-a"; CategoryId "cat-b"; CategoryId "cat-n" ] 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" } ] Revisions = [ { AsOf = Noda.epoch + Duration.FromDays 365; Text = Html "

A post!

" } @@ -266,9 +304,28 @@ let editCommonModelTests = testList "EditCommonModel" [ Expect.equal model.Template "" "Template not filled properly" Expect.equal model.Source "HTML" "Source not filled 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.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" } 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.Source "Markdown" "Source 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[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[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.Text "" "Text 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.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" } 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.Text "

A post!

" "Text 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.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" } ] + 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 @@ -514,11 +729,13 @@ let editPageModelTests = testList "EditPageModel" [ let model = EditPageModel.FromPage { Page.Empty with Id = PageId "abc" } Expect.equal model.Id "abc" "Parent fields not filled properly" 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" { let model = EditPageModel.FromPage testFullPage Expect.equal model.Id "the-page" "Parent fields not filled properly" Expect.isTrue model.IsShownInPageList "IsShownInPageList should have been set" + Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned" } ] testList "UpdatePage" [ @@ -526,7 +743,7 @@ let editPageModelTests = testList "EditPageModel" [ let model = EditPageModel.FromPage testFullPage model.Title <- "Updated Page" 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.Permalink (Permalink "blog/page.html") "Permalink not filled properly" 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.equal page.Template (Some "bork") "Template not filled properly" Expect.equal page.Text "

Howdy!

\n" "Text not filled properly" - Expect.equal page.Metadata.Length 2 "There should be 2 metadata items" - let item1 = List.item 0 page.Metadata - Expect.equal item1.Name "Test" "Meta item 0 name not filled properly" - Expect.equal item1.Value "me" "Meta item 0 value not filled properly" - let item2 = List.item 1 page.Metadata - Expect.equal item2.Name "Two" "Meta item 1 name not filled properly" - Expect.equal item2.Value "2" "Meta item 1 value not filled properly" + Expect.equal page.OpenGraph testFullPage.OpenGraph "OpenGraph properties should be unchanged" + Expect.hasLength page.Metadata 2 "There should be 2 metadata items" + Expect.equal + page.Metadata + [ { Name = "Test"; Value = "me" }; { Name = "Two"; Value = "2" } ] + "Metadata not filled properly" Expect.equal page.Revisions.Length 2 "There should be 2 revisions" let rev1 = List.item 0 page.Revisions 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.Source <- "HTML" model.Text <- "

Howdy, partners!

" + model.AssignOpenGraph <- false model.MetaNames <- [| "banana"; "apple"; "grape" |] model.MetaValues <- [| "monkey"; "zebra"; "ape" |] 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.Permalink (Permalink "blog/updated.html") "Permalink 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.isNone page.Template "Template not filled properly" Expect.equal page.Text "

Howdy, partners!

" "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" - let item1 = List.item 0 page.Metadata - Expect.equal item1.Name "apple" "Meta item 0 name not filled properly" - Expect.equal item1.Value "zebra" "Meta item 0 value not filled properly" - let item2 = List.item 1 page.Metadata - Expect.equal item2.Name "banana" "Meta item 1 name not filled properly" - Expect.equal item2.Value "monkey" "Meta item 1 value 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.Metadata + [ { Name = "apple"; Value = "zebra" } + { Name = "banana"; Value = "monkey" } + { Name = "grape"; Value = "ape" } ] + "Metadata not filled properly" 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 @@ -593,6 +808,7 @@ let editPostModelTests = testList "EditPostModel" [ test "succeeds for empty post" { 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.isFalse model.AssignOpenGraph "OpenGraph properties should not be assigned" Expect.equal model.Tags "" "Tags not filled properly" Expect.isEmpty model.CategoryIds "CategoryIds 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" { let model = EditPostModel.FromPost { WebLog.Empty with TimeZone = "Etc/GMT+1" } testFullPost 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.CategoryIds [| "cat-a"; "cat-b"; "cat-n" |] "CategoryIds 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.Template <- "updated" model.CategoryIds <- [| "cat-x"; "cat-y" |] + model.AssignOpenGraph <- false model.MetaNames <- [| "Zed Meta"; "A Meta" |] model.MetaValues <- [| "A Value"; "Zed Value" |] model.Media <- "an-updated-ep.mp3" @@ -701,7 +919,7 @@ let editPostModelTests = testList "EditPostModel" [ model testList "UpdatePost" [ 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.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" @@ -711,11 +929,12 @@ let editPostModelTests = testList "EditPostModel" [ Expect.equal post.Tags [ "aardvarks"; "turkeys"; "zebras" ] "Tags 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.Metadata.Length 2 "There should have been 2 meta items" - Expect.equal post.Metadata[0].Name "A Meta" "Meta item 0 name not filled properly" - Expect.equal post.Metadata[0].Value "Zed Value" "Meta item 0 value not filled properly" - Expect.equal post.Metadata[1].Name "Zed Meta" "Meta item 1 name not filled properly" - Expect.equal post.Metadata[1].Value "A Value" "Meta item 1 value not filled properly" + Expect.isNone post.OpenGraph "OpenGraph properties should have been cleared" + Expect.hasLength post.Metadata 2 "There should have been 2 meta items" + Expect.equal + post.Metadata + [ { 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[0].AsOf (Noda.epoch + Duration.FromDays 400) "Revision 0 AsOf not filled properly" @@ -761,7 +980,7 @@ let editPostModelTests = testList "EditPostModel" [ minModel.SeasonDescription <- "" minModel.EpisodeNumber <- "" 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" let ep = post.Episode.Value Expect.equal ep.Media "an-updated-ep.mp3" "Media not filled properly" @@ -788,7 +1007,7 @@ let editPostModelTests = testList "EditPostModel" [ minModel.ChapterSource <- "internal" minModel.ChapterFile <- "" 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" let ep = post.Episode.Value Expect.equal ep.Chapters (Some []) "Chapters not filled properly" @@ -801,6 +1020,7 @@ let editPostModelTests = testList "EditPostModel" [ let post = minModel.UpdatePost { testFullPost with Episode = Some { testFullPost.Episode.Value with Chapters = Some [] } } + WebLog.Empty (Noda.epoch + Duration.FromDays 500) Expect.isSome post.Episode "There should have been a podcast episode" let ep = post.Episode.Value @@ -813,14 +1033,15 @@ let editPostModelTests = testList "EditPostModel" [ let model = updatedModel () model.IsEpisode <- false 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.Episode "Episode not filled properly" } test "succeeds when publishing a draft" { let model = updatedModel () 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.PublishedOn (Some (Noda.epoch + Duration.FromDays 375)) "PublishedOn not set properly" } diff --git a/src/MyWebLog/Handlers/Page.fs b/src/MyWebLog/Handlers/Page.fs index 0e47a95..4f47040 100644 --- a/src/MyWebLog/Handlers/Page.fs +++ b/src/MyWebLog/Handlers/Page.fs @@ -164,7 +164,7 @@ let save : HttpHandler = requireAccess Author >=> fun next ctx -> task { match! tryPage with | Some page when canEdit page.AuthorId ctx -> 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 if updateList then do! PageListCache.update ctx do! addMessage ctx { UserMessage.Success with Message = "Page saved successfully" } diff --git a/src/MyWebLog/Handlers/Post.fs b/src/MyWebLog/Handlers/Post.fs index 9d5fb44..fd20dc8 100644 --- a/src/MyWebLog/Handlers/Post.fs +++ b/src/MyWebLog/Handlers/Post.fs @@ -157,7 +157,7 @@ let pageOfTaggedPosts slugAndPage : HttpHandler = fun next ctx -> task { let webLog = ctx.WebLog let data = ctx.Data match parseSlugAndPage webLog slugAndPage with - | Some pageNbr, rawTag, isFeed -> + | Some pageNbr, rawTag, isFeed -> let urlTag = HttpUtility.UrlDecode rawTag let! tag = backgroundTask { 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 -> let priorCats = post.CategoryIds let updatedPost = - model.UpdatePost post (Noda.now ()) + model.UpdatePost post ctx.WebLog (Noda.now ()) |> function | post -> if model.SetPublished then