Skip to content

Instantly share code, notes, and snippets.

@MykolaGolubyev
Created May 24, 2019 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MykolaGolubyev/69804382e886f0f972577f859e0e6556 to your computer and use it in GitHub Desktop.
Save MykolaGolubyev/69804382e886f0f972577f859e0e6556 to your computer and use it in GitHub Desktop.
def customerPayload = [firstName: "FN", lastName: "LN"]
def customer = createLazyResource("customer") { // lazy resource to be created on the first access
def id = http.post("/customers", customerPayload) {
return id
}
return new Customer(id: id, url: "/customers/${id}") // definition is below
}
scenario("customer create") {
customer.id.should != null // accessing resource for the first time will trigger POST (in this example)
}
scenario("customer read") {
http.get(customer.url) { // convenient re-use of url defined above
body.should == customerPayload
}
}
scenario("customer update") {
def changedLastName = "NLN"
http.put(customer.url, [*:customerPayload, lastName: changedLastName]) {
lastName.should == changedLastName
}
http.get(customer.url) {
lastName.should == changedLastName
}
}
scenario("customer delete") {
http.delete(customer.url) {
statusCode.should == 204
}
http.get(customer.url) {
statusCode.should == 404
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment