Skip to content

Commit 12ca5a1

Browse files
committed
Refactor for legibility
1 parent 4424fb0 commit 12ca5a1

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

tests/csapi/txnid_test.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package csapi_tests
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/matrix-org/complement/internal/b"
@@ -38,30 +39,24 @@ func TestTxnInEvent(t *testing.T) {
3839
res := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "event", eventID})
3940
body := client.ParseJSON(t, res)
4041
result := gjson.ParseBytes(body)
41-
if !result.Get("unsigned.transaction_id").Exists() {
42+
unsignedTxnId := result.Get("unsigned.transaction_id")
43+
if !unsignedTxnId.Exists() {
4244
t.Fatalf("Event did not have a 'unsigned.transaction_id' on the GET /rooms/%s/event/%s response", roomID, eventID)
4345
}
4446

45-
txnIdFromResult:= result.Get("unsigned.transaction_id").Str
46-
47-
if txnIdFromResult != txnId {
48-
t.Fatalf("Event did not have a 'unsigned.transaction_id' of %s on GET /rooms/%s/event/%s response. Found %s instead", txnId, eventID, roomID, txnIdFromResult)
49-
}
47+
must.EqualStr(t, unsignedTxnId.Str, txnId, fmt.Sprintf("Event did not have a 'unsigned.transaction_id' on GET /rooms/%s/event/%s response", eventID, roomID))
5048
}
5149

5250

5351
func mustHaveTransactionID(t *testing.T, roomID, eventID, expectedTxnId string) client.SyncCheckOpt {
5452
return client.SyncTimelineHas(roomID, func(r gjson.Result) bool {
5553
if r.Get("event_id").Str == eventID {
56-
if !r.Get("unsigned.transaction_id").Exists() {
54+
unsignedTxnId := r.Get("unsigned.transaction_id")
55+
if !unsignedTxnId.Exists() {
5756
t.Fatalf("Event %s in room %s should have a 'unsigned.transaction_id', but it did not", eventID, roomID)
5857
}
5958

60-
txnIdFromSync := r.Get("unsigned.transaction_id").Str
61-
62-
if txnIdFromSync != expectedTxnId {
63-
t.Fatalf("Event %s in room %s should have a 'unsigned.transaction_id' of %s but found %s", eventID, roomID, expectedTxnId, txnIdFromSync)
64-
}
59+
must.EqualStr(t, unsignedTxnId.Str, expectedTxnId, fmt.Sprintf("Event %s in room %s should have a 'unsigned.transaction_id'", eventID, roomID))
6560

6661
return true
6762
}
@@ -73,8 +68,8 @@ func mustHaveTransactionID(t *testing.T, roomID, eventID, expectedTxnId string)
7368
func mustNotHaveTransactionID(t *testing.T, roomID, eventID string) client.SyncCheckOpt {
7469
return client.SyncTimelineHas(roomID, func(r gjson.Result) bool {
7570
if r.Get("event_id").Str == eventID {
76-
res := r.Get("unsigned.transaction_id")
77-
if res.Exists() {
71+
unsignedTxnId := r.Get("unsigned.transaction_id")
72+
if unsignedTxnId.Exists() {
7873
t.Fatalf("Event %s in room %s should NOT have a 'unsigned.transaction_id', but it did (%s)", eventID, roomID, res.Str)
7974
}
8075

0 commit comments

Comments
 (0)