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

Function TestRegisterSessionAsChanUserNotChanSubcriber

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

Source from the content-addressed store, hash-verified

1841}
1842
1843func TestRegisterSessionAsChanUserNotChanSubcriber(t *testing.T) {
1844 topicName := "grpTest"
1845 chanName := "chnTest"
1846 numUsers := 1
1847 helper := TopicTestHelper{}
1848 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
1849 // The topic is a channel.
1850 helper.topic.isChan = true
1851 defer helper.tearDown()
1852 if len(helper.topic.sessions) != 0 {
1853 helper.finish()
1854 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
1855 }
1856
1857 s := helper.sessions[0]
1858 uid := helper.uids[0]
1859 r := helper.results[0]
1860
1861 // User is not a channel subscriber (userData.isChan is false).
1862 join := &ClientComMessage{
1863 Original: chanName,
1864 Sub: &MsgClientSub{
1865 Id: "id456",
1866 Topic: chanName,
1867 },
1868 AsUser: uid.UserId(),
1869 AuthLvl: int(auth.LevelAuth),
1870 sess: s,
1871 }
1872
1873 helper.topic.registerSession(join)
1874 helper.finish()
1875
1876 // Check for errors from testHubLoop
1877 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1878 t.Fatal(errorMsgs[0].Ctrl.Text)
1879 }
1880
1881 if len(s.subs) != 0 {
1882 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
1883 }
1884 online := helper.topic.perUser[uid].online
1885 if online != 0 {
1886 t.Errorf("Number of online sessions: expected 0, found %d", online)
1887 }
1888 // Session output. Tell the subscriber to use non-channel name.
1889 registerSessionVerifyOutputs(t, r, []int{http.StatusSeeOther})
1890 // Presence notifications.
1891 if len(helper.hubMessages) != 0 {
1892 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))
1893 }
1894}
1895
1896func TestRegisterSessionOwnerBansHimself(t *testing.T) {
1897 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…