Skip to content

Commit

Permalink
Add test for creating design docs and executing views.
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Jan 18, 2018
1 parent 819b4b2 commit 1b99250
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Davenport.Fsharp.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ let defaultRecord = {
Baz = 11
}

let viewName = "only-bazs-greater-than-10"

let designDocName = "list"

let defaultDesignDocs =
mapFunction "function (doc) { if (doc.Baz > 10) { emit(doc._id, doc); } }"
|> reduceFunction "_count"
|> view viewName
|> toSeq
|> designDoc designDocName
|> toSeq

let client =
"localhost:5984"
|> database "davenport_net_fsharp"
Expand Down Expand Up @@ -309,4 +321,18 @@ let tests =

Expect.isTrue called "Warning event was not called"
}

testCaseAsync "Creates design docs and gets view results" <| async {
// Make sure the design docs exist
do! createDesignDocs defaultDesignDocs client
// Create at least one doc that would match
let! created = create ({defaultRecord with Baz = 15}) client

printfn "Created id is %s" created.Id

let! viewResult = executeView<int> designDocName viewName None client

Expect.isGreaterThan (Seq.length viewResult) 0 "View should return at least one result"
Expect.isGreaterThanOrEqual (viewResult |> Seq.sumBy (fun d -> d.Value)) 10 "The sum of all doc values should be greater than 10"
}
]

0 comments on commit 1b99250

Please sign in to comment.