43
43
{ matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ] }
44
44
45
45
context " when updating rows" $ do
46
-
47
46
it " works for one row" $ do
48
47
_ <- post " /addresses" [json | { id: 97, address: "A Street" } |]
49
48
request methodPatch
@@ -56,26 +55,26 @@ spec =
56
55
it " raises an error for multiple rows" $ do
57
56
_ <- post " /addresses" [json | { id: 98, address: "xxx" } |]
58
57
_ <- post " /addresses" [json | { id: 99, address: "yyy" } |]
59
- p <- request methodPatch
60
- " /addresses?id=gt.0"
61
- [(" Prefer" , " return=representation" ), singular]
62
- [json | { address: "zzz" } |]
58
+ p <- request methodPatch " /addresses?id=gt.0"
59
+ [(" Prefer" , " return=representation" ), singular]
60
+ [json | { address: "zzz" } |]
63
61
liftIO $ do
64
62
simpleStatus p `shouldBe` notAcceptable406
65
63
isErrorFormat (simpleBody p) `shouldBe` True
66
64
67
65
-- the rows should not be updated, either
68
66
get " /addresses?id=eq.98" `shouldRespondWith` [str |[{"id":98,"address":"xxx"}]|]
69
67
70
- it " raises an error for zero rows" $ do
71
- p <- request methodPatch " /items?id=gt.0&id=lt.0"
72
- [(" Prefer" , " return=representation" ), singular] [json |{"id":1}|]
73
- liftIO $ do
74
- simpleStatus p `shouldBe` notAcceptable406
75
- isErrorFormat (simpleBody p) `shouldBe` True
68
+ it " raises an error for zero rows" $
69
+ request methodPatch " /items?id=gt.0&id=lt.0"
70
+ [(" Prefer" , " return=representation" ), singular] [json |{"id":1}|]
71
+ `shouldRespondWith`
72
+ [str |{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
73
+ { matchStatus = 406
74
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
75
+ }
76
76
77
77
context " when creating rows" $ do
78
-
79
78
it " works for one row" $ do
80
79
p <- request methodPost
81
80
" /addresses"
@@ -117,17 +116,17 @@ spec =
117
116
, matchHeaders = [" Content-Range" <:> " */*" ]
118
117
}
119
118
120
- it " raises an error when creating zero entities" $ do
121
- p <- request methodPost
122
- " /addresses"
123
- [(" Prefer" , " return=representation" ), singular]
124
- [json | [ ] |]
125
- liftIO $ do
126
- simpleStatus p `shouldBe` notAcceptable406
127
- isErrorFormat (simpleBody p) `shouldBe` True
119
+ it " raises an error when creating zero entities" $
120
+ request methodPost " /addresses"
121
+ [(" Prefer" , " return=representation" ), singular]
122
+ [json | [ ] |]
123
+ `shouldRespondWith`
124
+ [str |{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
125
+ { matchStatus = 406
126
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
127
+ }
128
128
129
129
context " when deleting rows" $ do
130
-
131
130
it " works for one row" $ do
132
131
p <- request methodDelete
133
132
" /items?id=eq.11"
@@ -146,21 +145,24 @@ spec =
146
145
, matchHeaders = [" Content-Range" <:> " 0-9/*" ]
147
146
}
148
147
149
- it " raises an error when deleting zero entities" $ do
150
- p <- request methodDelete " /items?id=lt.0"
151
- [(" Prefer" , " return=representation" ), singular] " "
152
- liftIO $ do
153
- simpleStatus p `shouldBe` notAcceptable406
154
- isErrorFormat (simpleBody p) `shouldBe` True
148
+ it " raises an error when deleting zero entities" $
149
+ request methodDelete " /items?id=lt.0"
150
+ [(" Prefer" , " return=representation" ), singular] " "
151
+ `shouldRespondWith`
152
+ [str |{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
153
+ { matchStatus = 406
154
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
155
+ }
155
156
156
157
context " when calling a stored proc" $ do
157
-
158
- it " fails for zero rows" $ do
159
- p <- request methodPost " /rpc/getproject"
160
- [singular] [json |{ "id": 9999999}|]
161
- liftIO $ do
162
- simpleStatus p `shouldBe` notAcceptable406
163
- isErrorFormat (simpleBody p) `shouldBe` True
158
+ it " fails for zero rows" $
159
+ request methodPost " /rpc/getproject"
160
+ [singular] [json |{ "id": 9999999}|]
161
+ `shouldRespondWith`
162
+ [str |{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
163
+ { matchStatus = 406
164
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
165
+ }
164
166
165
167
-- this one may be controversial, should vnd.pgrst.object include
166
168
-- the likes of 2 and "hello?"
@@ -174,20 +176,26 @@ spec =
174
176
[singular] [json |{ "id": 1}|] `shouldRespondWith`
175
177
[str |{"id":1,"name":"Windows 7","client_id":1}|]
176
178
177
- it " fails for multiple rows" $ do
178
- p <- request methodPost " /rpc/getallprojects" [singular] " {}"
179
- liftIO $ do
180
- simpleStatus p `shouldBe` notAcceptable406
181
- isErrorFormat (simpleBody p) `shouldBe` True
179
+ it " fails for multiple rows" $
180
+ request methodPost " /rpc/getallprojects"
181
+ [singular] " {}"
182
+ `shouldRespondWith`
183
+ [str |{"details":"Results contain 5 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
184
+ { matchStatus = 406
185
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
186
+ }
182
187
183
188
it " executes the proc exactly once per request" $ do
184
189
request methodPost " /rpc/getproject?select=id,name" [] [json | {"id": 1} |]
185
190
`shouldRespondWith` [str |[{"id":1,"name":"Windows 7"}]|]
186
- p <- request methodPost " /rpc/setprojects" [singular]
187
- [json | {"id_l": 1, "id_h": 2, "name": "changed"} |]
188
- liftIO $ do
189
- simpleStatus p `shouldBe` notAcceptable406
190
- isErrorFormat (simpleBody p) `shouldBe` True
191
+
192
+ request methodPost " /rpc/setprojects" [singular]
193
+ [json | {"id_l": 1, "id_h": 2, "name": "changed"} |]
194
+ `shouldRespondWith`
195
+ [str |{"details":"Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned"}|]
196
+ { matchStatus = 406
197
+ , matchHeaders = [" Content-Type" <:> " application/vnd.pgrst.object+json; charset=utf-8" ]
198
+ }
191
199
192
200
-- should not actually have executed the function
193
201
request methodPost " /rpc/getproject?select=id,name" [] [json | {"id": 1} |]
0 commit comments