Test for Smokeball
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0 KiB

  1. # Smokeball JavaScript Coding Challenge
  2. ## System Requirements
  3. The coding challenge requires the following to be installed on your development machine;
  4. * [nodejs](https://nodejs.org/en/download/) version 10 or above.
  5. * A [git](https://git-scm.com/downloads) client.
  6. ## Installation
  7. 1. Fork the `javascript-developer-test` repository to your personal github account.
  8. 2. Clone the `javascript-developer-test` repository from your personal github account onto your development machine.
  9. 3. Open a terminal and `cd` into the root directory of the `javascript-developer-test` repository.
  10. 4. Execute `npm install` in the terminal.
  11. ## Challenge Instructions
  12. Your challenge is to implement the `getArnieQuotes()` function, which is exported from `./src/get-arnie-quotes.js`.
  13. The `getArnieQuotes()` function accepts an array of strings, with each string containing a URL.
  14. The unit tests in `./src/get-arnie-quotes.test.js` will provide pre-defined URLs to the function and test your function's implementation. To run the unit tests, execute `npm test` in the terminal.
  15. The goal is to write an implementation of `getArnieQuotes` that passes all unit tests.
  16. To pass the unit tests, `getArnieQuotes()` must perform the following each URL passed in;
  17. 1. Perform a HTTP GET on the URL
  18. 2. If the HTTP status code of the response is 200, push an object to the results array with a single key `"Arnie Quote"` and the HTTP response body's `message` property as the key's associated value.
  19. 3. If the HTTP status code of the response is not 200, push an object to the results array with a single key `"FAILURE"` and the HTTP response body's `message` property as the key's associated value.
  20. Finally, the `getArnieQuotes()` function must return the overall results array.
  21. Note that in this challenge, the HTTP calls are mocked. You *must* use the provided `httpGet` function to perform your HTTP requests.
  22. ## Tips
  23. * Only modify the `get-arnie-quotes.js` file.
  24. * You may introduce additional internal functions in `get-arnie-quotes.js`
  25. * Exploring all of the code files may provide useful hints.
  26. * We are most impressed with readable code that works.
  27. ## Submission
  28. Once all unit tests pass, push your code upstream then send us the link to the github repo with your solution.
  29. ## Docs
  30. ### `getArnieQuotes(urls)`
  31. ```jsdoc
  32. Executes a HTTP GET request on each of the URLs, transforms each of the HTTP responses according to the challenge instructions and returns the results.
  33. @param {string[]} urls The urls to be requested
  34. @return {Promise} A promise which resolves to a results array.
  35. An example results array:
  36. [
  37. { 'Arnie Quote': 'Some cool quote' },
  38. { 'FAILURE: 'Your request has been terminated' },
  39. ]
  40. ```
  41. ### `httpGet(url)`
  42. ```jsdoc
  43. Executes a faked HTTP GET request on the passed URL.
  44. @param {string} url The url upon which to perform a HTTP GET
  45. @return {Promise} A promise which resolves to a HTTP response.
  46. An example HTTP response:
  47. {
  48. status: 200,
  49. body: "{ 'message': 'Some cool arnie quote' }" // JSON string
  50. }
  51. ```