@@ -58,6 +58,17 @@ test('that attachWebSocket will add a websocket to the url map', t => {
5858 t . is ( connection . websockets . length , 1 , 'websocket property contains only the websocket object' ) ;
5959} ) ;
6060
61+ test ( 'that attachWebSocket will add a websocket with query params to the url map' , t => {
62+ const resultServer = networkBridge . attachServer ( fakeObject , 'ws://localhost:8080' ) ;
63+ const resultWebSocket = networkBridge . attachWebSocket ( fakeObject , 'ws://localhost:8080?foo=bar' ) ;
64+ const connection = networkBridge . urlMap [ 'ws://localhost:8080' ] ;
65+
66+ t . deepEqual ( resultServer , fakeObject , 'server returned because it was successfully added to the url map' ) ;
67+ t . deepEqual ( resultWebSocket , fakeObject , 'server returned as the websocket was successfully added to the map' ) ;
68+ t . deepEqual ( connection . websockets [ 0 ] , fakeObject , 'fakeObject was added to the websockets array' ) ;
69+ t . is ( connection . websockets . length , 1 , 'websocket property contains only the websocket object' ) ;
70+ } ) ;
71+
6172test ( 'that attachWebSocket will add the same websocket only once' , t => {
6273 const resultServer = networkBridge . attachServer ( fakeObject , 'ws://localhost:8080' ) ;
6374 const resultWebSocket = networkBridge . attachWebSocket ( fakeObject , 'ws://localhost:8080' ) ;
@@ -83,6 +94,18 @@ test('that server and websocket lookups return the correct objects', t => {
8394 t . deepEqual ( websocketLookup . length , 1 , 'the correct number of websockets are returned' ) ;
8495} ) ;
8596
97+ test ( 'that server and websocket lookups ignore query params' , t => {
98+ networkBridge . attachServer ( fakeObject , 'ws://localhost:8080' ) ;
99+ networkBridge . attachWebSocket ( fakeObject , 'ws://localhost:8080?foo=bar' ) ;
100+
101+ const serverLookup = networkBridge . serverLookup ( 'ws://localhost:8080?foo1=1' ) ;
102+ const websocketLookup = networkBridge . websocketsLookup ( 'ws://localhost:8080?foo2=2' ) ;
103+
104+ t . deepEqual ( serverLookup , fakeObject , 'server correctly returned' ) ;
105+ t . deepEqual ( websocketLookup , [ fakeObject ] , 'websockets correctly returned' ) ;
106+ t . deepEqual ( websocketLookup . length , 1 , 'the correct number of websockets are returned' ) ;
107+ } ) ;
108+
86109test ( 'that removing server and websockets works correctly' , t => {
87110 networkBridge . attachServer ( fakeObject , 'ws://localhost:8080' ) ;
88111 networkBridge . attachWebSocket ( fakeObject , 'ws://localhost:8080' ) ;
@@ -99,6 +122,22 @@ test('that removing server and websockets works correctly', t => {
99122 t . deepEqual ( networkBridge . urlMap , { } , 'Url map is back in its default state' ) ;
100123} ) ;
101124
125+ test ( 'that removing server and websockets works correctly with query params' , t => {
126+ networkBridge . attachServer ( fakeObject , 'ws://localhost:8080' ) ;
127+ networkBridge . attachWebSocket ( fakeObject , 'ws://localhost:8080?foo=bar' ) ;
128+
129+ let websocketLookup = networkBridge . websocketsLookup ( 'ws://localhost:8080?anything=else' ) ;
130+ t . deepEqual ( websocketLookup . length , 1 , 'the correct number of websockets are returned' ) ;
131+
132+ networkBridge . removeWebSocket ( fakeObject , 'ws://localhost:8080?arbitraryParameter' ) ;
133+
134+ websocketLookup = networkBridge . websocketsLookup ( 'ws://localhost:8080?one=more' ) ;
135+ t . deepEqual ( websocketLookup . length , 0 , 'the correct number of websockets are returned' ) ;
136+
137+ networkBridge . removeServer ( 'ws://localhost:8080?please' ) ;
138+ t . deepEqual ( networkBridge . urlMap , { } , 'Url map is back in its default state' ) ;
139+ } ) ;
140+
102141test ( 'a socket can join and leave a room' , t => {
103142 const fakeSocket = { url : 'ws://roomy' } ;
104143
@@ -120,3 +159,25 @@ test('a socket can join and leave a room', t => {
120159 inRoom = networkBridge . websocketsLookup ( 'ws://roomy' , 'room' ) ;
121160 t . is ( inRoom . length , 0 , 'there are no sockets in the room after leaving' ) ;
122161} ) ;
162+
163+ test ( 'a socket with query params can join and leave a room' , t => {
164+ const fakeSocket = { url : 'ws://roomy?foo=bar' } ;
165+
166+ networkBridge . attachServer ( fakeObject , 'ws://roomy' ) ;
167+ networkBridge . attachWebSocket ( fakeSocket , 'ws://roomy' ) ;
168+
169+ let inRoom ;
170+ inRoom = networkBridge . websocketsLookup ( 'ws://roomy' , 'room' ) ;
171+ t . is ( inRoom . length , 0 , 'there are no sockets in the room to start with' ) ;
172+
173+ networkBridge . addMembershipToRoom ( fakeSocket , 'room' ) ;
174+
175+ inRoom = networkBridge . websocketsLookup ( 'ws://roomy' , 'room' ) ;
176+ t . is ( inRoom . length , 1 , 'there is 1 socket in the room after joining' ) ;
177+ t . deepEqual ( inRoom [ 0 ] , fakeSocket ) ;
178+
179+ networkBridge . removeMembershipFromRoom ( fakeSocket , 'room' ) ;
180+
181+ inRoom = networkBridge . websocketsLookup ( 'ws://roomy' , 'room' ) ;
182+ t . is ( inRoom . length , 0 , 'there are no sockets in the room after leaving' ) ;
183+ } ) ;
0 commit comments