MCPcopy
hub / github.com/tinode/chat / TestRegisterSessionUserSpecifiedInSetMessage

Function TestRegisterSessionUserSpecifiedInSetMessage

server/topic_test.go:1519–1570  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1517}
1518
1519func TestRegisterSessionUserSpecifiedInSetMessage(t *testing.T) {
1520 topicName := "grpTest"
1521 numUsers := 1
1522 helper := TopicTestHelper{}
1523 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
1524 defer helper.tearDown()
1525 if len(helper.topic.sessions) != 0 {
1526 helper.finish()
1527 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
1528 }
1529
1530 uid := helper.uids[0]
1531
1532 s := helper.sessions[0]
1533 join := &ClientComMessage{
1534 Original: topicName,
1535 Sub: &MsgClientSub{
1536 Id: "id456",
1537 Topic: topicName,
1538 Set: &MsgSetQuery{
1539 Sub: &MsgSetSub{
1540 // Specify the user. This should result in an error.
1541 User: "foo",
1542 },
1543 },
1544 },
1545 AsUser: uid.UserId(),
1546 sess: s,
1547 }
1548
1549 helper.topic.registerSession(join)
1550 helper.finish()
1551
1552 // Check for errors from testHubLoop
1553 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1554 t.Fatal(errorMsgs[0].Ctrl.Text)
1555 }
1556
1557 if len(s.subs) != 0 {
1558 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
1559 }
1560 online := helper.topic.perUser[uid].online
1561 if online != 0 {
1562 t.Errorf("Number of online sessions: expected 0, found %d", online)
1563 }
1564 // Session output.
1565 registerSessionVerifyOutputs(t, helper.results[0], []int{http.StatusBadRequest})
1566 // Presence notifications.
1567 if len(helper.hubMessages) != 0 {
1568 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))
1569 }
1570}
1571
1572func TestRegisterSessionInvalidWantStrInSetMessage(t *testing.T) {
1573 topicName := "grpTest"

Callers

nothing calls this directly

Calls 6

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
registerSessionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…