forked from pauloborba/teachingassistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uso de promessas no teste do servidor
- Loading branch information
1 parent
06f393c
commit 0f41101
Showing
2 changed files
with
28 additions
and
31 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
import request = require("request"); | ||
import request = require("request-promise"); | ||
import { closeServer } from '../ta-server'; | ||
|
||
var base_url = "http://localhost:3000/"; | ||
|
||
describe("O servidor", () => { | ||
var server:any; | ||
|
||
beforeAll(() => server = require('../ta-server')); | ||
beforeAll(() => {server = require('../ta-server')}); | ||
|
||
afterAll(() => server.closeServer()); | ||
afterAll(() => {server.closeServer()}); | ||
|
||
it("inicialmente retorna uma lista de alunos vazia", (done:any) => { | ||
request.get(base_url + "alunos", (error, response, body) => { | ||
expect(body).toBe("[]"); | ||
done(); | ||
}); | ||
it("inicialmente retorna uma lista de alunos vazia", () => { | ||
return request.get(base_url + "alunos").then(body => expect(body).toBe("[]")).catch(e => expect(e).toEqual(null)); | ||
}) | ||
|
||
it("só cadastra alunos", (done:any) => { | ||
request.post(base_url + "aluno", {"json":{"name": "Mari", "cpf" : "962"}}, (error, response, body) => { | ||
expect(body).toEqual({failure: "O aluno não pode ser cadastrado"}); | ||
done(); | ||
}); | ||
}) | ||
|
||
it("não cadastra alunos com CPF duplicado", (done:any) => { | ||
request.post(base_url + "aluno", {"json":{"nome": "Mari", "cpf" : "965"}}, (error, response, body) => { | ||
expect(body).toEqual({success: "O aluno foi cadastrado com sucesso"}); | ||
done(); | ||
}); | ||
request.post(base_url + "aluno", {"json":{"nome": "Pedro", "cpf" : "965"}}, (error, response, body) => { | ||
expect(body).toEqual({failure: "O aluno não pode ser cadastrado"}); | ||
done(); | ||
}); | ||
request.get(base_url + "alunos", (error, response, body) => { | ||
expect(body).toContain('[{"nome": "Mari", "cpf" : "965", "email": "", "metas":{}}]'); | ||
expect(body).not.toContain('[{"nome": "Pedro", "cpf" : "965", "email": "", "metas":{}}]'); | ||
done(); | ||
}); | ||
it("só cadastra alunos", () => { | ||
var options:any = {method: 'POST', uri: (base_url + "aluno"), body:{name: "Mari", cpf: "962"}, json: true}; | ||
return request(options).then(body => | ||
expect(body).toEqual({failure: "O aluno não pode ser cadastrado"}) | ||
).catch(e => | ||
expect(e).toEqual(null) | ||
) | ||
}); | ||
|
||
|
||
it("não cadastra alunos com CPF duplicado", () => { | ||
return request.post(base_url + "aluno", {"json":{"nome": "Mari", "cpf" : "965"}}).then(body => { | ||
expect(body).toEqual({success: "O aluno foi cadastrado com sucesso"}); | ||
return request.post(base_url + "aluno", {"json":{"nome": "Pedro", "cpf" : "965"}}).then(body => { | ||
expect(body).toEqual({failure: "O aluno não pode ser cadastrado"}); | ||
return request.get(base_url + "alunos").then(body => { | ||
expect(body).toContain('{"nome":"Mari","cpf":"965","email":"","metas":{}}'); | ||
expect(body).not.toContain('{"nome":"Pedro","cpf":"965","email":"","metas":{}}'); | ||
}); | ||
}); | ||
}); | ||
}) | ||
|
||
}) |