Skip to content

Commit

Permalink
Project nil fields instead of noop (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosestito committed Apr 27, 2022
1 parent 9703f85 commit e80b7b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
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

0 comments on commit e80b7b3

Please sign in to comment.