-
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.
Merge pull request #38 from fga-eps-mds/develop
Integration tests
- Loading branch information
Showing
21 changed files
with
562 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { presets: ["@babel/preset-env"] }; |
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
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
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,4 +1,5 @@ | ||
const dotenv = require("dotenv"); | ||
|
||
dotenv.config({ | ||
path: process.env.NODE_ENV === "test" ? ".env.test" : ".env", | ||
}); |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
const supertest = require("supertest"); | ||
// const app = require("../../../src/app"); | ||
import app from '../../../src/app' | ||
|
||
describe("Testes Etnia", () => { | ||
describe("Testes de criação de Etnia", () => { | ||
it("Etnia - 200 - Criado com sucesso", async () => { | ||
const data = { nome: "tupi45" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body.id_conteudo).toBeTruthy() | ||
}); | ||
|
||
it("Etnia - 200 - Criado com sucesso - 2", async () => { | ||
const data = { nome: "tupi-guarani" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body.id_conteudo).toBeTruthy() | ||
}); | ||
|
||
it("Etnia - 400 - Nome Existente", async () => { | ||
const data = { nome: "tupi45" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome já existente - Etnia - tupi45", | ||
}); | ||
}); | ||
|
||
it("Etnia - 400 - Nome Vazio", async () => { | ||
const data = { nome: "" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome inválido - Etnia - ", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de listagem Etnia", () => { | ||
it("Etnia - 200 - listando com sucesso - Por ID", async () => { | ||
const result = await supertest(app).get("/etnia/1"); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body.id_conteudo).toBeTruthy() | ||
}); | ||
|
||
it("Etnia - 200 - listando com sucesso - Todos", async () => { | ||
const result = await supertest(app).get("/etnia"); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body.length).toBeTruthy() | ||
}); | ||
|
||
it("Etnia - 404 - tentando listar id inexistente", async () => { | ||
const result = await supertest(app).get("/etnia/10"); | ||
|
||
expect(result.status).toStrictEqual(404); | ||
expect(result.body).toMatchObject({ | ||
error: "Etnia não encontrada - Etnia - ID 10", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de atualização de Etnia", () => { | ||
it("Etnia - 200 - Atualizando com sucesso - Por ID", async () => { | ||
const data = { | ||
id_conteudo: 3, | ||
id_etnia: 1, | ||
nome: "guarani", | ||
}; | ||
supertest(app) | ||
.put("/etnia/1") | ||
.send(data) | ||
.then(async (result) => { | ||
expect(result.status).toStrictEqual(200); | ||
}); | ||
}); | ||
|
||
it("Etnia - 400 - Nome Existente", async () => { | ||
const data = { nome: "tupi-guarani" }; | ||
const result = await supertest(app).put("/etnia/2").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome já existente - Etnia - tupi-guarani", | ||
}); | ||
}); | ||
|
||
it("Etnia - 400 - Nome Vazio", async () => { | ||
const data = { nome: "" }; | ||
const result = await supertest(app).put("/etnia/1").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome inválido - Etnia", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de deleção de Etnia", () => { | ||
it("Etnia - 200 - Deletando com sucesso - Por ID", async () => { | ||
supertest(app) | ||
.delete("/etnia/1") | ||
.then(async (result) => { | ||
expect(result.status).toStrictEqual(200); | ||
|
||
supertest(app) | ||
.get("/etnia/1") | ||
.then((resultDB) => { | ||
expect(resultDB.body).toMatchObject({ | ||
error: "Etnia não encontrada - Etnia - ID 1", | ||
}); | ||
}); | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
}); | ||
|
||
it("Etnia - 404 - ID Existente", async () => { | ||
const data = { nome: "tupi-guarani" }; | ||
const result = await supertest(app).delete("/etnia/15"); | ||
|
||
expect(result.status).toStrictEqual(404); | ||
expect(result.body).toMatchObject({ | ||
error: "Etnia não encontrada - Etnia - ID 15", | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const supertest = require("supertest"); | ||
import app from '../../../src/app'; | ||
const modelLingua = require("../../../src/models/Lingua"); | ||
const modelLocalidade = require("../../../src/models/Localidade"); | ||
|
||
|
||
describe("Testes Idioma", () => { | ||
let lingua; | ||
let localidade; | ||
|
||
beforeAll(async () => { | ||
lingua = await modelLingua.create({ nome: "tupi-guarani" }); | ||
localidade = await modelLocalidade.create({ | ||
latitude: 123.5, | ||
longitude: 456.9, | ||
}); | ||
}); | ||
|
||
describe("Testes de criação de Idioma", () => { | ||
it("Idioma - 200 - Criado com sucesso", async () => { | ||
const data = { | ||
id_localidade: localidade.id_localidade, | ||
id_lingua: lingua.id_lingua, | ||
}; | ||
const result = await supertest(app).post("/idioma").send(data); | ||
expect(result.status).toStrictEqual(200); | ||
expect(result.body).toBeTruthy(); | ||
|
||
}); | ||
}); | ||
|
||
describe("Testes de listagem Idioma", () => { | ||
it("Idioma - 200 - listando com sucesso - Todos", async () => { | ||
const result = await supertest(app).get("/idioma").send({ | ||
id_localidade: 1, | ||
id_lingua: 2, | ||
}); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body.length).toBeTruthy() | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const supertest = require("supertest"); | ||
import app from '../../../src/app' | ||
|
||
describe("Testes Lingua", () => { | ||
describe("Testes de criação de Lingua", () => { | ||
it("Lingua - 200 - Criado com sucesso", async () => { | ||
const data = { nome: "tupi" }; | ||
const result = await supertest(app).post("/lingua").send(data); | ||
expect(result.status).toStrictEqual(200); | ||
}); | ||
|
||
it("Lingua - 400 - Nome Existente", async () => { | ||
const data = { nome: "tupi" }; | ||
const result = await supertest(app).post("/lingua").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome já existente - Lingua - tupi", | ||
}); | ||
}); | ||
|
||
it("Lingua - 400 - Nome Vazio", async () => { | ||
const data = { nome: "" }; | ||
const result = await supertest(app).post("/lingua").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Credenciais inválido - Lingua - ", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de listagem Lingua", () => { | ||
it("Lingua - 200 - listando com sucesso - Por ID", async () => { | ||
const result = await supertest(app).get("/lingua/1"); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
|
||
}); | ||
it("Lingua - 200 - listando com sucesso - Todos", async () => { | ||
const result = await supertest(app).get("/lingua"); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
}); | ||
|
||
it("Lingua - 404 - tentando listar id inexistente", async () => { | ||
const result = await supertest(app).get("/lingua/10"); | ||
|
||
expect(result.status).toStrictEqual(404); | ||
expect(result.body).toMatchObject({ | ||
error: "Lingua não encontrada - Lingua - ID 10", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de atualização de Lingua", () => { | ||
it("Lingua - 200 - Atualizando com sucesso - Por ID", async () => { | ||
const data = { | ||
nome: "guarani", | ||
}; | ||
supertest(app) | ||
.put("/lingua/1") | ||
.send(data) | ||
.then(async (result) => { | ||
expect(result.status).toStrictEqual(200); | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
}); | ||
|
||
it("Lingua - 400 - Nome Existente", async () => { | ||
const data = { nome: "tupi-guarani" }; | ||
const result = await supertest(app).put("/lingua/2").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome já existente - Lingua - tupi-guarani", | ||
}); | ||
}); | ||
|
||
it("Lingua - 400 - Nome Vazio", async () => { | ||
const data = { nome: "" }; | ||
const result = await supertest(app).put("/lingua/1").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toMatchObject({ | ||
error: "Nome e Glottocode inválidos - Lingua", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de deleção de Lingua", () => { | ||
it("Lingua - 200 - Deletando com sucesso - Por ID", async () => { | ||
const result = await supertest(app).delete("/lingua/1"); | ||
expect(result.status).toStrictEqual(200); | ||
expect(result.body).toMatchObject({ | ||
Result: "Lingua deletada com sucesso", | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.