Skip to content

Commit 4381623

Browse files
committed
test(query): add testcase to cover user.EmailWasUpdated case
1 parent 72b0f97 commit 4381623

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

query/scenario_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ func TestScenario(t *testing.T) {
5151
AssertOn(t, makeQueryHandler)
5252
})
5353

54+
t.Run("returns the expected User by its email after it has been changed", func(t *testing.T) {
55+
query.
56+
Scenario[user.GetByEmail, user.View, *user.GetByEmailHandler]().
57+
Given(event.Persisted{
58+
StreamID: event.StreamID(id.String()),
59+
Version: 1,
60+
Envelope: event.ToEnvelope(&user.Event{
61+
ID: id,
62+
RecordTime: before,
63+
Kind: &user.WasCreated{
64+
FirstName: expected.FirstName,
65+
LastName: expected.LastName,
66+
BirthDate: expected.BirthDate,
67+
68+
},
69+
}),
70+
}, event.Persisted{
71+
StreamID: event.StreamID(id.String()),
72+
Version: 2,
73+
Envelope: event.ToEnvelope(&user.Event{
74+
ID: id,
75+
RecordTime: before,
76+
Kind: &user.EmailWasUpdated{
77+
Email: expected.Email,
78+
},
79+
}),
80+
}).
81+
When(query.ToEnvelope(user.GetByEmail(expected.Email))).
82+
Then(expected).
83+
AssertOn(t, makeQueryHandler)
84+
})
85+
5486
t.Run("returns user.ErrNotFound if the requested User does not exist", func(t *testing.T) {
5587
query.
5688
Scenario[user.GetByEmail, user.View, *user.GetByEmailHandler]().

0 commit comments

Comments
 (0)