freeCodeCamp / CurriculumExpansion

Creative Commons Attribution Share Alike 4.0 International
313 stars 104 forks source link

Testable API and Microservice Projects: URL Shortener #80

Closed QuincyLarson closed 7 years ago

QuincyLarson commented 7 years ago

We are updating the API and Microservice projects to be testable. Campers will start with a boilerplate specific to each project.

Here some proposed user stories - feel free to expand upon them by replying to this comment, and if you see any that look unnecessary, please say so: (to be added)

Progress:

Em-Ant commented 7 years ago

Links

boilerplate: https://hyperdev.com/#!/project/pastoral-caution working demo: https://hyperdev.com/#!/project/thread-paper

Current user stories

  1. I can pass a URL as a parameter and I will receive a shortened URL in the JSON response.
  2. If I pass an invalid URL that doesn't follow the valid http://www.example.com format, the JSON response will contain an error instead.
  3. When I visit that shortened URL, it will redirect me to my original link..

Proposed Improvements

  1. I can POST a URL to [project_url]/api/shorturl/new and I will receive a shortened URL in the JSON response. Example : {"original_url":"www.google.com","short_url":1}
  2. If I pass an invalid URL that doesn't follow the valid http(s)://www.example.com(/more/routes) format, the JSON response will contain an error like {"error":"invalid URL"}. HINT: to be sure that the submitted url points to a valid site you can use the function dns.lookup(host, cb) from the dns core module.
  3. When I visit the shortened URL, it will redirect me to my original link.
Em-Ant commented 7 years ago

@QuincyLarson should we go with POST ? If we use many boilerplates I can create a form in the main view.

@Greenheart feel free add your thoughts.

Greenheart commented 7 years ago

After reading up on this, I think we should use POST to follow conventions.

@Em-Ant I read the referenced issue. Have you solved how campers should test their API for this project? :)

tisdag 22 november 2016 skrev Emanuele Antonelli notifications@github.com:

@QuincyLarson https://github.com/QuincyLarson should we go with POST ? If we use many boilerplates I can create a form in the main view.

@Greenheart https://github.com/Greenheart feel free add your thoughts.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FreeCodeCamp/CurriculumExpansion/issues/80#issuecomment-262223431, or mute the thread https://github.com/notifications/unsubscribe-auth/AF12Kfm6pPbsHxAmDd395aWKeSe6CDqJks5rAtmCgaJpZM4K3XN3 .

Em-Ant commented 7 years ago

I was thinking to test the redirection using another hyperdev server .

The steps could be :

  1. We add a valid url pointing to the support hyperdev server, having a random string in it. We test that the API response is ok, and we store the short url in a global var (e.g. window.shortUrl)
  2. We use the redirection endpoint with the stored short url. After redirection the support hyperdev server will send back the random string. If we need maximum cheating protection, we could add some kind of encryption performed by the 2nd server.

Check out the last tests on narrow-plane. I implemented a draft version of this process.

Em-Ant commented 7 years ago

@QuincyLarson @BerkeleyTrue if we use the worflow explained above, the 2 steps need to be executed sequentially. Does our system support serial ajax calls (not parallel) ?

QuincyLarson commented 7 years ago

@Em-Ant @BerkeleyTrue said as long as when a request completes, it resolves a promise, these ajax calls can be run serially. Does this answer your question?

Greenheart commented 7 years ago

@Em-Ant Nice idea!

onsdag 23 november 2016 skrev Quincy Larson notifications@github.com:

@Em-Ant https://github.com/Em-Ant @BerkeleyTrue https://github.com/BerkeleyTrue said as long as when a request completes, it resolves a promise, these ajax calls can be run serially. Does this answer your question?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FreeCodeCamp/CurriculumExpansion/issues/80#issuecomment-262430585, or mute the thread https://github.com/notifications/unsubscribe-auth/AF12KaBOWceymDmv-6wFc_HsiGfitfwNks5rA7qXgaJpZM4K3XN3 .

Em-Ant commented 7 years ago

@QuincyLarson if the ajax call can be run serially I think it should be ok. Thanks.

QuincyLarson commented 7 years ago

OK - cool. Please let me know if I can help with anything else. My goal is to keep you all unblocked so you can keep making steady progress with this 🙂

Em-Ant commented 7 years ago

This should be ready to QA.

boilerplate: https://hyperdev.com/#!/project/pastoral-caution working demo: https://hyperdev.com/#!/project/thread-paper

testing with narrow-plane, option MS3-url shortener .

notes :

QuincyLarson commented 7 years ago

Forum thread for QA'ing this is live here: https://forum.freecodecamp.com/t/url-shortener-project-with-testable-user-stories-guinea-pigs-needed/60782

QuincyLarson commented 7 years ago

Thanks for your help everyone! This is being QA'd and discussed.

I'm closing this issue. If anyone wants to discuss these further, please reopen it.