BlinkUX / sequelize-mock

A simple mock interface specifically for testing code relying on Sequelize models
https://sequelize-mock.readthedocs.io
MIT License
139 stars 73 forks source link

Returning NaN when use sequelize.fn("count") #89

Open Hoffmano opened 3 years ago

Hoffmano commented 3 years ago

When I use Sequelize Mock between with a query like that:

const getStats = async () => {
  const {
    active,
    'in-progress': inProgress,
  } = await ImmediateCare.findAll({
    raw: true,
    attributes: ['status', [fn('count', col('id')), 'count']],
    group: ['ImmediateCare.status'],
  }).then((status) => {
    const counts = {
      active: 0,
      'in-progress': 0,
    }

    status.forEach((s) => {
      counts[s.status] = parseInt(s.count, 10)
    })

    return counts
  })

  const patientsPerProfessional = inProgress !== 0
    ? active / inProgress
    : active

  return {
    active,
    inProgress,
    patientsPerProfessional,
  }
}

Is being returned NaN, I'm guessing that is because Sequelize Mock can't mock sequelize.fn('count') image

Is that right?

StackOverflow