feat: add limited update
This commit is contained in:
committed by
Steve Chavez
parent
799daa7556
commit
f4becf99ad
@@ -386,3 +386,202 @@ spec = do
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [matchHeaderAbsent hContentType]
|
||||
}
|
||||
|
||||
context "limited update" $ do
|
||||
it "works with the limit query param" $ do
|
||||
get "/limited_update_items"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items?limit=2"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items?order=id"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "updated-item" }
|
||||
, { "id": 2, "name": "updated-item" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
it "works with the limit query param plus a filter" $ do
|
||||
get "/limited_update_items"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items?limit=1&id=gt.2"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items?order=id"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "updated-item" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
it "works with the limit and offset query params" $ do
|
||||
get "/limited_update_items"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items?limit=1&offset=1"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items?order=id"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "updated-item" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
it "works on a table with a composite pk" $ do
|
||||
get "/limited_update_items_cpk"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items_cpk?limit=1&offset=1"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items_cpk?order=id,name"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "updated-item" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items_cpk"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
it "works with views with an inferred pk" $ do
|
||||
get "/limited_update_items_view"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items_view?limit=1&offset=1"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items_view?order=id"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "updated-item" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items_view"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
it "works on a table without a pk" $ do
|
||||
get "/limited_update_items_no_pk"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "item-1" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPatch "/limited_update_items_no_pk?limit=1"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"name": "updated-item"} |]
|
||||
`shouldRespondWith`
|
||||
""
|
||||
{ matchStatus = 204
|
||||
, matchHeaders = [ matchHeaderAbsent hContentType
|
||||
, "Preference-Applied" <:> "tx=commit" ]
|
||||
}
|
||||
|
||||
get "/limited_update_items_no_pk?order=id"
|
||||
`shouldRespondWith`
|
||||
[json|[
|
||||
{ "id": 1, "name": "updated-item" }
|
||||
, { "id": 2, "name": "item-2" }
|
||||
, { "id": 3, "name": "item-3" }
|
||||
]|]
|
||||
|
||||
request methodPost "/rpc/reset_limited_items"
|
||||
[("Prefer", "tx=commit")]
|
||||
[json| {"tbl_name": "limited_update_items_no_pk"} |]
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 204 }
|
||||
|
||||
Reference in New Issue
Block a user