Skip to content

Commit a2500ca

Browse files
committed
Finished initial tests
1 parent 0f0b4d3 commit a2500ca

File tree

3 files changed

+71
-29
lines changed

3 files changed

+71
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# rssCloud Server
22

3-
[![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/andrewshell/rsscloud-server/blob/2.x/LICENSE.md)
4-
[![rssCloud Server 2.x](https://circleci.com/gh/andrewshell/rsscloud-server/tree/2.x.svg?style=shield)](https://circleci.com/gh/andrewshell/rsscloud-server/tree/2.x)
3+
[![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/rsscloud/rsscloud-server/blob/2.x/LICENSE.md)
4+
[![rssCloud Server 2.x](https://circleci.com/gh/rsscloud/rsscloud-server/tree/2.x.svg?style=shield)](https://circleci.com/gh/rsscloud/rsscloud-server/tree/2.x)
55
[![Andrew Shell's Weblog](https://img.shields.io/badge/weblog-rssCloud-brightgreen)](https://blog.andrewshell.org/search/?keywords=rsscloud)
66

77
rssCloud Server implementation in Node.js
88

99
## How to install
1010

1111
```bash
12-
git clone https://github.com/andrewshell/rsscloud-server.git
12+
git clone https://github.com/rsscloud/rsscloud-server.git
1313
cd rsscloud-server
1414
npm install
1515
npm start

controllers/rpc2.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
}
2626

2727
function handleError(req, res, err) {
28-
console.error(err);
29-
// processResponse(req, res, rpcReturnFault(1, err.message));
30-
31-
// Dave's rssCloud server always returns true whether it succeeded or not
32-
processResponse(req, res, rpcReturnSuccess(true));
28+
// console.error(err);
29+
processResponse(req, res, rpcReturnFault(4, err.message));
3330
}
3431

3532
router.post('/', textParser, function (req, res) {
@@ -53,9 +50,10 @@
5350
.catch(err => handleError(req, res, err));
5451
break;
5552
case 'rssCloud.ping':
53+
// Dave's rssCloud server always returns true whether it succeeded or not
5654
ping(request.params[0])
5755
.then(result => processResponse(req, res, rpcReturnSuccess(result.success)))
58-
.catch(err => handleError(req, res, err));
56+
.catch(err => processResponse(req, res, rpcReturnSuccess(true)));
5957
break;
6058
default:
6159
handleError(

test/please-notify.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ const chai = require("chai"),
66
mock = require("./mock"),
77
mongodb = require("./mongodb"),
88
xmlrpc = require("davexmlrpc"),
9-
rpcReturnSuccess = require('../services/rpc-return-success');
9+
rpcReturnSuccess = require('../services/rpc-return-success'),
10+
rpcReturnFault = require('../services/rpc-return-fault');
1011

1112
chai.use(chaiHttp);
1213
chai.use(chaiXml);
1314

1415
function pleaseNotify(pingProtocol, body, returnFormat) {
1516
if ('XML-RPC' === pingProtocol) {
16-
// const rpctext = xmlrpc.buildCall('rssCloud.ping', [resourceUrl], 'xml');
17+
const rpctext = xmlrpc.buildCall('rssCloud.pleaseNotify', body, 'xml');
1718

18-
// return chai
19-
// .request(SERVER_URL)
20-
// .post("/RPC2")
21-
// .set('content-type', 'text/xml')
22-
// .send(rpctext);
19+
return chai
20+
.request(SERVER_URL)
21+
.post("/RPC2")
22+
.set('content-type', 'text/xml')
23+
.send(rpctext);
2324
} else {
2425
let req = chai
2526
.request(SERVER_URL)
@@ -36,7 +37,7 @@ function pleaseNotify(pingProtocol, body, returnFormat) {
3637

3738
for (const protocol of ['http-post', 'https-post', 'xml-rpc']) {
3839
for (const returnFormat of ['XML', 'JSON']) {
39-
for (const pingProtocol of ['REST']) {
40+
for (const pingProtocol of ['XML-RPC', 'REST']) {
4041

4142
if ('XML-RPC' === pingProtocol && 'JSON' === returnFormat) {
4243
// Not Applicable
@@ -77,7 +78,7 @@ for (const pingProtocol of ['REST']) {
7778
notifyProcedure = 'river.feedUpdated';
7879
}
7980

80-
const body = {
81+
let body = {
8182
domain: mock.serverDomain,
8283
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
8384
path: pingPath,
@@ -86,6 +87,17 @@ for (const pingProtocol of ['REST']) {
8687
url1: resourceUrl
8788
};
8889

90+
if ('XML-RPC' === pingProtocol) {
91+
body = [
92+
notifyProcedure,
93+
'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
94+
pingPath,
95+
protocol,
96+
[resourceUrl],
97+
mock.serverDomain
98+
];
99+
}
100+
89101
mock.route('GET', feedPath, 200, '<RSS Feed />');
90102
mock.route('GET', pingPath, 200, (req) => { return req.query.challenge; });
91103
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
@@ -94,10 +106,14 @@ for (const pingProtocol of ['REST']) {
94106

95107
expect(res).status(200);
96108

97-
if ('JSON' === returnFormat) {
98-
expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
109+
if ('XML-RPC' === pingProtocol) {
110+
expect(res.text).xml.equal(rpcReturnSuccess(true));
99111
} else {
100-
expect(res.text).xml.equal('<notifyResult success="true" msg="Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!"/>');
112+
if ('JSON' === returnFormat) {
113+
expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
114+
} else {
115+
expect(res.text).xml.equal('<notifyResult success="true" msg="Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!"/>');
116+
}
101117
}
102118

103119
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
@@ -123,14 +139,24 @@ for (const pingProtocol of ['REST']) {
123139
notifyProcedure = 'river.feedUpdated';
124140
}
125141

126-
const body = {
142+
let body = {
127143
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
128144
path: pingPath,
129145
notifyProcedure: notifyProcedure,
130146
protocol,
131147
url1: resourceUrl
132148
};
133149

150+
if ('XML-RPC' === pingProtocol) {
151+
body = [
152+
notifyProcedure,
153+
'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
154+
pingPath,
155+
protocol,
156+
[resourceUrl]
157+
];
158+
}
159+
134160
mock.route('GET', feedPath, 200, '<RSS Feed />');
135161
mock.route('POST', pingPath, 200, 'Thanks for the update! :-)');
136162
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
@@ -139,10 +165,14 @@ for (const pingProtocol of ['REST']) {
139165

140166
expect(res).status(200);
141167

142-
if ('JSON' === returnFormat) {
143-
expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
168+
if ('XML-RPC' === pingProtocol) {
169+
expect(res.text).xml.equal(rpcReturnSuccess(true));
144170
} else {
145-
expect(res.text).xml.equal('<notifyResult success="true" msg="Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!"/>');
171+
if ('JSON' === returnFormat) {
172+
expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
173+
} else {
174+
expect(res.text).xml.equal('<notifyResult success="true" msg="Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!"/>');
175+
}
146176
}
147177

148178
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
@@ -168,14 +198,24 @@ for (const pingProtocol of ['REST']) {
168198
notifyProcedure = 'river.feedUpdated';
169199
}
170200

171-
const body = {
201+
let body = {
172202
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
173203
path: pingPath,
174204
notifyProcedure: notifyProcedure,
175205
protocol,
176206
url1: resourceUrl
177207
};
178208

209+
if ('XML-RPC' === pingProtocol) {
210+
body = [
211+
notifyProcedure,
212+
'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
213+
pingPath,
214+
protocol,
215+
[resourceUrl]
216+
];
217+
}
218+
179219
mock.route('GET', feedPath, 404, 'Not Found');
180220
mock.route('POST', pingPath, 200, 'Thanks for the update! :-)');
181221
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
@@ -184,10 +224,14 @@ for (const pingProtocol of ['REST']) {
184224

185225
expect(res).status(200);
186226

187-
if ('JSON' === returnFormat) {
188-
expect(res.body).deep.equal({ success: false, msg: `The subscription was cancelled because there was an error reading the resource at URL ${resourceUrl}.` });
227+
if ('XML-RPC' === pingProtocol) {
228+
expect(res.text).xml.equal(rpcReturnFault(4, `The subscription was cancelled because there was an error reading the resource at URL ${resourceUrl}.`));
189229
} else {
190-
expect(res.text).xml.equal(`<notifyResult success="false" msg="The subscription was cancelled because there was an error reading the resource at URL ${resourceUrl}."/>`);
230+
if ('JSON' === returnFormat) {
231+
expect(res.body).deep.equal({ success: false, msg: `The subscription was cancelled because there was an error reading the resource at URL ${resourceUrl}.` });
232+
} else {
233+
expect(res.text).xml.equal(`<notifyResult success="false" msg="The subscription was cancelled because there was an error reading the resource at URL ${resourceUrl}."/>`);
234+
}
191235
}
192236

193237
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);

0 commit comments

Comments
 (0)