Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
96723e83
Commit
96723e83
authored
May 05, 2021
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing tests for various error paths
I ignored one path that is only used in local development.
parent
ca5b5393
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
8 deletions
+64
-8
streamer.js
src/sidebar/services/streamer.js
+2
-1
streamer-test.js
src/sidebar/services/test/streamer-test.js
+62
-7
No files found.
src/sidebar/services/streamer.js
View file @
96723e83
...
...
@@ -99,6 +99,7 @@ export class StreamerService {
// HTTP status code for HTTP -> WS upgrade requests.
const
websocketHost
=
new
URL
(
settings
.
websocketUrl
).
hostname
;
if
([
'localhost'
,
'127.0.0.1'
].
indexOf
(
websocketHost
)
!==
-
1
)
{
/* istanbul ignore next */
warnOnce
(
'Check that your H service is configured to allow '
+
'WebSocket connections from '
+
...
...
@@ -128,7 +129,7 @@ export class StreamerService {
);
}
}
else
{
warnOnce
(
'
r
eceived unsupported notification'
,
message
.
type
);
warnOnce
(
'
R
eceived unsupported notification'
,
message
.
type
);
}
};
...
...
src/sidebar/services/test/streamer-test.js
View file @
96723e83
...
...
@@ -78,6 +78,7 @@ describe('StreamerService', () => {
let
fakeGroups
;
let
fakeSession
;
let
fakeSettings
;
let
fakeWarnOnce
;
let
activeStreamer
;
function
createDefaultStreamer
()
{
...
...
@@ -92,9 +93,7 @@ describe('StreamerService', () => {
beforeEach
(
function
()
{
fakeAuth
=
{
getAccessToken
:
function
()
{
return
Promise
.
resolve
(
'dummy-access-token'
);
},
getAccessToken
:
sinon
.
stub
().
resolves
(
'dummy-access-token'
),
};
fakeStore
=
fakeReduxStore
(
...
...
@@ -126,7 +125,10 @@ describe('StreamerService', () => {
websocketUrl
:
'ws://example.com/ws'
,
};
fakeWarnOnce
=
sinon
.
stub
();
$imports
.
$mock
({
'../../shared/warn-once'
:
fakeWarnOnce
,
'../websocket'
:
FakeSocket
,
});
});
...
...
@@ -177,7 +179,15 @@ describe('StreamerService', () => {
});
});
describe
(
'#connect()'
,
function
()
{
describe
(
'#connect'
,
function
()
{
beforeEach
(()
=>
{
sinon
.
stub
(
console
,
'error'
);
});
afterEach
(()
=>
{
console
.
error
.
restore
();
});
it
(
'should create a websocket connection'
,
function
()
{
createDefaultStreamer
();
return
activeStreamer
.
connect
().
then
(
function
()
{
...
...
@@ -207,9 +217,7 @@ describe('StreamerService', () => {
});
it
(
'should not include credentials in the URL if the client has no access token'
,
function
()
{
fakeAuth
.
getAccessToken
=
function
()
{
return
Promise
.
resolve
(
null
);
};
fakeAuth
.
getAccessToken
.
resolves
(
null
);
createDefaultStreamer
();
return
activeStreamer
.
connect
().
then
(
function
()
{
...
...
@@ -231,6 +239,15 @@ describe('StreamerService', () => {
assert
.
ok
(
!
fakeWebSocket
.
didClose
);
});
});
it
(
'throws an error if fetching the access token fails'
,
async
()
=>
{
fakeAuth
.
getAccessToken
.
rejects
(
new
Error
(
'Getting token failed'
));
createDefaultStreamer
();
const
connected
=
activeStreamer
.
connect
();
await
assert
.
rejects
(
connected
,
'Getting token failed'
);
});
});
describe
(
'#reconnect()'
,
function
()
{
...
...
@@ -292,6 +309,44 @@ describe('StreamerService', () => {
});
});
it
(
'logs an error if the connection fails'
,
()
=>
{
createDefaultStreamer
();
activeStreamer
.
connect
();
const
event
=
new
ErrorEvent
(
'Something went wrong'
);
fakeWebSocket
.
emit
(
'error'
,
event
);
assert
.
calledWith
(
fakeWarnOnce
,
'Error connecting to H push notification service:'
,
event
);
});
[
null
,
false
].
forEach
(
message
=>
{
it
(
'ignores invalid messages'
,
()
=>
{
createDefaultStreamer
();
activeStreamer
.
connect
();
fakeWebSocket
.
notify
(
message
);
});
});
it
(
'ignores messages with an unknown type'
,
()
=>
{
createDefaultStreamer
();
activeStreamer
.
connect
();
fakeWebSocket
.
notify
({
type
:
'unknown-event'
,
});
assert
.
calledWith
(
fakeWarnOnce
,
'Received unsupported notification'
,
'unknown-event'
);
});
describe
(
'annotation notifications'
,
function
()
{
beforeEach
(
function
()
{
createDefaultStreamer
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment