Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix System Replication nil values projection #446

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defmodule Trento.DatabaseInstanceReadModel do
field :https_port, :integer
field :start_priority, :string
field :host_id, Ecto.UUID, primary_key: true
field :system_replication, :string
field :system_replication_status, :string
field :system_replication, :string, default: ""
field :system_replication_status, :string, default: ""
field :health, Ecto.Enum, values: [:passing, :warning, :critical, :unknown]

has_one :host, HostReadModel, references: :host_id, foreign_key: :id
Expand Down
34 changes: 33 additions & 1 deletion test/trento/application/projectors/database_projector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Trento.DatabaseProjectorTest do
instance_number: instance_number,
host_id: host_id,
system_replication: "Primary",
system_replication_status: "ACTIVE"
system_replication_status: "Active"
}

ProjectorTestHelper.project(DatabaseProjector, event, "database_projector")
Expand All @@ -99,4 +99,36 @@ defmodule Trento.DatabaseProjectorTest do
assert event.system_replication == projection.system_replication
assert event.system_replication_status == projection.system_replication_status
end

test "should update the system replication when DatabaseInstanceSystemReplicationChanged with nil values is received" do
%{
sap_system_id: sap_system_id,
instance_number: instance_number,
host_id: host_id
} =
database_instance_projection_without_host(
system_replication: "Secondary",
system_replication_status: ""
)

event = %DatabaseInstanceSystemReplicationChanged{
sap_system_id: sap_system_id,
instance_number: instance_number,
host_id: host_id,
system_replication: nil,
system_replication_status: nil
}

ProjectorTestHelper.project(DatabaseProjector, event, "database_projector")

projection =
Repo.get_by!(DatabaseInstanceReadModel,
sap_system_id: sap_system_id,
instance_number: instance_number,
host_id: host_id
)

assert nil == projection.system_replication
assert nil == projection.system_replication_status
end
end