@@ -5,7 +5,8 @@ const chai = require("chai"),
55 SERVER_URL = process . env . APP_URL || "http://localhost:5337" ,
66 mock = require ( "./mock" ) ,
77 mongodb = require ( "./mongodb" ) ,
8- xmlrpc = require ( "davexmlrpc" ) ;
8+ xmlrpc = require ( "davexmlrpc" ) ,
9+ rpcReturnSuccess = require ( '../services/rpc-return-success' ) ;
910
1011chai . use ( chaiHttp ) ;
1112chai . use ( chaiXml ) ;
@@ -33,7 +34,7 @@ function pleaseNotify(pingProtocol, body, returnFormat) {
3334 }
3435}
3536
36- for ( const protocol of [ 'http-post' , 'https-post' ] ) {
37+ for ( const protocol of [ 'http-post' , 'https-post' , 'xml-rpc' ] ) {
3738for ( const returnFormat of [ 'XML' , 'JSON' ] ) {
3839for ( const pingProtocol of [ 'REST' ] ) {
3940
@@ -66,24 +67,28 @@ for (const pingProtocol of ['REST']) {
6667
6768 it ( 'should accept a pleaseNotify for new resource' , async ( ) => {
6869 const feedPath = '/rss.xml' ,
69- pingPath = '/feedupdated' ,
7070 resourceUrl = mock . serverUrl + feedPath ;
7171
72- let body = {
72+ let pingPath = '/feedupdated' ,
73+ notifyProcedure = false ;
74+
75+ if ( 'xml-rpc' === protocol ) {
76+ pingPath = '/RPC2' ;
77+ notifyProcedure = 'river.feedUpdated' ;
78+ }
79+
80+ const body = {
7381 domain : mock . serverDomain ,
74- port : 'http -post' === protocol ? mock . serverPort : mock . secureServerPort ,
82+ port : 'https -post' === protocol ? mock . secureServerPort : mock . serverPort ,
7583 path : pingPath ,
76- notifyProcedure : false ,
84+ notifyProcedure : notifyProcedure ,
7785 protocol,
7886 url1 : resourceUrl
7987 } ;
8088
81- if ( 'xml-rpc' === protocol ) {
82- // body = {}
83- }
84-
8589 mock . route ( 'GET' , feedPath , 200 , '<RSS Feed />' ) ;
8690 mock . route ( 'GET' , pingPath , 200 , ( req ) => { return req . query . challenge ; } ) ;
91+ mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
8792
8893 let res = await pleaseNotify ( pingProtocol , body , returnFormat ) ;
8994
@@ -96,28 +101,39 @@ for (const pingProtocol of ['REST']) {
96101 }
97102
98103 expect ( mock . requests . GET ) . property ( feedPath ) . lengthOf ( 1 , `Missing GET ${ feedPath } ` ) ;
99- expect ( mock . requests . GET ) . property ( pingPath ) . lengthOf ( 1 , `Missing GET ${ pingPath } ` ) ;
104+
105+ if ( 'xml-rpc' === protocol ) {
106+ expect ( mock . requests . RPC2 ) . property ( notifyProcedure ) . lengthOf ( 1 , `Missing XML-RPC call ${ notifyProcedure } ` ) ;
107+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] ) . property ( 'rpcBody' ) ;
108+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] . rpcBody . params [ 0 ] ) . equal ( resourceUrl ) ;
109+ } else {
110+ expect ( mock . requests . GET ) . property ( pingPath ) . lengthOf ( 1 , `Missing GET ${ pingPath } ` ) ;
111+ }
100112 } ) ;
101113
102114 it ( 'should accept a pleaseNotify without domain for new resource' , async ( ) => {
103115 const feedPath = '/rss.xml' ,
104- pingPath = '/feedupdated' ,
105116 resourceUrl = mock . serverUrl + feedPath ;
106117
107- let body = {
108- port : 'http-post' === protocol ? mock . serverPort : mock . secureServerPort ,
118+ let pingPath = '/feedupdated' ,
119+ notifyProcedure = false ;
120+
121+ if ( 'xml-rpc' === protocol ) {
122+ pingPath = '/RPC2' ;
123+ notifyProcedure = 'river.feedUpdated' ;
124+ }
125+
126+ const body = {
127+ port : 'https-post' === protocol ? mock . secureServerPort : mock . serverPort ,
109128 path : pingPath ,
110- notifyProcedure : false ,
129+ notifyProcedure : notifyProcedure ,
111130 protocol,
112131 url1 : resourceUrl
113132 } ;
114133
115- if ( 'xml-rpc' === protocol ) {
116- // body = {}
117- }
118-
119134 mock . route ( 'GET' , feedPath , 200 , '<RSS Feed />' ) ;
120135 mock . route ( 'POST' , pingPath , 200 , 'Thanks for the update! :-)' ) ;
136+ mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
121137
122138 let res = await pleaseNotify ( pingProtocol , body , returnFormat ) ;
123139
@@ -130,87 +146,39 @@ for (const pingProtocol of ['REST']) {
130146 }
131147
132148 expect ( mock . requests . GET ) . property ( feedPath ) . lengthOf ( 1 , `Missing GET ${ feedPath } ` ) ;
133- expect ( mock . requests . POST ) . property ( pingPath ) . lengthOf ( 1 , `Missing POST ${ pingPath } ` ) ;
134- } ) ;
135149
136- // it('should accept a pleaseNotify for new resource and return JSON', async () => {
137- // const feedPath = '/rss.xml',
138- // pingPath = '/feedupdated',
139- // resourceUrl = mock.serverUrl + feedPath,
140- // notifyProcedure = false,
141- // apiurl = ('http-post' === protocol ? mock.serverUrl : mock.secureServerUrl) + pingPath;
142-
143- // mock.route('GET', feedPath, 200, '<RSS Feed />');
144- // mock.route('GET', pingPath, 200, (req) => { return req.query.challenge; });
145-
146- // let res = await chai
147- // .request(SERVER_URL)
148- // .post("/pleaseNotify")
149- // .set('accept', 'application/json')
150- // .set('content-type', 'application/x-www-form-urlencoded')
151- // .send({
152- // domain: 'rsscloud-tests',
153- // port: 8002,
154- // path: pingPath,
155- // notifyProcedure: false,
156- // protocol,
157- // url1: resourceUrl
158- // });
159-
160- // expect(res).status(200);
161- // 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!` });
162- // expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
163- // expect(mock.requests.GET).property(pingPath).lengthOf(1, `Missing GET ${pingPath}`);
164- // });
165-
166- // it('should accept a pleaseNotify without domain for new resource and return JSON', async () => {
167- // const feedPath = '/rss.xml',
168- // pingPath = '/feedupdated',
169- // resourceUrl = mock.serverUrl + feedPath,
170- // notifyProcedure = false,
171- // apiurl = ('http-post' === protocol ? mock.serverUrl : mock.secureServerUrl) + pingPath;
172-
173- // mock.route('GET', feedPath, 200, '<RSS Feed />');
174- // mock.route('POST', pingPath, 200, '');
175-
176- // let res = await chai
177- // .request(SERVER_URL)
178- // .post("/pleaseNotify")
179- // .set('accept', 'application/json')
180- // .set('content-type', 'application/x-www-form-urlencoded')
181- // .send({
182- // port: 8002,
183- // path: pingPath,
184- // notifyProcedure: false,
185- // protocol,
186- // url1: resourceUrl
187- // });
188-
189- // expect(res).status(200);
190- // 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!` });
191- // expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
192- // expect(mock.requests.POST).property(pingPath).lengthOf(1, `Missing POST ${pingPath}`);
193- // });
150+ if ( 'xml-rpc' === protocol ) {
151+ expect ( mock . requests . RPC2 ) . property ( notifyProcedure ) . lengthOf ( 1 , `Missing XML-RPC call ${ notifyProcedure } ` ) ;
152+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] ) . property ( 'rpcBody' ) ;
153+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] . rpcBody . params [ 0 ] ) . equal ( resourceUrl ) ;
154+ } else {
155+ expect ( mock . requests . POST ) . property ( pingPath ) . lengthOf ( 1 , `Missing POST ${ pingPath } ` ) ;
156+ }
157+ } ) ;
194158
195159 it ( 'should reject a pleaseNotify for bad resource' , async ( ) => {
196160 const feedPath = '/rss.xml' ,
197- pingPath = '/feedupdated' ,
198161 resourceUrl = mock . serverUrl + feedPath ;
199162
200- let body = {
201- port : 'http-post' === protocol ? mock . serverPort : mock . secureServerPort ,
163+ let pingPath = '/feedupdated' ,
164+ notifyProcedure = false ;
165+
166+ if ( 'xml-rpc' === protocol ) {
167+ pingPath = '/RPC2' ;
168+ notifyProcedure = 'river.feedUpdated' ;
169+ }
170+
171+ const body = {
172+ port : 'https-post' === protocol ? mock . secureServerPort : mock . serverPort ,
202173 path : pingPath ,
203- notifyProcedure : false ,
174+ notifyProcedure : notifyProcedure ,
204175 protocol,
205176 url1 : resourceUrl
206177 } ;
207178
208- if ( 'xml-rpc' === protocol ) {
209- // body = {}
210- }
211-
212179 mock . route ( 'GET' , feedPath , 404 , 'Not Found' ) ;
213180 mock . route ( 'POST' , pingPath , 200 , 'Thanks for the update! :-)' ) ;
181+ mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
214182
215183 let res = await pleaseNotify ( pingProtocol , body , returnFormat ) ;
216184
@@ -223,7 +191,12 @@ for (const pingProtocol of ['REST']) {
223191 }
224192
225193 expect ( mock . requests . GET ) . property ( feedPath ) . lengthOf ( 1 , `Missing GET ${ feedPath } ` ) ;
226- expect ( mock . requests . POST ) . property ( pingPath ) . lengthOf ( 0 , `Should not POST ${ pingPath } ` ) ;
194+
195+ if ( 'xml-rpc' === protocol ) {
196+ expect ( mock . requests . RPC2 ) . property ( notifyProcedure ) . lengthOf ( 0 , `Should not XML-RPC call ${ notifyProcedure } ` ) ;
197+ } else {
198+ expect ( mock . requests . POST ) . property ( pingPath ) . lengthOf ( 0 , `Should not POST ${ pingPath } ` ) ;
199+ }
227200 } ) ;
228201 } ) ;
229202
0 commit comments