1
1
package csapi_tests
2
2
3
3
import (
4
+ "fmt"
4
5
"testing"
5
6
6
7
"github.com/matrix-org/complement/internal/b"
@@ -38,30 +39,24 @@ func TestTxnInEvent(t *testing.T) {
38
39
res := c .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "v3" , "rooms" , roomID , "event" , eventID })
39
40
body := client .ParseJSON (t , res )
40
41
result := gjson .ParseBytes (body )
41
- if ! result .Get ("unsigned.transaction_id" ).Exists () {
42
+ unsignedTxnId := result .Get ("unsigned.transaction_id" )
43
+ if ! unsignedTxnId .Exists () {
42
44
t .Fatalf ("Event did not have a 'unsigned.transaction_id' on the GET /rooms/%s/event/%s response" , roomID , eventID )
43
45
}
44
46
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 ))
50
48
}
51
49
52
50
53
51
func mustHaveTransactionID (t * testing.T , roomID , eventID , expectedTxnId string ) client.SyncCheckOpt {
54
52
return client .SyncTimelineHas (roomID , func (r gjson.Result ) bool {
55
53
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 () {
57
56
t .Fatalf ("Event %s in room %s should have a 'unsigned.transaction_id', but it did not" , eventID , roomID )
58
57
}
59
58
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 ))
65
60
66
61
return true
67
62
}
@@ -73,8 +68,8 @@ func mustHaveTransactionID(t *testing.T, roomID, eventID, expectedTxnId string)
73
68
func mustNotHaveTransactionID (t * testing.T , roomID , eventID string ) client.SyncCheckOpt {
74
69
return client .SyncTimelineHas (roomID , func (r gjson.Result ) bool {
75
70
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 () {
78
73
t .Fatalf ("Event %s in room %s should NOT have a 'unsigned.transaction_id', but it did (%s)" , eventID , roomID , res .Str )
79
74
}
80
75
0 commit comments