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.

84 lines
3.4 KiB

3 years ago
4 years ago
4 years ago
4 years ago
  1. # Smokeball TypeScript 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 12 or above.
  5. * A [git](https://git-scm.com/downloads) client.
  6. ## Installation
  7. 1. Fork the `ts-test` repository to your personal github account.
  8. 2. Clone the `ts-test` repository from your personal github account onto your development machine.
  9. 3. Open a terminal and `cd` into the root directory of the `ts-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.ts`.
  13. The `getArnieQuotes()` function accepts an array of strings, with each string containing a URL.
  14. The unit tests in `./src/get-arnie-quotes.spec.ts` 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.ts` file.
  25. * You may introduce additional internal functions in `get-arnie-quotes.ts`
  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. * Other solutions to this puzzle are available on github and can be used to give you ideas, however, not all forked solutions are correct.
  31. * Direct plagiarism results in an immediate failure.
  32. ## Submission
  33. 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.
  34. ## Docs
  35. ### `getArnieQuotes(urls)`
  36. ```jsdoc
  37. 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.
  38. @param {string[]} urls The urls to be requested
  39. @return {Promise} A promise which resolves to a results array.
  40. An example results array:
  41. [
  42. { 'Arnie Quote': 'Some cool quote' },
  43. { 'FAILURE': 'Your request has been terminated' },
  44. ]
  45. ```
  46. ### `httpGet(url)`
  47. ```jsdoc
  48. Executes a faked HTTP GET request on the passed URL.
  49. @param {string} url The url upon which to perform a HTTP GET
  50. @return {Promise} A promise which resolves to a HTTP response.
  51. An example HTTP response:
  52. {
  53. status: 200,
  54. body: "{ 'message': 'Some cool arnie quote' }" // JSON string
  55. }
  56. ```