Skip to content

Commit

Permalink
Add activity errors endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kevbuchanan authored and Naren Chainani committed Mar 31, 2016
1 parent 7098582 commit 7ace034
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/backbeat/web/events_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def validate(params, param, type, message)
find_node
end

get "/:id/errors" do
find_node.status_changes.where(to_status: :errored)
end

put "/:id/status/:new_status" do
node = find_node
node.touch!
Expand Down
30 changes: 30 additions & 0 deletions spec/integration/backbeat/web/events_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,34 @@
expect(node.reload.current_server_status).to eq("deactivated")
end
end

context "GET /events/:id/errors" do
it "returns all status changes to an errored state" do
node.status_changes.create({
from_status: "ready",
to_status: "errored",
status_type: "current_server_status",
response: { error: { message: "Whoops" } }
})
node.status_changes.create({
from_status: "pending",
to_status: "ready",
status_type: "current_server_status",
response: { result: "Done" }
})
node.status_changes.create({
from_status: "sent_to_client",
to_status: "errored",
status_type: "current_client_status",
response: { error: { message: "An error" } }
})

response = get "/v2/events/#{node.id}/errors"
body = JSON.parse(response.body)

expect(body.count).to eq(2)
expect(body.first["response"]["error"]["message"]).to eq("Whoops")
expect(body.second["response"]["error"]["message"]).to eq("An error")
end
end
end

0 comments on commit 7ace034

Please sign in to comment.