let cData = require('./data.js')
const app = require('../../app.js').listen()
const request = require('supertest')
const { describe, it } = require('mocha')
const { expect, assert } = require('chai')

describe('Login', function () {
  it('test enterPhone', function () {
    expect(cData.enterPhone).to.be.a('string')
  })

  it('test /login/getCode', function (done) {
    request(app)
      .get('/login/getCode')
      .query({ phone: cData.enterPhone })
      .expect(res => {
        expect(res.body.data).to.have.property('duration')
        cData.checkCode = res.body.data.code
      })
      .end(done)
  })

  it('test /login/checkCode', function (done) {
    request(app)
      .get('/login/checkCode')
      .query({ phone: cData.enterPhone, code: cData.checkCode })
      .expect(res => {
        assert.equal(res.body.code, 0)
        cData.token = res.body.data.token
        expect(res.body.data).to.have.property('res')
      })
      .end(done)
  })
})
