text: jest.mock('jsonwebtoken', () => ({
    token: 'any_token',
    sign (payload, secret) {
      this.payload = payload
      this.secret = secret
      return this.token
    }
  }))
  
  const jwt = require('jsonwebtoken')
  const MissingParamError = require('../errors/missing-param-error')
  const TokenGenerator = require('./token-generator')
  
  const makeSut = () => {
    return new TokenGenerator('secret_key')
  }
  
  describe('Token Generator', () => {
    it('Should return null if JWT returns null', async () => {
      const sut = makeSut()
      jwt.token = null
      const token = await sut.generate('any_id')
      expect(token).toBeNull()
    })
  
    it('Should return a token if JWT returns token', async () => {
      const sut = makeSut()
      const token = await sut.generate('any_id')
      expect(token).toBe(jwt.token)
    })
  
    it('Should call JWT with correct values', async () => {
      const sut = makeSut()
      await sut.generate('any_id')
      expect(jwt.payload).toEqual({ _id: 'any_id' })
      expect(jwt.secret).toBe(sut.secret)
    })
  
    it('Should throw error if secret is not provided', async () => {
      const sut = new TokenGenerator()
      const promise = sut.generate('any_id')
      expect(promise).rejects.toThrow(new MissingParamError('secret'))
    })
  
    it('Should throw error if id is not provided', async () => {
      const sut = makeSut()
      const promise = sut.generate()
      expect(promise).rejects.toThrow(new MissingParamError('id'))
    })
  })
  