mardi 27 octobre 2020

expected 200 "OK", got 500 "Internal Server Error"

I keep getting this error expected 200 "OK", got 500 "Internal Server Error" on one of my test and I have no idea how to fix it. Please help!!

Here is my test:

describe('instances tests', () => {
  let app = null
  const startTime = Date.now()
  Date.now = () => startTime
  const getTimePlusHours = (hours) => {
    return new Date(Date.now() + 3600000 * hours)
  }
  const instanceData = {
    cloudId: 123456,
    expiresIn: 2
  }
  const endTime = getTimePlusHours(instanceData.expiresIn)

    it('can add instances', () => {
            return request(app)
              .post('/api/instances')
              .send(instanceData)
              .set('Accept', 'application/json')
              .expect('Content-Type', /json/)
              .expect(200).then((response) => {
                assert.strictEqual(response.body.cloud_id, instanceData.cloudId)
                assert.strictEqual(response.body.user_id, 1)
                assert.strictEqual(Date.parse(response.body.expires), endTime.valueOf())
                return Instances.query({
                  where: {cloud_id: instanceData.cloudId}
                }).fetchAll().then((instances) => {
                  assert.strictEqual(instances.models[0].get('cloud_id'), instanceData.cloudId)
                  assert.strictEqual(instances.models[0].get('expires'), endTime.valueOf())
                  assert.strictEqual(instances.models[0].get('user_id'), 1)
                })
              })
          })

Here is my module:

describe('instances', () => {
  beforeAll(() => {
    return bookshelf.knex.migrate.latest()
  })
  it('creates valid instance', () => {
    const expires = Date.now()
    return Instances.forge({
      cloud_id: 123456,
      user_id: 1,
      expires
    }).save(null, {method: 'insert'}).then((instance) => {
      expect(instance).toBeTruthy()
      expect(instance.get('id')).toBeTruthy()
      expect(instance.get('user_id')).toBe(1)
      expect(instance.get('cloud_id')).toBe(123456)
      expect(instance.get('expires')).toBe(expires)
    })
  })

How can I fix this error? Please and thank you.

Aucun commentaire:

Enregistrer un commentaire