Add framework for post tests
- SQLite is failing on fresh environment - Remove no equality/no comparison on meta/revision - Rename RethinkDB test file
This commit is contained in:
parent
990b72b1ec
commit
78c1c5e68e
@ -314,7 +314,7 @@ type MarkupText =
|
||||
|
||||
|
||||
/// An item of metadata
|
||||
[<CLIMutable; NoComparison; NoEquality>]
|
||||
[<CLIMutable>]
|
||||
type MetaItem = {
|
||||
/// The name of the metadata value
|
||||
Name: string
|
||||
@ -329,7 +329,7 @@ type MetaItem = {
|
||||
|
||||
|
||||
/// A revision of a page or post
|
||||
[<CLIMutable; NoComparison; NoEquality>]
|
||||
[<CLIMutable>]
|
||||
type Revision = {
|
||||
/// When this revision was saved
|
||||
AsOf: Instant
|
||||
|
@ -1,3 +1,6 @@
|
||||
/// <summary>
|
||||
/// Integration tests for <see cref="ICategoryData" /> implementations
|
||||
/// </summary>
|
||||
module CategoryDataTests
|
||||
|
||||
open Expecto
|
||||
|
@ -1,3 +1,6 @@
|
||||
/// <summary>
|
||||
/// Integration tests for <see cref="IPageData" /> implementations
|
||||
/// </summary>
|
||||
module PageDataTests
|
||||
|
||||
open System
|
||||
|
52
src/MyWebLog.Tests/Data/PostDataTests.fs
Normal file
52
src/MyWebLog.Tests/Data/PostDataTests.fs
Normal file
@ -0,0 +1,52 @@
|
||||
/// <summary>
|
||||
/// Integration tests for <see cref="IPostData" /> implementations
|
||||
/// </summary>
|
||||
module PostDataTests
|
||||
|
||||
open Expecto
|
||||
open MyWebLog
|
||||
open MyWebLog.Data
|
||||
open NodaTime
|
||||
|
||||
/// The ID of the root web log
|
||||
let rootId = WebLogId "uSitJEuD3UyzWC9jgOHc8g"
|
||||
|
||||
let ``Add succeeds`` (data: IData) = task {
|
||||
let post =
|
||||
{ Id = PostId "a-new-post"
|
||||
WebLogId = WebLogId "test"
|
||||
AuthorId = WebLogUserId "test-author"
|
||||
Status = Published
|
||||
Title = "A New Test Post"
|
||||
Permalink = Permalink "2020/test-post.html"
|
||||
PublishedOn = Some (Noda.epoch + Duration.FromMinutes 1L)
|
||||
UpdatedOn = Noda.epoch + Duration.FromMinutes 3L
|
||||
Template = Some "fancy"
|
||||
Text = "<p>Test text here"
|
||||
CategoryIds = [ CategoryId "a"; CategoryId "b" ]
|
||||
Tags = [ "x"; "y"; "zed" ]
|
||||
Episode = Some { Episode.Empty with Media = "test-ep.mp3" }
|
||||
Metadata = [ { Name = "Meta"; Value = "Data" } ]
|
||||
PriorPermalinks = [ Permalink "2020/test-post-a.html" ]
|
||||
Revisions = [ { AsOf = Noda.epoch + Duration.FromMinutes 1L; Text = Html "<p>Test text here" } ] }
|
||||
do! data.Post.Add post
|
||||
let! stored = data.Post.FindFullById post.Id post.WebLogId
|
||||
Expect.isSome stored "The added post should have been retrieved"
|
||||
let it = stored.Value
|
||||
Expect.equal it.Id post.Id "ID not saved properly"
|
||||
Expect.equal it.WebLogId post.WebLogId "Web log ID not saved properly"
|
||||
Expect.equal it.AuthorId post.AuthorId "Author ID not saved properly"
|
||||
Expect.equal it.Status post.Status "Status not saved properly"
|
||||
Expect.equal it.Title post.Title "Title not saved properly"
|
||||
Expect.equal it.Permalink post.Permalink "Permalink not saved properly"
|
||||
Expect.equal it.PublishedOn post.PublishedOn "Published On not saved properly"
|
||||
Expect.equal it.UpdatedOn post.UpdatedOn "Updated On not saved properly"
|
||||
Expect.equal it.Template post.Template "Template not saved properly"
|
||||
Expect.equal it.Text post.Text "Text not saved properly"
|
||||
Expect.equal it.CategoryIds post.CategoryIds "Category IDs not saved properly"
|
||||
Expect.equal it.Tags post.Tags "Tags not saved properly"
|
||||
Expect.equal it.Episode post.Episode "Episode not saved properly"
|
||||
Expect.equal it.Metadata post.Metadata "Metadata items not saved properly"
|
||||
Expect.equal it.PriorPermalinks post.PriorPermalinks "Prior permalinks not saved properly"
|
||||
Expect.equal it.Revisions post.Revisions "Revisions not saved properly"
|
||||
}
|
@ -23,19 +23,19 @@ let mkData () =
|
||||
|
||||
/// The host for the PostgreSQL test database (defaults to localhost)
|
||||
let testHost =
|
||||
RethinkDbTests.env "PG_HOST" "localhost"
|
||||
RethinkDbDataTests.env "PG_HOST" "localhost"
|
||||
|
||||
/// The database name for the PostgreSQL test database (defaults to postgres)
|
||||
let testDb =
|
||||
RethinkDbTests.env "PG_DB" "postgres"
|
||||
RethinkDbDataTests.env "PG_DB" "postgres"
|
||||
|
||||
/// The user ID for the PostgreSQL test database (defaults to postgres)
|
||||
let testUser =
|
||||
RethinkDbTests.env "PG_USER" "postgres"
|
||||
RethinkDbDataTests.env "PG_USER" "postgres"
|
||||
|
||||
/// The password for the PostgreSQL test database (defaults to postgres)
|
||||
let testPw =
|
||||
RethinkDbTests.env "PG_PW" "postgres"
|
||||
RethinkDbDataTests.env "PG_PW" "postgres"
|
||||
|
||||
/// Create a fresh environment from the root backup
|
||||
let freshEnvironment () = task {
|
||||
@ -219,6 +219,15 @@ let pageTests = testList "Page" [
|
||||
]
|
||||
]
|
||||
|
||||
/// Integration tests for the Post implementation in PostgreSQL
|
||||
let postTests = testList "Post" [
|
||||
testTask "Add succeeds" {
|
||||
// We'll need the root website categories restored for these tests
|
||||
do! freshEnvironment ()
|
||||
do! PostDataTests.``Add succeeds`` (mkData ())
|
||||
}
|
||||
]
|
||||
|
||||
/// Drop the throwaway PostgreSQL database
|
||||
let environmentCleanUp = test "Clean Up" {
|
||||
if db.IsSome then db.Value.Dispose()
|
||||
@ -230,5 +239,6 @@ let all =
|
||||
[ environmentSetUp
|
||||
categoryTests
|
||||
pageTests
|
||||
postTests
|
||||
environmentCleanUp ]
|
||||
|> testSequenced
|
||||
|
@ -1,4 +1,4 @@
|
||||
module RethinkDbTests
|
||||
module RethinkDbDataTests
|
||||
|
||||
open System
|
||||
open Expecto
|
||||
@ -218,6 +218,15 @@ let pageTests = testList "Page" [
|
||||
]
|
||||
]
|
||||
|
||||
/// Integration tests for the Post implementation in RethinkDB
|
||||
let postTests = testList "Post" [
|
||||
testTask "Add succeeds" {
|
||||
// We'll need the root website categories restored for these tests
|
||||
do! freshEnvironment ()
|
||||
do! PostDataTests.``Add succeeds`` data.Value
|
||||
}
|
||||
]
|
||||
|
||||
/// Drop the throwaway RethinkDB database
|
||||
let environmentCleanUp = testTask "Clean Up" {
|
||||
do! disposeData ()
|
||||
@ -229,5 +238,6 @@ let all =
|
||||
[ environmentSetUp
|
||||
categoryTests
|
||||
pageTests
|
||||
postTests
|
||||
environmentCleanUp ]
|
||||
|> testSequenced
|
@ -14,7 +14,7 @@ let ser = Json.configure (JsonSerializer.CreateDefault())
|
||||
|
||||
/// The test database name
|
||||
let dbName =
|
||||
RethinkDbTests.env "SQLITE_DB" "test-db.db"
|
||||
RethinkDbDataTests.env "SQLITE_DB" "test-db.db"
|
||||
|
||||
/// Create a SQLiteData instance for testing
|
||||
let mkData () =
|
||||
@ -30,13 +30,17 @@ let dispose (data: IData) =
|
||||
let freshEnvironment (data: IData option) = task {
|
||||
let env =
|
||||
match data with
|
||||
| Some d -> d
|
||||
| Some d ->
|
||||
System.Console.WriteLine "Existing data"
|
||||
d
|
||||
| None ->
|
||||
System.Console.WriteLine $"No data; deleting {dbName}"
|
||||
File.Delete dbName
|
||||
mkData ()
|
||||
do! env.StartUp()
|
||||
// This exercises Restore for all implementations; all tests are dependent on it working as expected
|
||||
do! Maintenance.Backup.restoreBackup "root-weblog.json" None false false env
|
||||
return env
|
||||
}
|
||||
|
||||
/// Set up the environment for the SQLite tests
|
||||
@ -284,6 +288,16 @@ let pageTests = testList "Page" [
|
||||
]
|
||||
]
|
||||
|
||||
/// Integration tests for the Post implementation in SQLite
|
||||
let postTests = testList "Post" [
|
||||
testTask "Add succeeds" {
|
||||
// We'll need the root website categories restored for these tests
|
||||
let! data = freshEnvironment None
|
||||
try do! PostDataTests.``Add succeeds`` data
|
||||
finally dispose data
|
||||
}
|
||||
]
|
||||
|
||||
/// Delete the SQLite database
|
||||
let environmentCleanUp = test "Clean Up" {
|
||||
File.Delete dbName
|
||||
@ -296,5 +310,6 @@ let all =
|
||||
[ environmentSetUp
|
||||
categoryTests
|
||||
pageTests
|
||||
postTests
|
||||
environmentCleanUp ]
|
||||
|> testSequenced
|
||||
|
@ -12,7 +12,8 @@
|
||||
<Compile Include="Data\UtilsTests.fs" />
|
||||
<Compile Include="Data\CategoryDataTests.fs" />
|
||||
<Compile Include="Data\PageDataTests.fs" />
|
||||
<Compile Include="Data\RethinkDbTests.fs" />
|
||||
<Compile Include="Data\PostDataTests.fs" />
|
||||
<Compile Include="Data\RethinkDbDataTests.fs" />
|
||||
<Compile Include="Data\SQLiteDataTests.fs" />
|
||||
<Compile Include="Data\PostgresDataTests.fs" />
|
||||
<Compile Include="Program.fs" />
|
||||
|
@ -5,7 +5,7 @@ let allTests = testList "MyWebLog" [
|
||||
testList "Data" [
|
||||
ConvertersTests.all
|
||||
UtilsTests.all
|
||||
RethinkDbTests.all
|
||||
RethinkDbDataTests.all
|
||||
SQLiteDataTests.all
|
||||
PostgresDataTests.all
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user