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.4 KiB

3 years ago
3 years ago
3 years ago
3 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. * Properly define the `TResult` type.
  26. * You may introduce additional internal functions in `get-arnie-quotes.ts`
  27. * Exploring all of the code files may provide you with useful hints.
  28. * Not all of the requirements are covered by the unit tests.
  29. * We are most impressed with readable code that works.
  30. * Keep your solution as simple as possible, input validation for `get-arnie-quotes()` is not required.
  31. * Other solutions to this puzzle are available on github and can 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. ```