Skip to content

Commit b1641be

Browse files
committed
chore: tests
1 parent 03d981c commit b1641be

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎test/support/temporal/domain.ex‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ defmodule AshPostgres.Test.Temporal.Domain do
77
use Ash.Domain, validate_config_inclusion?: false
88

99
resources do
10-
resource(AshPostgres.Test.Temporal.Subscription)
10+
resource AshPostgres.Test.Temporal.Subscription do
11+
define(:add_seat_if_basic, action: :add_seat_if_basic, get_by: [:id])
12+
end
1113
resource(AshPostgres.Test.Temporal.Tier)
1214
resource(AshPostgres.Test.Temporal.Event)
1315
resource(AshPostgres.Test.Temporal.Member)

‎test/temporal_test.exs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,30 @@ defmodule AshPostgres.TemporalTest do
720720
] = seats_timeline(1)
721721
end
722722

723+
test "an atomic update through an exists at the current instant leaves later versions alone" do
724+
TestRepo.query!("""
725+
INSERT INTO subscription (id, tier, seats, valid_at) VALUES
726+
(2, 'now', 1, tstzrange(now() - interval '1 day', now() + interval '1 day', '[)')),
727+
(2, 'later', 9, tstzrange(now() + interval '1 day', NULL, '[)'))
728+
""")
729+
730+
Subscription
731+
|> Ash.Query.filter(id == 2)
732+
|> Ash.bulk_update!(:add_seat_if_basic, %{}, strategy: :atomic)
733+
734+
assert [["now", 1, _], ["now", 1, _], ["later", 9, _]] = seats_timeline(2)
735+
end
736+
737+
test "an atomic update through an exists, by code interface, applies only to the version valid at as_of" do
738+
AshPostgres.Test.Temporal.Domain.add_seat_if_basic!(1, as_of: @jan15)
739+
740+
assert [
741+
["bronze", 3, ~U[2026-01-01 00:00:00.000000Z]],
742+
["bronze", 4, ~U[2026-01-15 00:00:00.000000Z]],
743+
["gold", 5, ~U[2026-02-01 00:00:00.000000Z]]
744+
] = seats_timeline(1)
745+
end
746+
723747
test "an atomic update whose range spans two stored versions carves both" do
724748
[bronze] =
725749
Subscription

0 commit comments

Comments
 (0)