summaryrefslogtreecommitdiff
path: root/test/chatroom.test
blob: 9be5665e7196db34c5b356b0582cd746dfc8e4d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
test ChatroomSetup:
	# Local chatrooms

	spawn as p1
	with p1:
		send "create-identity Device1 Owner1"

		send "chatroom-create first"
		send "chatroom-create second"

		send "chatroom-list-local"

		expect /chatroom-list-item ([a-z0-9#]+) first sub true/ capture first
		expect /chatroom-list-item [a-z0-9#]+ second sub true/
		local:
			expect /chatroom-list-(.*)/ capture done
			guard (done == "done")

	expect /chatroom-create-done ([a-z0-9#]+) first.*/ from p1 capture first
	expect /chatroom-create-done ([a-z0-9#]+) second.*/ from p1 capture second

	# Send chatrooms to new peers

	spawn as p2
	send "create-identity Device2 Owner2" to p2

	spawn as p3
	send "create-identity Device3 Owner3" to p3

	for p in [ p1, p2, p3 ]:
		with p:
			send "chatroom-watch-local"
			send "start-server"

	for p in [ p2, p3 ]:
		with p:
			expect /chatroom-watched-added [a-z0-9#]+ first sub false/
			expect /chatroom-watched-added [a-z0-9#]+ second sub false/

	# Subscribe and unsubscribe

	with p1:
		send "chatroom-unsubscribe $first"
		expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/

		send "chatroom-subscribe $first"
		expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/

	with p2:
		send "chatroom-list-local"
		expect /chatroom-list-item ([a-z0-9#]+) first sub false/ capture p2_first
		expect /chatroom-list-item ([a-z0-9#]+) second sub false/ capture p2_second
		local:
			expect /chatroom-list-(.*)/ capture done
			guard (done == "done")

		send "chatroom-subscribe $p2_first"
		send "chatroom-subscribe $p2_second"

		expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/
		expect /chatroom-watched-updated [a-z0-9#]+ second sub true .*/

		send "chatroom-unsubscribe $p2_first"
		send "chatroom-unsubscribe $p2_second"

		expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/
		expect /chatroom-watched-updated [a-z0-9#]+ second sub false .*/

	# Create and sync additional chatrooms

	send "chatroom-create third" to p1
	send "chatroom-create fourth" to p2
	send "chatroom-create fifth" to p3

	expect /chatroom-create-done ([a-z0-9#]+) fourth.*/ from p2 capture fourth
	expect /chatroom-create-done ([a-z0-9#]+) fifth.*/ from p3 capture fifth

	for p in [ p1, p2, p3 ]:
		with p:
			expect /chatroom-watched-added [a-z0-9#]+ third sub [a-z]+/
			expect /chatroom-watched-added [a-z0-9#]+ fourth sub [a-z]+/
			expect /chatroom-watched-added [a-z0-9#]+ fifth sub [a-z]+/

	# Update chatroom name

	send "chatroom-set-name $first first2" to p1
	for p in [ p1, p2, p3 ]:
		with p:
			expect /chatroom-watched-updated [a-z0-9#]+ first2.*/

	send "chatroom-set-name $fourth fourth2" to p2
	send "chatroom-set-name $fifth fifth2" to p3
	for p in [ p1, p2, p3 ]:
		with p:
			expect /chatroom-watched-updated [a-z0-9#]+ fourth2.*/
			expect /chatroom-watched-updated [a-z0-9#]+ fifth2.*/


test ChatroomMessages:
	spawn as p1

	send "create-identity Device1 Owner1" to p1

	for p in [ p1 ]:
		with p:
			send "chatroom-watch-local"
			send "start-server"

	send "chatroom-create room" to p1
	expect /chatroom-create-done ([a-z0-9#]+) room.*/ from p1 capture room

	for p in [ p1 ]:
		with p:
			expect /chatroom-watched-added [a-z0-9#]+ room sub [a-z]+/

	send "chatroom-message-send $room message1" to p1
	expect /chatroom-message-new $room from Owner1 text message1/ from p1

	send "chatroom-message-send $room message2" to p1
	local:
		expect /chatroom-message-new $room from Owner1 text (.*)/ from p1 capture msg
		guard (msg == "message2")