diff --git a/README.md b/README.md index e1210f16..38c4e8d0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ - # INDEX - [About this project](#About-this-project) - [Development Environment Setup](#Development-Environment-Setup) @@ -45,6 +44,15 @@ STRIPE_TOKEN=sk_text_YourStripeToken ``` +``` +SECRET:your_google_oauth_secret +``` + +``` +CLIENTID:your_google_oauth_cliendId +``` + + - Start the application using `npm run dev` or `yarn run dev` to launch the application. - Access the application in a web browser using the provided URL or port number. @@ -55,12 +63,20 @@ STRIPE_TOKEN=sk_text_YourStripeToken ## Tests - The aplication was tested with [Jest](https://jestjs.io/) and [Supertest](https://www.npmjs.com/package/supertest) - ``` -npm test +npm run test ``` +# Live demo & Product Explanation. + +[Demo](https://ciervademo.onrender.com/) +This a simple demo. +Shoping Cart State is hanlde by the frontend, so you can store the shoping cart items init and still keep it even if the user is not loged into the app. +This guarantee an excelent user experience btw, bc the user can explore your site before making orders. +The backend provide pagination for some routes, for more info [check the Documentation](https://documenter.getpostman.com/view/21643141/2s93sXcaLf#f3eb5112-676b-46c6-89a2-f5dd6b6c0927) + + # Contribution. - Read The Documentation diff --git a/index.js b/index.js index 836039aa..2a88f7e0 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,14 @@ import express from 'express'; -import importMiddlewares from './middlewaresHandler.js'; -import { connect } from './server.js'; -import { config } from 'dotenv'; +import importMiddlewares from './server/config/middlewaresConfig.js'; +import { connect } from './server/config/serverConfig.js'; import { errorHandler } from './server/helpers/errorHandler.js'; -import apiRouthes from './server/api/routes.js'; +import apiRouthes from './server/config/endpointsConfig.js'; +import envConfig from './server/config/envConfig.js'; //config - -config(); const app = express(); const PORT = process.env.PORT; -export const JWT_TOKEN = process.env.JWT_TOKEN; +export const JWT_TOKEN = envConfig.JWT; // importing middlewares const middlewares = await importMiddlewares(); diff --git a/package.json b/package.json index c79968b7..0cef1460 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "type": "module", "scripts": { - "test": "jest", + "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "start": "node index.js", "dev": "nodemon index.js" }, diff --git a/server/api/routes.js b/server/api/routes.js deleted file mode 100644 index 99e1c65d..00000000 --- a/server/api/routes.js +++ /dev/null @@ -1,16 +0,0 @@ -import user from '../Users/userRoutes.js'; -import cart from '../ShopingCart/shoppingCartRoutes.js'; -import product from '../Products/productRoutes.js'; -import purchase from '../Purchases/purchasesRoutes.js'; -import comment from '../Comments/commentsRoutes.js'; -import response from '../Responses/responsesRoutes.js'; - -const apiRouthes = [ - { route: '/api/users', controller: user }, - { route: '/api/carts', controller: cart }, - { route: '/api/purchases', controller: purchase }, - { route: '/api/products', controller: product }, - { route: '/api/comments', controller: comment }, - { route: '/api/responses', controller: response }, - ]; - export default apiRouthes diff --git a/server/Comments/commentController.js b/server/application/comments/commentController.js similarity index 95% rename from server/Comments/commentController.js rename to server/application/comments/commentController.js index 089b2a3e..ff52b06b 100644 --- a/server/Comments/commentController.js +++ b/server/application/comments/commentController.js @@ -1,7 +1,7 @@ import Comment from './commentModel.js'; import commentService from './commentService.js'; // function to check ownership -import isResourceOwner from '../helpers/isOwner.js'; +import isResourceOwner from '../../helpers/isOwner.js'; const commentController = { createComment, diff --git a/server/Comments/commentModel.js b/server/application/comments/commentModel.js similarity index 100% rename from server/Comments/commentModel.js rename to server/application/comments/commentModel.js diff --git a/server/Comments/commentService.js b/server/application/comments/commentService.js similarity index 100% rename from server/Comments/commentService.js rename to server/application/comments/commentService.js diff --git a/server/Comments/commentsRoutes.js b/server/application/comments/commentsRoutes.js similarity index 79% rename from server/Comments/commentsRoutes.js rename to server/application/comments/commentsRoutes.js index 7ca2a30b..9a2bccef 100644 --- a/server/Comments/commentsRoutes.js +++ b/server/application/comments/commentsRoutes.js @@ -1,7 +1,7 @@ import commentController from './commentController.js'; import express from 'express'; -import { cleanBody } from '../helpers/sanitizer.js'; -import authMiddleware from '../helpers/jwt.js'; +import { cleanBody } from '../../helpers/sanitizer.js'; +import authMiddleware from '../../helpers/jwt.js'; const router = express.Router(); router.post( diff --git a/server/Products/productController.js b/server/application/products/productController.js similarity index 100% rename from server/Products/productController.js rename to server/application/products/productController.js diff --git a/server/Products/productModel.js b/server/application/products/productModel.js similarity index 100% rename from server/Products/productModel.js rename to server/application/products/productModel.js diff --git a/server/Products/productRoutes.js b/server/application/products/productRoutes.js similarity index 77% rename from server/Products/productRoutes.js rename to server/application/products/productRoutes.js index edb061eb..cf8bf9ba 100644 --- a/server/Products/productRoutes.js +++ b/server/application/products/productRoutes.js @@ -1,9 +1,9 @@ import { Router } from 'express'; -import authMiddleware from '../helpers/jwt.js'; -import adminCheck from '../helpers/adminCheck.js'; +import authMiddleware from '../../helpers/jwt.js'; +import adminCheck from '../../helpers/adminCheck.js'; +import { caching } from '../../helpers/cache.js'; +import { cleanBody, validateQuery } from '../../helpers/sanitizer.js'; import productController from './productController.js'; -import { caching } from '../helpers/cache.js'; -import { cleanBody, validateQuery } from '../helpers/sanitizer.js'; const router = Router(); @@ -51,4 +51,4 @@ router.delete( cleanBody, productController.deleteProduct, ); -export default router; \ No newline at end of file +export default router; diff --git a/server/Products/productService.js b/server/application/products/productService.js similarity index 97% rename from server/Products/productService.js rename to server/application/products/productService.js index 2684668b..6d5d719a 100644 --- a/server/Products/productService.js +++ b/server/application/products/productService.js @@ -1,6 +1,6 @@ import Product from './productModel.js'; import mongoose from 'mongoose'; -import { NotFoundError } from '../helpers/errorHandler.js'; +import { NotFoundError } from '../../helpers/errorHandler.js'; const productService = { getProduct, diff --git a/server/Purchases/purchasesController.js b/server/application/purchases/purchasesController.js similarity index 100% rename from server/Purchases/purchasesController.js rename to server/application/purchases/purchasesController.js diff --git a/server/Purchases/purchasesModel.js b/server/application/purchases/purchasesModel.js similarity index 100% rename from server/Purchases/purchasesModel.js rename to server/application/purchases/purchasesModel.js diff --git a/server/Purchases/purchasesRoutes.js b/server/application/purchases/purchasesRoutes.js similarity index 87% rename from server/Purchases/purchasesRoutes.js rename to server/application/purchases/purchasesRoutes.js index eecb3cc9..4e1df395 100644 --- a/server/Purchases/purchasesRoutes.js +++ b/server/application/purchases/purchasesRoutes.js @@ -1,7 +1,7 @@ import { Router } from 'express'; import purchaseController from './purchasesController.js'; -import authMiddleware from '../helpers/jwt.js'; -import adminCheck from '../helpers/adminCheck.js'; +import authMiddleware from '../../helpers/jwt.js'; +import adminCheck from '../../helpers/adminCheck.js'; const router = Router(); router.post('/create', authMiddleware, purchaseController.createPurchase); diff --git a/server/Purchases/purchasesService.js b/server/application/purchases/purchasesService.js similarity index 97% rename from server/Purchases/purchasesService.js rename to server/application/purchases/purchasesService.js index 9593199d..dadb3ae3 100644 --- a/server/Purchases/purchasesService.js +++ b/server/application/purchases/purchasesService.js @@ -1,5 +1,5 @@ import Purchase from './purchasesModel.js'; -import StripePaymentProvider from '../helpers/stripe.js'; +import StripePaymentProvider from '../../helpers/stripe.js'; const paymentProvider = new StripePaymentProvider(); const purchaseService = { diff --git a/server/Responses/responsesController.js b/server/application/responses/responsesController.js similarity index 94% rename from server/Responses/responsesController.js rename to server/application/responses/responsesController.js index 8ef8a32c..9b0f918c 100644 --- a/server/Responses/responsesController.js +++ b/server/application/responses/responsesController.js @@ -1,7 +1,7 @@ import responseService from './responsesService.js'; import Response from './responsesModel.js'; // function to check ownership -import isResourceOwner from '../helpers/isOwner.js'; +import isResourceOwner from '../../helpers/isOwner.js'; const responseControllers = { createResponse, diff --git a/server/Responses/responsesModel.js b/server/application/responses/responsesModel.js similarity index 100% rename from server/Responses/responsesModel.js rename to server/application/responses/responsesModel.js diff --git a/server/Responses/responsesRoutes.js b/server/application/responses/responsesRoutes.js similarity index 80% rename from server/Responses/responsesRoutes.js rename to server/application/responses/responsesRoutes.js index 6892356a..580c03a1 100644 --- a/server/Responses/responsesRoutes.js +++ b/server/application/responses/responsesRoutes.js @@ -1,7 +1,7 @@ import responseControllers from './responsesController.js'; import express from 'express'; -import { cleanBody } from '../helpers/sanitizer.js'; -import authMiddleware from '../helpers/jwt.js'; +import { cleanBody } from '../../helpers/sanitizer.js'; +import authMiddleware from '../../helpers/jwt.js'; const router = express.Router(); router.get('/getAll', authMiddleware, responseControllers.getAllResponse); router.post( diff --git a/server/Responses/responsesService.js b/server/application/responses/responsesService.js similarity index 100% rename from server/Responses/responsesService.js rename to server/application/responses/responsesService.js diff --git a/server/ShopingCart/shopinCartModel.js b/server/application/shopingCart/shopinCartModel.js similarity index 100% rename from server/ShopingCart/shopinCartModel.js rename to server/application/shopingCart/shopinCartModel.js diff --git a/server/ShopingCart/shopingCartController.js b/server/application/shopingCart/shopingCartController.js similarity index 92% rename from server/ShopingCart/shopingCartController.js rename to server/application/shopingCart/shopingCartController.js index 253d7d89..66372272 100644 --- a/server/ShopingCart/shopingCartController.js +++ b/server/application/shopingCart/shopingCartController.js @@ -1,7 +1,7 @@ import cartService from './shopingCartService.js'; // function to check ownership -import isResourceOwner from '../helpers/isOwner.js'; -import Cart from '../ShopingCart/shopinCartModel.js'; +import isResourceOwner from '../../helpers/isOwner.js'; +import Cart from './shopinCartModel.js'; const cartController = { createCart, diff --git a/server/ShopingCart/shopingCartService.js b/server/application/shopingCart/shopingCartService.js similarity index 96% rename from server/ShopingCart/shopingCartService.js rename to server/application/shopingCart/shopingCartService.js index 6c74fa59..99bd8f61 100644 --- a/server/ShopingCart/shopingCartService.js +++ b/server/application/shopingCart/shopingCartService.js @@ -1,5 +1,6 @@ import ShoppingCart from './shopinCartModel.js'; -import userService from '../Users/usersService.js'; +import userService from '../users/usersService.js'; + const cartService = { createCart, editCart, diff --git a/server/ShopingCart/shoppingCartRoutes.js b/server/application/shopingCart/shoppingCartRoutes.js similarity index 76% rename from server/ShopingCart/shoppingCartRoutes.js rename to server/application/shopingCart/shoppingCartRoutes.js index fc7e27de..1b50e2e7 100644 --- a/server/ShopingCart/shoppingCartRoutes.js +++ b/server/application/shopingCart/shoppingCartRoutes.js @@ -1,8 +1,8 @@ import { Router } from 'express'; import cartController from './shopingCartController.js'; -import authMiddleware from '../helpers/jwt.js'; -import adminCheck from '../helpers/adminCheck.js'; -import { cleanBody } from '../helpers/sanitizer.js'; +import authMiddleware from '../../helpers/jwt.js'; +import adminCheck from '../../helpers/adminCheck.js'; +import { cleanBody } from '../../helpers/sanitizer.js'; const router = Router(); router.post('/create', authMiddleware, cleanBody, cartController.createCart); diff --git a/server/Users/userModel.js b/server/application/users/userModel.js similarity index 100% rename from server/Users/userModel.js rename to server/application/users/userModel.js diff --git a/server/Users/userRoutes.js b/server/application/users/userRoutes.js similarity index 76% rename from server/Users/userRoutes.js rename to server/application/users/userRoutes.js index 0580fafa..1c73c4cf 100644 --- a/server/Users/userRoutes.js +++ b/server/application/users/userRoutes.js @@ -1,8 +1,8 @@ import { Router } from 'express'; import usersController from './usersControllers.js'; -import adminCheck from '../helpers/adminCheck.js'; -import authMiddleware from '../helpers/jwt.js'; -import { cleanBody } from '../helpers/sanitizer.js'; +import adminCheck from '../../helpers/adminCheck.js' +import authMiddleware from '../../helpers/jwt.js'; +import { cleanBody } from '../../helpers/sanitizer.js'; const router = Router(); router.post('/signIn', cleanBody, usersController.signIn); diff --git a/server/Users/usersControllers.js b/server/application/users/usersControllers.js similarity index 96% rename from server/Users/usersControllers.js rename to server/application/users/usersControllers.js index 428473fb..26c58301 100644 --- a/server/Users/usersControllers.js +++ b/server/application/users/usersControllers.js @@ -1,17 +1,8 @@ import userService from './usersService.js'; const maxAge = 24 * 60 * 60 * 1000; -const usersController = { - signIn, - signUp, - getUser, - getStat, - googleToken, - findByEmail, -}; - function signIn(req, res, next) { -console.log("aca"); + console.log('aca'); userService .signIn(req.body) .then(({ user, sendToken }) => { @@ -31,6 +22,7 @@ console.log("aca"); } function signUp(req, res, next) { + console.log('controller'); userService .signUp(req.body) .then((user) => res.json(user)) @@ -65,4 +57,12 @@ function googleToken(req, res, next) { .catch((error) => next(error)); } +const usersController = { + signIn, + signUp, + getUser, + getStat, + googleToken, + findByEmail, +}; export default usersController; diff --git a/server/Users/usersService.js b/server/application/users/usersService.js similarity index 84% rename from server/Users/usersService.js rename to server/application/users/usersService.js index eee36f55..5c56a764 100644 --- a/server/Users/usersService.js +++ b/server/application/users/usersService.js @@ -1,15 +1,17 @@ -import Encrypt from '../helpers/bcrypt.js'; import User from './userModel.js'; -import { JWT_TOKEN } from '../../index.js'; -import Token from '../helpers/token.js'; +import { JWT_TOKEN } from '../../../index.js'; +import Token from '../../helpers/token.js'; +import Encrypt from '../../helpers/bcrypt.js'; import { BadRequestError, NotFoundError, UnauthorizedError, -} from '../helpers/errorHandler.js'; +} from '../../helpers/errorHandler.js'; import { OAuth2Client } from 'google-auth-library'; -const SECRET = process.env.SECRET; -const CLIENTID = process.env.CLIENTID; +import envConfig from '../../config/envConfig.js'; + +const SECRET = envConfig.SECRET; +const CLIENTID = envConfig.CLIENTID; //config const userService = { @@ -31,7 +33,7 @@ async function findByEmail(email) { if (alreadyExist) { return alreadyExist; } else { - return null; + throw new NotFoundError(`user with ${email} not found`); } } @@ -64,22 +66,21 @@ async function checkLength(item, num) { async function signUp(user) { const allowedFields = ['email', 'password', 'username']; - const filteredUser = Object.keys(user) //check if user contains allowedFields .filter((key) => allowedFields.includes(key)) .reduce((obj, key) => { obj[key] = user[key]; return obj; }, {}); + await checkLength(filteredUser.password, 8); - const validatePass = await checkLength(filteredUser.password, 8); - if (validatePass) { + try { const encryptPassword = await encrypt.hashPassword(filteredUser.password); const createUser = new User({ ...filteredUser, password: encryptPassword }); const newUser = await createUser.save(); return newUser; - } else { - throw new BadRequestError('password does not match'); + } catch (error) { + throw new BadRequestError(error.message); } } diff --git a/server/config/endpointsConfig.js b/server/config/endpointsConfig.js new file mode 100644 index 00000000..190e79b7 --- /dev/null +++ b/server/config/endpointsConfig.js @@ -0,0 +1,16 @@ +import user from '../application/users/userRoutes.js'; +import cart from '../application/shopingCart/shoppingCartRoutes.js'; +import product from '../application/products/productRoutes.js'; +import purchase from '../application/purchases/purchasesRoutes.js'; +import comment from '../application/comments/commentsRoutes.js'; +import response from '../application/responses/responsesRoutes.js'; + +const apiRouthes = [ + { route: '/api/users', controller: user }, + { route: '/api/carts', controller: cart }, + { route: '/api/purchases', controller: purchase }, + { route: '/api/products', controller: product }, + { route: '/api/comments', controller: comment }, + { route: '/api/responses', controller: response }, + ]; + export default apiRouthes diff --git a/server/config/envConfig.js b/server/config/envConfig.js new file mode 100644 index 00000000..3518054f --- /dev/null +++ b/server/config/envConfig.js @@ -0,0 +1,12 @@ +import { config } from 'dotenv'; +config(); + +const envConfig = { + PORT: process.env.PORT, + JWT: process.env.JWT_TOKEN, + SERVER: process.env.MONGO, + STRIPE: process.env.STRIPE_TOKEN, + SECRET: process.env.SECRET, + CLIENTID: process.env.CLIENTID, +}; +export default envConfig; diff --git a/middlewaresHandler.js b/server/config/middlewaresConfig.js similarity index 80% rename from middlewaresHandler.js rename to server/config/middlewaresConfig.js index d3b8df32..0f12133b 100644 --- a/middlewaresHandler.js +++ b/server/config/middlewaresConfig.js @@ -5,7 +5,7 @@ import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); //middleware Files -const middlewareDir = path.join(__dirname, 'server/middlewares'); +const middlewareDir = path.join(__dirname, '../middlewares'); //put the middleware files into the array & export it const importMiddlewares = async () => { @@ -14,7 +14,7 @@ const importMiddlewares = async () => { for (const file of middlewareFiles) { console.log(`./server/middlewares/${file}`); - const middleware = await import(`./server/middlewares/${file}`); + const middleware = await import(`../middlewares/${file}`); middlewareArray.push(middleware.default); } diff --git a/server.js b/server/config/serverConfig.js similarity index 71% rename from server.js rename to server/config/serverConfig.js index f07a5019..e63651a1 100644 --- a/server.js +++ b/server/config/serverConfig.js @@ -1,11 +1,11 @@ import mongoose from 'mongoose'; -import { config } from 'dotenv'; -config(); +import envConfig from './envConfig.js'; +const db = envConfig.SERVER; const server = mongoose; export const connect = () => { server - .connect(process.env.MONGO) + .connect(db) .then(() => { console.log('connected to mongoose'); }) diff --git a/server/helpers/adminCheck.js b/server/helpers/adminCheck.js index 1c11e32f..427bc88d 100644 --- a/server/helpers/adminCheck.js +++ b/server/helpers/adminCheck.js @@ -1,4 +1,4 @@ -import User from '../Users/userModel.js'; +import User from '../application/users/userModel.js'; import { UnauthorizedError } from './errorHandler.js'; async function adminCheck(req, res, next) { diff --git a/server/helpers/stripe.js b/server/helpers/stripe.js index 7949ad9b..59eb9122 100644 --- a/server/helpers/stripe.js +++ b/server/helpers/stripe.js @@ -1,8 +1,7 @@ import IPaymentProvider from './paymentProcess.js'; -import { config } from 'dotenv'; -config(); +import envConfig from '../config/envConfig.js'; import stripe from 'stripe'; -const stripeInstance = stripe(process.env.STRIPE_TOKEN); +const stripeInstance = stripe(envConfig.STRIPE); export default class StripePaymentProvider extends IPaymentProvider { async createPayment(tokenId, amount) { diff --git a/server/tests/componentsTests/usersControllers.test.js b/server/tests/componentsTests/usersControllers.test.js new file mode 100644 index 00000000..141b71ac --- /dev/null +++ b/server/tests/componentsTests/usersControllers.test.js @@ -0,0 +1,14 @@ +import { expect } from 'chai'; +import usersController from '../../application/users/usersControllers'; + +describe('this tests should return succesfull responses', () => { + it('should return an user with status code 200', async () => { + const body = { + email: '12345@hotmail.com', + password: + '@ztCU^d3Q9%JXkN!toR&fVniRupNySHo3w^6tP*VfG9vuoH9u#zod42JC6Y6Poq', + }; + const response = usersController.signIn(body); + console.log(response); + }); +}); diff --git a/server/tests/purchases.test.js b/server/tests/purchases.test.js deleted file mode 100644 index fa0a79fd..00000000 --- a/server/tests/purchases.test.js +++ /dev/null @@ -1,102 +0,0 @@ -import request from 'supertest'; -import { Router } from 'express'; -import cartController from './shopingCartController.js'; -import authMiddleware from '../helpers/jwt.js'; -import adminCheck from '../helpers/adminCheck.js'; -import { cleanBody } from '../helpers/sanitizer.js'; - -const router = Router(); - -// Mock authMiddleware and adminCheck -jest.mock('../helpers/jwt.js', () => jest.fn()); -jest.mock('../helpers/adminCheck.js', () => jest.fn()); - -// Mock cartController methods -cartController.createCart = jest.fn(); -cartController.getAll = jest.fn(); -cartController.getUserCart = jest.fn(); -cartController.editCart = jest.fn(); -cartController.deleteCart = jest.fn(); - -// Mock router methods -router.post = jest.fn(); -router.get = jest.fn(); -router.put = jest.fn(); -router.delete = jest.fn(); - -describe('Cart Routes', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - it('should call the appropriate methods when POST /create is called', async () => { - router.post('/create', authMiddleware, cleanBody, cartController.createCart); - - const req = { body: { products: [] }, user: { id: 'user_id' } }; - const res = { json: jest.fn() }; - const next = jest.fn(); - - await request(router).post('/create').send(req.body).set('Authorization', 'Bearer token'); - - expect(authMiddleware).toHaveBeenCalled(); - expect(cleanBody).toHaveBeenCalled(); - expect(cartController.createCart).toHaveBeenCalledWith(req, res, next); - }); - - it('should call the appropriate methods when GET /getAll is called', async () => { - router.get('/getAll', authMiddleware, adminCheck, cartController.getAll); - - const req = { query: { page: '1', size: '10' } }; - const res = { json: jest.fn() }; - const next = jest.fn(); - - await request(router).get('/getAll').query(req.query).set('Authorization', 'Bearer token'); - - expect(authMiddleware).toHaveBeenCalled(); - expect(adminCheck).toHaveBeenCalled(); - expect(cartController.getAll).toHaveBeenCalledWith(req, res, next); - }); - - it('should call the appropriate methods when GET /:userId is called', async () => { - router.get('/:userId', authMiddleware, cartController.getUserCart); - - const req = { params: { userId: 'user_id' } }; - const res = { json: jest.fn() }; - const next = jest.fn(); - - await request(router).get(`/${req.params.userId}`).set('Authorization', 'Bearer token'); - - expect(authMiddleware).toHaveBeenCalled(); - expect(cartController.getUserCart).toHaveBeenCalledWith(req, res, next); - }); - - it('should call the appropriate methods when PUT /update/:cartId is called', async () => { - router.put('/update/:cartId', authMiddleware, cleanBody, cartController.editCart); - - const req = { body: {}, params: { cartId: 'cart_id' }, user: { id: 'user_id' } }; - const res = { json: jest.fn() }; - const next = jest.fn(); - - await request(router) - .put(`/update/${req.params.cartId}`) - .send(req.body) - .set('Authorization', 'Bearer token'); - - expect(authMiddleware).toHaveBeenCalled(); - expect(cleanBody).toHaveBeenCalled(); - expect(cartController.editCart).toHaveBeenCalledWith(req, res, next); - }); - - it('should call the appropriate methods when DELETE /delete/:cartId is called', async () => { - router.delete('/delete/:cartId', authMiddleware, cartController.deleteCart); - - const req ={ params: { cartId: 'cart_id' }, user: { id: 'user_id' } }; - const res = { json: jest.fn() }; - const next = jest.fn(); - - await request(router).delete(`/delete/${req.params.cartId}`).set('Authorization', 'Bearer token'); - - expect(authMiddleware).toHaveBeenCalled(); - expect(cartController.deleteCart).toHaveBeenCalledWith(req, res, next); - }); -}); diff --git a/server/tests/product.test.js b/server/tests/serviceTests/product.test.js similarity index 100% rename from server/tests/product.test.js rename to server/tests/serviceTests/product.test.js diff --git a/server/tests/serviceTests/purchases.test.js b/server/tests/serviceTests/purchases.test.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/server/tests/serviceTests/purchases.test.js @@ -0,0 +1 @@ + diff --git a/server/tests/shoppingCart.test.js b/server/tests/serviceTests/shoppingCart.test.js similarity index 100% rename from server/tests/shoppingCart.test.js rename to server/tests/serviceTests/shoppingCart.test.js diff --git a/server/tests/user.test.js b/server/tests/serviceTests/user.test.js similarity index 100% rename from server/tests/user.test.js rename to server/tests/serviceTests/user.test.js