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.

81 lines
3.3 KiB

4 years ago
4 years ago
4 years ago
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 passes all unit tests.
  16. To pass the unit tests, `getArnieQuotes()` must perform the following on each passed URL
  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 a promise that resolves to the overall results array.
  21. Note that for 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 you with useful hints.
  26. * We are most impressed with readable code that works.
  27. * Keep your solution as simple as possible, input validation for `get-arnie-quotes()` is not required.
  28. * Code as if your `get-arnie-quotes()` function may one day be used against a real http implementation.
  29. ## Submission
  30. 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.
  31. ## Docs
  32. ### `getArnieQuotes(urls)`
  33. ```jsdoc
  34. 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.
  35. @param {string[]} urls The urls to be requested
  36. @return {Promise} A promise which resolves to a results array.
  37. An example results array:
  38. [
  39. { 'Arnie Quote': 'Some cool quote' },
  40. { 'FAILURE: 'Your request has been terminated' },
  41. ]
  42. ```
  43. ### `httpGet(url)`
  44. ```jsdoc
  45. Executes a faked HTTP GET request on the passed URL.
  46. @param {string} url The url upon which to perform a HTTP GET
  47. @return {Promise} A promise which resolves to a HTTP response.
  48. An example HTTP response:
  49. {
  50. status: 200,
  51. body: "{ 'message': 'Some cool arnie quote' }" // JSON string
  52. }
  53. ```