Created
March 29, 2020 14:55
-
-
Save ericrocha97/4e090e3771781d6af625ad655c9fbe22 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('supertest'); | |
const app = require('../../src/app'); | |
const connection = require('../../src/database/connection'); | |
describe('Incident', () => { | |
beforeEach(async () => { | |
await connection.migrate.rollback(); | |
await connection.migrate.latest(); | |
}); | |
afterAll(async () => { | |
await connection.destroy(); | |
}); | |
it('shold be able to crete a new incident', async () => { | |
let responseCreateOng = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
let responseCreateIncident = await request(app) | |
.post('/incidents') | |
.send({ | |
title: "TITULO CASO", | |
description: "DESCRICAO CASO", | |
value: 999.99 | |
}) | |
.set('authorization', responseCreateOng.body.id); | |
expect(responseCreateIncident.body).toHaveProperty('id'); | |
expect(responseCreateIncident.body.id).toBe(1); | |
}); | |
it('should be able to list the existents incidents', async () => { | |
let responseCreateOng = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
for (var i = 0; i <= 5; i++) { | |
await request(app) | |
.post('/incidents') | |
.send({ | |
title: "TITULO CASO", | |
description: "DESCRICAO CASO", | |
value: 999.99 | |
}) | |
.set('authorization', responseCreateOng.body.id); | |
} | |
let responseListIncident = await request(app).get('/incidents'); | |
expect(responseListIncident.body).toHaveLength(5); | |
}); | |
it('shold be able to delete a created incident', async () => { | |
let responseCreateOng = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
let responseCreateIncident = await request(app) | |
.post('/incidents') | |
.send({ | |
title: "TITULO CASO", | |
description: "DESCRICAO CASO", | |
value: 999.99 | |
}) | |
.set('authorization', responseCreateOng.body.id); | |
let responseDeleteIncident = await request(app) | |
.delete(`/incidents/${responseCreateIncident.body.id}`) | |
.set('authorization', responseCreateOng.body.id); | |
let responseListIncident = await request(app).get('/incidents'); | |
expect(responseDeleteIncident.status).toBe(204); | |
expect(responseListIncident.body).toHaveLength(0) | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('supertest'); | |
const app = require('../../src/app'); | |
const connection = require('../../src/database/connection'); | |
describe('ONG', () => { | |
beforeEach(async () => { | |
await connection.migrate.rollback(); | |
await connection.migrate.latest(); | |
}); | |
afterAll(async () => { | |
await connection.destroy(); | |
}); | |
it('should be able to create a new ONG', async () => { | |
const response = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
expect(response.body).toHaveProperty('id'); | |
expect(response.body.id).toHaveLength(8); | |
}); | |
it('shold be able to deleta a created ONG', async () => { | |
let responseCreateOng = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
let responseDeleteOng = await request(app).delete(`/ongs/${responseCreateOng.body.id}`) | |
let responseListOng = await request(app).get('/ongs'); | |
expect(responseDeleteOng.status).toBe(204); | |
expect(responseListOng.body).toHaveLength(0) | |
}); | |
it('should be able to list the existents ONGS', async () => { | |
let responseCreateOng = await request(app) | |
.post('/ongs') | |
.send({ | |
name: "NOME ONG", | |
email: "email@domain.com", | |
whatsapp: "(99) 99999-9999", | |
city: "CIDADE", | |
uf: "UF" | |
}); | |
let responseListOng = await request(app).get('/ongs'); | |
expect(responseListOng.body).toHaveLength(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment