forked from SaturnFramework/Saturn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinksTests.fs
76 lines (69 loc) · 2.07 KB
/
LinksTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module LinksTests
open Expecto
open Saturn
open Helpers
type LinkType =
| Index
| Add
| WithId
| Edit
with
override x.ToString() =
match x with
| Index -> "Index"
| Add -> "Add"
| WithId -> "WithId"
| Edit -> "Edit"
let getLink typ ctx =
match typ with
| Index -> Links.index ctx
| Add -> Links.add ctx
| _ -> ""
|> Controller.text ctx
let getLinkWithId typ ctx (id: string) =
match typ with
| Index -> Links.index ctx
| Add -> Links.add ctx
| WithId -> Links.withId ctx id
| Edit -> Links.edit ctx id
|> Controller.text ctx
let testController typ = controller {
index (getLink typ)
show (getLinkWithId typ)
add (getLink typ)
edit (getLinkWithId typ)
create (getLink typ)
update (getLinkWithId typ)
patch (getLinkWithId typ)
delete (getLinkWithId typ)
delete_all (getLink typ)
}
let getResponse typ id =
match typ, id with
| Index, _ -> "/"
| Add, _ -> "/add"
| WithId, None -> ""
| WithId, Some id -> "/" + id
| Edit, None -> ""
| Edit, Some id -> "/" + id + "/edit"
[<Tests>]
let linksTests =
[Index; Add; WithId; Edit]
|> List.map (fun typ ->
let ctrl = testController typ
let responseTestCase = responseTestCase ctrl
let response = getResponse typ
let desc = sprintf "Link tests for link type - %s" (typ.ToString())
testList desc [
testCase "index" <| responseTestCase "GET" "/" (response None)
testCase "show" <| responseTestCase "GET" "/1" (response (Some "1"))
testCase "add" <| responseTestCase "GET" "/add" (response None)
testCase "edit" <| responseTestCase "GET" "/1/edit" (response (Some "1"))
testCase "create" <| responseTestCase "POST" "/" (response None)
testCase "update" <| responseTestCase "POST" "/1" (response (Some "1"))
testCase "patch" <| responseTestCase "PATCH" "/1" (response (Some "1"))
testCase "delete" <| responseTestCase "DELETE" "/1" (response (Some "1"))
testCase "delete all" <| responseTestCase "DELETE" "/" (response None)
]
)
|> testList "Links tests"