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.

85 lines
3.5 KiB

4 years ago
4 years ago
4 years ago
  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 meets all requirements and passes all unit tests.
  16. ## Requirements
  17. `getArnieQuotes()` must perform the following on every passed in URL
  18. 1. Execute a HTTP GET
  19. 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.
  20. 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.
  21. Finally, the `getArnieQuotes()` function's return value must be a promise that resolves to the overall results array.
  22. Note that for this challenge, the HTTP calls are mocked. You *must* use the provided `httpGet` function to perform your HTTP requests.
  23. ## Tips
  24. * Only modify the `get-arnie-quotes.js` file.
  25. * You may introduce additional internal functions in `get-arnie-quotes.js`
  26. * Exploring all of the code files may provide you with useful hints.
  27. * Not all of the requirements are covered by the unit tests.
  28. * We are most impressed with readable code that works.
  29. * Keep your solution as simple as possible, input validation for `get-arnie-quotes()` is not required.
  30. * Code as if your `get-arnie-quotes()` function may one day be used against a real http implementation.
  31. * Other solutions to this puzzle may be available on github and may be used to give you ideas, however, not all forked solutions are correct.
  32. * Direct plagiarism results in an immediate failure.
  33. ## Submission
  34. Once all unit tests pass, push your code upstream then send us the link to your github repo with your solution. Please do not create a pull request against the source repository.
  35. ## Docs
  36. ### `getArnieQuotes(urls)`
  37. ```jsdoc
  38. 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.
  39. @param {string[]} urls The urls to be requested
  40. @return {Promise} A promise which resolves to a results array.
  41. An example results array:
  42. [
  43. { 'Arnie Quote': 'Some cool quote' },
  44. { 'FAILURE': 'Your request has been terminated' },
  45. ]
  46. ```
  47. ### `httpGet(url)`
  48. ```jsdoc
  49. Executes a faked HTTP GET request on the passed URL.
  50. @param {string} url The url upon which to perform a HTTP GET
  51. @return {Promise} A promise which resolves to a HTTP response.
  52. An example HTTP response:
  53. {
  54. status: 200,
  55. body: "{ 'message': 'Some cool arnie quote' }" // JSON string
  56. }
  57. ```