Skip to content

Commit 8f8a878

Browse files
committed
Finished tests for ping
1 parent ad3d42a commit 8f8a878

24 files changed

+1111
-682
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"extends": "crockford",
66
"env": {
77
"node": true,
8-
"es6": true
8+
"es6": true,
9+
"mocha": true
910
},
1011
"rules": {
1112
"no-underscore-dangle": "off",

DEVNOTES.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Developer Notes
2+
3+
## Can I test pleaseNotify without domain? Docker might not allow.
4+
5+
Please notify verifies a reader differently whether or not there is a domain specified. I need to make sure I test both cases.
6+
7+
## Make sure I test pleaseNotify with multiple urls including where one url fails.
8+
9+
Just because one fails doesn't mean the others aren't good. The response from Dave's server is a pass or fail so I'll stick with that and show a failure even if only one fails. This is probably an edge case.
10+
11+
## If I ping Dave's server with a bad domain I get the following error:
12+
13+
```xml
14+
<?xml version="1.0"?>
15+
<result success="false" msg="Can&apos;t open named stream because TCP/IP error code 11001 - Host not found. (DNS error)." />
16+
```
17+
18+
I should make sure I return the same response if possible.
19+
20+
## Is there a way to create mock a server with https in docker?
21+
22+
I'm adding https-post as an option and would like to make sure to test it.

bin/import-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function doImport() {
3636
subscription.protocol = 'http-post';
3737
return subscription;
3838
})
39-
}
39+
};
4040
return {
4141
replaceOne: {
4242
filter: { _id: id },

controllers/rpc2.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@
3636
parseRpcRequest(req)
3737
.then(request => {
3838
switch (request.methodName) {
39-
case 'rssCloud.hello':
40-
console.log(request.params[0]);
41-
processResponse(req, res, rpcReturnSuccess(true));
42-
break;
43-
case 'rssCloud.pleaseNotify':
44-
const params = parseNotifyParams.rpc(req, request.params);
45-
pleaseNotify(
46-
params.notifyProcedure,
47-
params.apiurl,
48-
params.protocol,
49-
params.urlList,
50-
params.diffDomain
51-
)
52-
.then(result => processResponse(req, res, rpcReturnSuccess(result.success)))
53-
.catch(err => handleError(req, res, err));
54-
break;
55-
case 'rssCloud.ping':
56-
ping(request.params[0])
57-
.then(result => processResponse(req, res, rpcReturnSuccess(result.success)))
58-
.catch(err => handleError(req, res, err));
59-
break;
60-
default:
61-
handleError(
62-
req,
63-
res,
64-
new Error(`Can't make the call because "${request.methodName}" is not defined.`)
65-
)
39+
case 'rssCloud.hello':
40+
console.log(request.params[0]);
41+
processResponse(req, res, rpcReturnSuccess(true));
42+
break;
43+
case 'rssCloud.pleaseNotify':
44+
const params = parseNotifyParams.rpc(req, request.params);
45+
pleaseNotify(
46+
params.notifyProcedure,
47+
params.apiurl,
48+
params.protocol,
49+
params.urlList,
50+
params.diffDomain
51+
)
52+
.then(result => processResponse(req, res, rpcReturnSuccess(result.success)))
53+
.catch(err => handleError(req, res, err));
54+
break;
55+
case 'rssCloud.ping':
56+
ping(request.params[0])
57+
.then(result => processResponse(req, res, rpcReturnSuccess(result.success)))
58+
.catch(err => handleError(req, res, err));
59+
break;
60+
default:
61+
handleError(
62+
req,
63+
res,
64+
new Error(`Can't make the call because "${request.methodName}" is not defined.`)
65+
);
6666
}
6767
})
6868
.catch(err => handleError(req, res, err));

controllers/view-log.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
async function fetchVals(db, callback) {
1111
const vals = {
12-
'eventlog': []
13-
};
12+
'eventlog': []
13+
},
1414

15-
const res = await mongodb.get('rsscloud')
16-
.collection('events')
17-
.find()
18-
.sort({ time: -1 })
19-
.limit(1000)
20-
.toArray();
15+
res = await mongodb.get('rsscloud')
16+
.collection('events')
17+
.find()
18+
.sort({ time: -1 })
19+
.limit(1000)
20+
.toArray();
2121

2222
vals.eventlog = res.map(item => {
2323
item.id = item._id.toHexString();
@@ -46,7 +46,7 @@
4646
}
4747
}
4848

49-
function handleError(req, res, errorMessage) {
49+
function handleError(req, res, err) {
5050
console.error(err);
5151
processResponse(req, res, errorResult(err.message));
5252
}

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
DOMAIN: rsscloud
1818
PORT: 5337
1919
MONGODB_URI: mongodb://mongodb:27017/rsscloud
20+
NODE_TLS_REJECT_UNAUTHORIZED: 0
2021
expose:
2122
- 5337
2223
depends_on:
@@ -32,8 +33,11 @@ services:
3233
MONGODB_URI: mongodb://mongodb:27017/rsscloud
3334
MOCK_SERVER_URL: http://rsscloud-tests:8002
3435
MOCK_SERVER_PORT: 8002
36+
SECURE_MOCK_SERVER_URL: https://rsscloud-tests:8003
37+
SECURE_MOCK_SERVER_PORT: 8003
3538
expose:
3639
- 8002
40+
- 8003
3741
depends_on:
3842
- mongodb
3943
- rsscloud

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"start": "nodemon --use_strict ./app.js",
88
"client": "nodemon --use_strict ./client.js",
99
"import-data": "node ./bin/import-data.js",
10-
"jshint": "echo '=> linting' && jshint ./**/*.js",
11-
"eslint": "echo '=> sniffing' && eslint controllers/ services/",
12-
"test": "mocha --timeout 10000 --bail",
10+
"jshint": "jshint ./**/*.js",
11+
"eslint": "eslint --fix controllers/ services/ test/",
12+
"test": "mocha --timeout 10000",
1313
"test-api": "docker-compose up --build --abort-on-container-exit"
1414
},
1515
"engines": {
@@ -48,6 +48,7 @@
4848
"chai-xml": "^0.3.2",
4949
"eslint": "^7.9.0",
5050
"eslint-config-crockford": "^2.0.0",
51+
"https": "^1.0.0",
5152
"jshint": "^2.12.0",
5253
"mocha": "^8.1.3",
5354
"nodemon": "2.0.4",

services/init-resource.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
function initResource(resource) {
77
const defaultResource = {
8-
flDirty: true,
9-
lastSize: 0,
10-
lastHash: '',
11-
ctChecks: 0,
12-
whenLastCheck: moment.utc('0', 'x').format(),
13-
ctUpdates: 0,
14-
whenLastUpdate: moment.utc('0', 'x').format()
15-
};
8+
flDirty: true,
9+
lastSize: 0,
10+
lastHash: '',
11+
ctChecks: 0,
12+
whenLastCheck: moment.utc('0', 'x').format(),
13+
ctUpdates: 0,
14+
whenLastUpdate: moment.utc('0', 'x').format()
15+
};
1616

1717
return Object.assign({}, defaultResource, resource);
1818
}

services/init-subscription.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
function initSubscription(subscriptions, notifyProcedure, apiurl, protocol) {
88
const defaultSubscription = {
9-
ctUpdates: 0,
10-
whenLastUpdate: moment.utc('0', 'x').format(),
11-
ctErrors: 0,
12-
ctConsecutiveErrors: 0,
13-
whenLastError: moment.utc('0', 'x').format(),
14-
whenExpires: moment().utc().add(config.ctSecsResourceExpire, 'seconds').format(),
15-
url: apiurl,
16-
notifyProcedure,
17-
protocol
18-
};
9+
ctUpdates: 0,
10+
whenLastUpdate: moment.utc('0', 'x').format(),
11+
ctErrors: 0,
12+
ctConsecutiveErrors: 0,
13+
whenLastError: moment.utc('0', 'x').format(),
14+
whenExpires: moment().utc().add(config.ctSecsResourceExpire, 'seconds').format(),
15+
url: apiurl,
16+
notifyProcedure,
17+
protocol
18+
},
1919

20-
const index = subscriptions.pleaseNotify.findIndex(subscription => {
21-
return subscription.url === apiurl;
22-
});
20+
index = subscriptions.pleaseNotify.findIndex(subscription => {
21+
return subscription.url === apiurl;
22+
});
2323

2424
if (-1 === index) {
2525
subscriptions.pleaseNotify.push(defaultSubscription);

0 commit comments

Comments
 (0)