Skip to content

Commit

Permalink
Merge pull request #869 from strukturag/test-join-room-error
Browse files Browse the repository at this point in the history
Add testcase when joining unknown room.
  • Loading branch information
fancycode authored Nov 21, 2024
2 parents 8037c3b + 08c67e0 commit 180efaa
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
if request.Room.Action == "leave" && request.Room.UserId == "test-userid1" {
assert.Fail("Should not receive \"leave\" event for first user, received %+v", request.Room)
}
case "test-invalid-room":
response := &BackendClientResponse{
Type: "error",
Error: &Error{
Code: "no_such_room",
Message: "The user is not invited to this room.",
},
}
return response
}

if strings.Contains(t.Name(), "Federation") {
Expand Down Expand Up @@ -2800,6 +2809,46 @@ func TestJoinRoom(t *testing.T) {
require.Equal("", roomMsg.Room.RoomId)
}

func TestJoinInvalidRoom(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
require := require.New(t)
assert := assert.New(t)
hub, _, _, server := CreateHubForTest(t)

client := NewTestClient(t, server, hub)
defer client.CloseWithBye()

require.NoError(client.SendHello(testDefaultUserId))

ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

hello, err := client.RunUntilHello(ctx)
require.NoError(err)

// Join room by id.
roomId := "test-invalid-room"
msg := &ClientMessage{
Id: "ABCD",
Type: "room",
Room: &RoomClientMessage{
RoomId: roomId,
SessionId: roomId + "-" + hello.Hello.SessionId,
},
}
require.NoError(client.WriteJSON(msg))

message, err := client.RunUntilMessage(ctx)
require.NoError(err)
require.NoError(checkUnexpectedClose(err))

assert.Equal(msg.Id, message.Id)
if assert.NoError(checkMessageType(message, "error")) {
assert.Equal("no_such_room", message.Error.Code)
}
}

func TestJoinRoomTwice(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
Expand Down

0 comments on commit 180efaa

Please sign in to comment.