Skip to content

Commit

Permalink
feat(CE): added sentry enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
Raushan Kumar Raman committed Oct 20, 2024
1 parent 357dd4b commit e64e7a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/spec/requests/api/v1/models_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
workspace.workspace_users.first.update(role: viewer_role)
post "/api/v1/models", params: request_body.to_json, headers: { "Content-Type": "application/json" }
.merge(auth_headers(user, workspace_id))
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:unauthorized)
end

Expand Down Expand Up @@ -290,6 +291,7 @@
context "when it is an unauthenticated user for update model" do
it "returns unauthorized" do
put "/api/v1/models/#{models.first.id}"
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:unauthorized)
end
end
Expand Down Expand Up @@ -320,6 +322,7 @@
put "/api/v1/models/#{models.second.id}", params: request_body.to_json,
headers: { "Content-Type": "application/json" }
.merge(auth_headers(user, workspace_id))
expect(Sentry).to have_receive(:capture_exception)
expect(response).to have_http_status(:unprocessable_entity)
end

Expand Down Expand Up @@ -377,6 +380,7 @@
workspace.workspace_users.first.update(role: viewer_role)
put "/api/v1/models/#{models.second.id}", params: request_body.to_json, headers:
{ "Content-Type": "application/json" }.merge(auth_headers(user, workspace_id))
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:unauthorized)
end

Expand All @@ -390,6 +394,7 @@
request_body[:model][:connector_id] = "connector_id_wrong"
put "/api/v1/models/#{models.second.id}", params: request_body.to_json, headers:
{ "Content-Type": "application/json" }.merge(auth_headers(user, workspace_id))
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:bad_request)
end
end
Expand Down
12 changes: 12 additions & 0 deletions server/spec/requests/api/v1/workspaces_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
context "when it is an unauthenticated user" do
it "returns unauthorized" do
get "/api/v1/workspaces/#{workspace.id}"
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:unauthorized)
end
end
Expand Down Expand Up @@ -121,6 +122,14 @@
expect(response_hash.dig(:data, :attributes, :members_count))
.to eq(workspace.users.count)
end

it "return failure and not find id" do
allow(Find).to receive(:call).and_raise(ActiveRecord::RecordNotFound )
get "/api/v1/workspaces/#{1}", headers: auth_header(user, workspace_id)

expect(Sentry).to capture_exception('Workspace not found')
expect(response).to have_http_status(:not_found)
end
end
end

Expand Down Expand Up @@ -181,6 +190,7 @@
post "/api/v1/workspaces", params: request_body.to_json, headers: { "Content-Type": "application/json" }
.merge(auth_headers(user, workspace_id))
expect(response).to have_http_status(:bad_request)
expect(Sentry).to capture_exception('Unauthorized access')
end
end
end
Expand All @@ -200,6 +210,7 @@
context "when it is an unauthenticated user for update workspace" do
it "returns unauthorized" do
put "/api/v1/workspaces/#{workspace.id}"
expect(Sentry).to capture_exception('Unauthorized access')
expect(response).to have_http_status(:unauthorized)
end
end
Expand Down Expand Up @@ -244,6 +255,7 @@
request_body[:workspace][:organization_id] = "organization_id_wrong"
put "/api/v1/workspaces/#{workspace.id}", params: request_body.to_json, headers:
{ "Content-Type": "application/json" }.merge(auth_headers(user, workspace_id))
expect(Sentry).to have_received(:capture_exception)
expect(response).to have_http_status(:bad_request)
end
end
Expand Down

0 comments on commit e64e7a0

Please sign in to comment.