rabbah commented on a change in pull request #227:
URL: 
https://github.com/apache/openwhisk-client-js/pull/227#discussion_r728934325



##########
File path: test/unit/client.test.js
##########
@@ -22,18 +22,60 @@ const Client = require('../../lib/client')
 const http = require('http')
 const nock = require('nock')
 
-// Note: this has to come before any of the proxy tests, as they interfere
+// Note: All client.request tests have to come before any of the proxy tests, 
as they interfere
+
+test('should return response', async t => {
+  const client = new Client({ api_key: 'secret', apihost: 'test_host', proxy: 
'' })
+  const METHOD = 'GET'
+  const PATH = '/some/path'
+
+  const interceptor = nock('https://test_host').get(PATH).times(1).reply(200, 
'all good')
+  const result = await client.request(METHOD, PATH, {})
+  t.is(result.toString(), 'all good')
+  nock.removeInterceptor(interceptor)
+})
+
 test('should handle http request errors', async t => {
   const client = new Client({ api_key: 'secret', apihost: 'test_host', proxy: 
'' })
   const METHOD = 'GET'
   const PATH = '/some/path'
 
-  nock('https://test_host').get(PATH).replyWithError('simulated error')
+  const interceptor = 
nock('https://test_host').get(PATH).times(1).replyWithError('simulated error')
   const error = await t.throwsAsync(client.request(METHOD, PATH, {}))
   t.truthy(error.message)
   t.assert(error.message.includes('simulated error'))
+  nock.removeInterceptor(interceptor)
 })
 
+test('should support retries on error', async t => {
+  const client = new Client({ api_key: 'secret', apihost: 'test_host', proxy: 
'', retry: { retries: 2 } })
+  const METHOD = 'GET'
+  const PATH = '/some/path'
+
+  const interceptor = nock('https://test_host')
+    .get(PATH).times(2).replyWithError('simulated error')
+    .get(PATH).times(1).reply(200, 'now all good')

Review comment:
       To confirm my understanding of `times(2)`, the path will respond with 
the provided value `2 times` before the next mocked response?
   
   (Alternatively, is there a way to confirm the retry actually was called with 
another test assertion (passing a function to `retry` for a callback) to 
confirm both the function was called as in this case and later that it is not 
called when no retry is specified.)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to