Skip to content

Testing

HeribertoGalvezGarcia edited this page May 29, 2020 · 6 revisions

Auth Router

Tests /api/auth.

auth-router_login.spec.js

Tests POST /api/auth/login.

Returns correct body

Tests that the endpoint returns a token on success.

Return 400 if wrong credentials

Tests that the endpoint returns a 400 status code when invalid credentials are given.

auth-router_register.spec.js

Tests POST /api/auth/register.

Adds user to database and returns user

Tests that the user is successfully added to the database and that the user information is returned.

Return 409 on duplicate

Tests that a 409 status code is returned when a user with the given email already exists.

Company Model

Tests company database model.

companies-model_add_company.spec.js

Tests addCompany().

Adds company

Tests that a company is properly added to the database.

companies-model_find_all_companies.spec.js

Tests findCompanies().

Gets all companies

Tests that all companies are properly returned.

companies-model_find_company_by_id.spec.js

Tests findCompaniesById().

Returns company when found

Tests that company is returned when one exists.

Returns null when no company found

Tests that null is returned when company not found.

companies-model_find_company_reviews.spec.js

Tests findCompanyReviews().

Gets company reviews

Tests that the company's reviews are returned.

companies-model_update_company.spec.js

Tests updateCompany().

Update company

Tests that a company is successfully updated.

Company Router

Tests /api/companies.

companies-router_add_new_company.spec.js

Tests POST /api/companies.

Returns correct body

Tests that the company is returned when successfully added.

companies-router_find_all_companies.spec.js

Tests GET /api/companies.

Returns correct body

Tests that all companies are returned in the body.

companies-router_find_company_by_id.spec.js

Tests GET /api/companies/:companyId.

Return correct body

Tests that the company is returned in the body.

Middleware

Tests middleware.

middleware_checkForAdmin.spec.js

Tests checkForAdmin middleware.

Should return 403 if not admin

Tests that the middleware returns 403 if the user isn't an admin.

Should not return 403 if admin

Tests that the middleware doesn't return 403 if the user is an admin.

middleware_checkForCompanyData.spec.js

Tests checkForCompanyData middleware.

Return 400 if required field is missing

Tests that the middleware returns 400 if a missing field is missing.

Return 400 if body is empty

Tests that the middleware returns 400 if the body is empty.

middleware_checlForLoginData.spec.js

Tests checkForLoginData middleware.

Return 400 if required field is missing

Tests that the middleware returns 400 if a missing field is missing.

Return 400 if body is empty

Tests that the middleware returns 400 if the body is empty.

middleware_checkForRegisterData.spec.js

Tests checkForRegisterData middleware.

Return 400 if required field is missing

Tests that the middleware returns 400 if a missing field is missing.

Return 400 if body is empty

Tests that the middleware returns 400 if the body is empty.

middleware_checkForReviewData.spec.js

Tests checkForReviewData middleware.

Return 400 if required field is missing

Tests that the middleware returns 400 if a missing field is missing.

Return 400 if body is empty

Tests that the middleware returns 400 if the body is empty.

middleware_restricted.spec.js

Tests restricted middleware.

Token is needed for endpoints

Tests that a token is required for endpoints.

middleware_validateCompanyById

Tests validateCompanyById middleware.

Should 404 error if the company doesn't exist

Tests that the middleware returns 404 if the company doesn't exist.

middleware_validateReviewId

Tests validateReviewId middleware.

Should 404 error if the review doesn't exist

Tests that the middleware returns 404 if the review doesn't exist.

middleware_validateUserById.spec.js

Tests validateUserById middlware.

Should 404 if user doesn't exist

Tests that the middleware returns 404 if the user doesn't exist.

Review Model

Tests review database model.

reviews-model_add_review.spec.js

Tests addReview().

Adds review

Tests that a review is properly added to the database.

reviews-model_delete_review.spec.js

Tests deleteReview().

Deletes review

Tests that the review is properly deleted from the database.

reviews-model_find_review_by_id.spec.js

Tests findReviewById().

Returns review when review found

Tests that the review is returned when found.

Returns null when no review found

Tests that null is returned when no review found.

reviews-model_update_review.spec.js

Tests updateReview().

Updates review

Tests that a review is successfully updated.

Review Router

Tests /api/reviews

reviews-router_find_all_reviews.spec.js

Tests GET /api/reviews.

Returns correct body

Tests that all reviews are returned.

reviews-router_find_review_by_id.spec.js

Tests GET /api/reviews/:reviewId.

Return correct body

Tests that the proper review is returned.

User Model

Tests user database model.

users-model_add_user.spec.js

Tests addUser().

New user gets added to database

Tests that user is properly added to the database.

Returns result of findUserById

Tests that addUser returns the result of findUserById.

Adding duplicate user causes errors

Tests that a duplicate user cannot be created.

users-model_find_user_by_id.spec.js

Tests findUserById().

Returns user when user found

Tests that the user is return when user exists.

Returns null when no user found

Tests that null is return when user doesn't exist.

UserRouter

Tests /api/users.

users-router_add_review.spec.js

Tests POST /api/users/:userId/add-review.

Returns correct body

Tests that the endpoint returns the review created.

users-router_bind_user.spec.js

Tests PUT /api/users/:userId/bind

Should return proper body

Tests that the endpoint returns the update user.

users-router_delete_user.spec.js

Tests DELETE /api/users/:userId

Deletes user on success

Tests that the user is successfully deleted.

users-router_find_all_users.spec.js

Tests GET /api/users/all.

Should return proper body

Tests that all users are returned in the body.

users-router_find_user_by_id.spec.js

Tests GET /api/users/:userId.

Should return proper body

Tests that the user is returned in the body.

users-router_update_user.spec.js

Tests PUT /api/users/:userId.

Correctly hashes password

Tests that updating password hashes it.

Accepts correct user fields

Tests that all proper fields can be edited.

Ignores invalid fields

Tests that invalid fields are ignored.

Returns correct body

Tests that the updated user info is returned.

Return 409 on duplicate

Tests that a 409 status code is returned when duplicate email is used.

Clone this wiki locally