Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Authorize test:
- import jwt from 'jsonwebtoken'
- import config from '../../../config'
- import middleware from '../../../middleware'
- import { User } from '../../../database/models'
- const { authorize } = middleware
- test('Should call sendFailureResponse if user is not authorized', async () => {
- const req = {
- currentRecipe: {
- userId:1
- },
- authUser: {
- id:2
- },
- }
- const res = {
- sendFailureResponse: jest.fn()
- }
- const next = jest.fn()
- await authorize(req, res, next)
- expect(res.sendFailureResponse).toHaveBeenCalledWith({
- message: "Unauthorized."
- }, 401)
- expect(next).toHaveBeenCalledTimes(0)
- })
- Has recipe test:
- import middleware from '../../../middleware'
- import { runInNewContext } from 'vm';
- const { hasRecipe } = middleware
- test ('The hasRecipe calls the sendFailureResponse function if the validation fails', async () => {
- const req = {
- params: {
- recipeId: '',
- id: ''
- }
- }
- //console.log (req)
- const res = {
- sendFailureResponse: jest.fn()
- }
- const next = jest.fn()
- await hasRecipe(req, res, next)
- expect(res.sendFailureResponse).toHaveBeenCalledWith({
- message:
- 'Recipe not found.'
- }, 404)
- expect(next).toHaveBeenCalledTimes(0)
- })
- Signin test:
- import middleware from '../../../middleware'
- import { runInNewContext } from 'vm';
- const { signinUserValidator } = middleware
- test ('The signinUserValidator calls the next function if the validation is successful', async () => {
- const req = {
- body: {
- name: 'bahdcoder',
- email: 'bahdcoder@gmail.com',
- password: 'password'
- }
- }
- const res = {
- sendFailurResponse() {}
- }
- const next = jest.fn()
- await signinUserValidator(req, res, next)
- expect(next).toHaveBeenCalled()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement