Skip to content

Commit

Permalink
[CE] fix: add catalog validation error in sync (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
TivonB-AI2 authored May 17, 2024
1 parent a5b800e commit 5585d8c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
12 changes: 7 additions & 5 deletions server/app/models/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ def perform_post_discard_sync
def stream_name_exists?
return if destination.blank?

stream = destination.catalog.find_stream_by_name(stream_name)
return if stream.present?

errors.add(:stream_name,
"Add a valid stream_name associated with destination connector")
catalog = destination&.catalog
if catalog.blank?
errors.add(:catalog, "Catalog is missing")
elsif catalog.find_stream_by_name(stream_name).blank?
errors.add(:stream_name,
"Add a valid stream_name associated with destination connector")
end
end
end
43 changes: 38 additions & 5 deletions server/spec/requests/api/v1/syncs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
let(:connectors) do
[
create(:connector, workspace:, connector_type: "destination", name: "klavio1", connector_name: "Klaviyo"),
create(:connector, workspace:, connector_type: "source", name: "redshift", connector_name: "Redshift")
create(:connector, workspace:, connector_type: "source", name: "redshift", connector_name: "Redshift"),
create(:connector, workspace:, connector_type: "destination", name: "klavio2", connector_name: "Klaviyo"),
create(:connector, workspace:, connector_type: "source", name: "redshift2", connector_name: "Redshift")
]
end

let(:model) do
create(:model, connector: connectors.second, workspace:, name: "model1", query: "SELECT * FROM locations")
end

before do
create(:catalog, connector: connectors.find { |connector| connector.name == "klavio1" }, workspace:)
create(:catalog, connector: connectors.find { |connector| connector.name == "redshift" }, workspace:)
end

let(:model) do
create(:model, connector: connectors.second, workspace:, name: "model1", query: "SELECT * FROM locations")
end

let!(:syncs) do
[
create(:sync, workspace:, model:, source: connectors.second, destination: connectors.first)
Expand Down Expand Up @@ -312,6 +314,37 @@
end
end

describe "POST /api/v1/syncs - Create sync" do
let(:request_body) do
{
sync: {
source_id: connectors.fourth.id,
destination_id: connectors.third.id,
model_id: model.id,
schedule_type: "manual",
configuration: {
"test": "test"
},
sync_interval: 10,
sync_interval_unit: "minutes",
stream_name: "profile",
sync_mode: "full_refresh",
cursor_field: "created_date"
}
}
end

context "when catalog is not present" do
it "creates a new sync and returns failure" do
error_message = "Catalog is missing"
post "/api/v1/syncs", params: request_body.to_json, headers: { "Content-Type": "application/json" }
.merge(auth_headers(user))
result = JSON.parse(response.body)
expect(result["errors"][0]["source"]["catalog"]).to eq(error_message)
end
end
end

describe "DELETE /api/v1/syncs/id" do
context "when it is an unauthenticated user" do
it "returns unauthorized" do
Expand Down

0 comments on commit 5585d8c

Please sign in to comment.