BradleyHubbs / web-sprint-challenge-authentication-and-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authentication and Testing Sprint Challenge

Read these instructions carefully. Understand exactly what is expected before starting this Sprint Challenge.

This challenge allows you to practice the concepts and techniques learned over the past sprint and apply them in a concrete project. This sprint explored Authentication and Testing. During this sprint, you studied authentication, JSON web tokens, unit testing, and backend testing. In your challenge this week, you will demonstrate your mastery of these skills by creating a dad jokes app.

This is an individual assessment. All work must be your own. All projects will be submitted to Codegrade for automated review. You will also be given feedback by code reviewers on Monday following the challenge submission. For more information on the review process click here.

You are not allowed to collaborate during the sprint challenge. However, you are encouraged to follow the twenty-minute rule and seek support by dropping a đź‘‹ in your help channel should a blocker arise.

Sprint challenges open at Midnight PST on Thursday and close at 5pm PST on Friday. You will receive feedback on what you have submitted by 5pm. No retakes will be accepted.

Introduction

Dad jokes are all the rage these days! In this challenge, you will build a real wise-guy application.

Users must be able to call the [POST] /api/auth/register endpoint to create a new account, and the [POST] /api/auth/login endpoint to get a token.

We also need to make sure nobody without the token can call [GET] /api/jokes and gain access to our dad jokes.

We will hash the user's password using bcryptjs, and use JSON Web Tokens and the jsonwebtoken library.

Instructions

Task 1: Project Set Up

  • Fork and clone the repo. Delete your old fork from Github first if you are repeating this Unit.
  • Open the assignment in Canvas and click on the "Set up git" option.
  • Follow instructions to set up Codegrade's Webhook and Deploy Key.
  • Push your first commit: git commit --allow-empty -m "first commit" && git push.
  • Check to see that Codegrade has accepted your git submission.

For a step-by-step on setting up Codegrade see this guide.

Task 2: Project Requirements

Your finished project must include all of the following requirements (further instructions are found inside each file):

  • An authentication workflow with functionality for account creation and login, implemented inside api/auth/auth-router.js.
  • Middleware used to restrict access to resources from non-authenticated requests, implemented inside api/middleware/restricted.js.
  • A minimum of 2 tests per API endpoint, written inside api/server.test.js.

Notes:

  • Execute all tests locally (Codegrade's and your own) by running npm test.
  • Do not exceed 2^8 rounds of hashing with bcryptjs.
  • If you use environment variables make sure to provide fallbacks in the code (e.g. process.env.SECRET || "shh").
  • You are welcome to create additional files but do not move or rename existing files or folders.
  • Do not alter your package.json file except to install extra libraries. The "test" script has been added for you.
  • The database already has the users table, but if you run into issues, the migration is available.
  • In your solution, it is essential that you follow best practices and produce clean and professional results.
  • Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work.
  • It is better to submit a challenge that meets MVP than one that attempts too much and does not.

Task 3: Stretch Goals

IMPORTANT: Don't break MVP by working on stretch goals! Run npm test and keep an eye on your tests.

These goals may or may not be things you have learned in this module but they build on the material you just studied. Time allowing, stretch your limits and see if you can deliver on the following optional goals:

  • Write at least 4 tests per endpoint.
  • Extract user validation into a separate method and write unit tests for it.
  • Implement authentication using sessions instead of tokens. Build separate auth endpoints & middleware for this to avoid breaking tests.

Submission format

  • Submit via Codegrade by committing and pushing any new changes.
  • Create a pull request to merge <firstName-lastName> branch into main.
  • Please don't merge your own pull request and make sure you are on your own repo.
  • Check Codegrade for automated feedback.
  • Check Codegrade on Monday following the Sprint Challenge for reviewer feedback.
  • Any changes pushed after the deadline will not receive any feedback.

Interview Questions

Be prepared to demonstrate your understanding of this week's concepts by answering questions on the following topics.

  1. Differences between using sessions or JSON Web Tokens for authentication.
  2. What does bcryptjs do to help us store passwords in a secure manner?
  3. How are unit tests different from integration and end-to-end testing?
  4. How does Test Driven Development change the way we write applications and tests?

About


Languages

Language:JavaScript 100.0%