Skip to content

Commit

Permalink
Adicionando testes de permissão
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogerio Angeliski committed Feb 15, 2018
1 parent ec03712 commit 4b3e69f
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/api/event.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,34 @@ describe('Events', () => {
.end(TestUtil.endTest.bind(null, done))
})

it('should persist the new event when not have admin token', (done) => {
const event = {
'title': 'BrazilJS - POA',
'link': 'https://braziljs.org/conf/',
'price': 1.5,
'image': 'https://braziljs.org/wp-content/themes/braziljs/assets/img/logos/braziljs-00508dcfc4.svg',
'__v': 0,
'location': {
'city': 'POA',
'state': 'RS',
'address': 'Barra Shopping Sul'
},
'date': {
'day': 25,
'month': 'Agosto',
'year': 2017
}
}
const genericToken = Authentication.createToken('generic@testando.com').token

request.post('/')
.send(event)
.set('authorization', `Bearer ${genericToken}`)
.expect('Content-Type', /json/)
.expect(200)
.end(TestUtil.endTest.bind(null, done))
})

it('should return error when not have price', (done) => {
const event = {
'title': 'BrazilJS - POA',
Expand Down Expand Up @@ -174,6 +202,36 @@ describe('Events', () => {
.expect(200)
.end(TestUtil.endTest.bind(null, done))
})

it('should return error on generic user update the event', (done) => {
const event = {
'title': 'BrazilJS - POA',
'link': 'https://braziljs.org/conf/',
'price': 1.5,
'image': 'https://braziljs.org/wp-content/themes/braziljs/assets/img/logos/braziljs-00508dcfc4.svg',
'__v': 0,
'location': {
'city': 'POA',
'state': 'RS',
'address': 'Barra Shopping Sul'
},
'date': {
'day': 25,
'month': 'Agosto',
'year': 2017
}
}

const genericToken = Authentication.createToken('generic@testando.com').token

request.put('/200000000000000000000001')
.send(event)
.set('authorization', `Bearer ${genericToken}`)
.expect('Content-Type', /json/)
.expect(401)
.end(TestUtil.endTest.bind(null, done))
})

it('should return error on update event not persisted', (done) => {
const event = {}

Expand Down

0 comments on commit 4b3e69f

Please sign in to comment.