Skip to content

Instantly share code, notes, and snippets.

@ea2305
Created May 13, 2019 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ea2305/2e58a7dcfb47d9e54894053a49bc3d49 to your computer and use it in GitHub Desktop.
Save ea2305/2e58a7dcfb47d9e54894053a49bc3d49 to your computer and use it in GitHub Desktop.
'use strict'
// Importamos test y trait para poder realizar consultas a la api
const { test, trait } = use('Test/Suite')('User Login')
trait('Test/ApiClient')
// Models
const User = use('App/Models/User')
// user template
const test_user = {
username: 'test_user',
email: 'test@yopmail.com',
password: 'password'
}
test('[Login] Request access with bad email', async ({ client }) => {
// Create test user
const user = await User.create(test_user)
// Send request to API with invalid email
const response = await client.post('/api/v1/auth/login')
.send({
email: 'bad_email@example.com',
password: 'password'
})
.end()
// Check response status
response.assertStatus(401)
// check response content
response.assertJSONSubset({ error: 'bad credentials' })
// delete test user
await user.delete()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment