Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions match/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ func JSONKeyMissing(forbiddenKey string) JSON {
}
}

// JSONKeyMissing returns a matcher which will check that `forbiddenKey` is not present in the JSON object, or is null.
// `forbiddenKey` can be nested, see https://godoc.org/github.com/tidwall/gjson#Get for details.
func JSONKeyMissingOrNull(forbiddenKey string) JSON {
return func(body gjson.Result) error {
res := body.Get(forbiddenKey)
if res.Exists() && res.Type != gjson.Null {
return fmt.Errorf("key '%s' present and not null", forbiddenKey)
}
return nil
}
}

// JSONKeyTypeEqual returns a matcher which will check that `wantKey` is present and its value is of the type `wantType`.
// `wantKey` can be nested, see https://godoc.org/github.com/tidwall/gjson#Get for details.
func JSONKeyTypeEqual(wantKey string, wantType gjson.Type) JSON {
Expand Down
2 changes: 1 addition & 1 deletion tests/csapi/apidoc_room_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestRoomState(t *testing.T) {
match.JSONKeyPresent("joined"),
match.JSONKeyPresent("joined." + authedClient.UserID),
match.JSONKeyPresent("joined." + authedClient.UserID + ".display_name"),
match.JSONKeyPresent("joined." + authedClient.UserID + ".avatar_url"),
match.JSONKeyMissingOrNull("joined." + authedClient.UserID + ".avatar_url"),
},
})
})
Expand Down