Skip to content

Instantly share code, notes, and snippets.

@rynkis
Created September 20, 2019 08:05
Show Gist options
  • Save rynkis/226023c99a170b5828821d69208b3cbe to your computer and use it in GitHub Desktop.
Save rynkis/226023c99a170b5828821d69208b3cbe to your computer and use it in GitHub Desktop.
api testing sample
const should = require('should')
const request = require('supertest')
const app = require('/path/to/app').default.app
const { describe, it } = global
const username = 'username'
const password = 'password'
describe('token api test', () => {
describe('get token: login', () => {
it('should without error', async () => {
const res = await request(app).post(`/token`)
.set('Accept', 'application/json')
.send({ username, password })
.expect(200)
.expect('Content-Type', /json/)
should(res.body.code).be.equal(0)
should(res.body.data).be.a.Object()
should(res.body.data.token).be.a.String()
should(res.body.data.refresh_token).be.a.String()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment