-
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 #2 from fga-eps-mds/working_crud_etnia
CRUD de Etnias e testes unitários
- Loading branch information
Showing
34 changed files
with
969 additions
and
4,843 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 |
---|---|---|
|
@@ -2,4 +2,6 @@ node_modules | |
coverage | ||
build | ||
.env | ||
postgres | ||
postgres | ||
yarn.lock | ||
package-lock.json |
Binary file not shown.
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,183 @@ | ||
{ | ||
"_type": "export", | ||
"__export_format": 4, | ||
"__export_date": "2021-09-12T01:15:57.307Z", | ||
"__export_source": "insomnia.desktop.app:v2021.5.2", | ||
"resources": [ | ||
{ | ||
"_id": "req_83b731243d4d48d7b7f5e392e65255d9", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631409344802, | ||
"created": 1631407330258, | ||
"url": "localhost:8000/etnia/:id", | ||
"name": "delete etnia", | ||
"description": "", | ||
"method": "DELETE", | ||
"body": {}, | ||
"parameters": [], | ||
"headers": [], | ||
"authentication": {}, | ||
"metaSortKey": -1631407330258, | ||
"isPrivate": false, | ||
"settingStoreCookies": true, | ||
"settingSendCookies": true, | ||
"settingDisableRenderRequestBody": false, | ||
"settingEncodeUrl": true, | ||
"settingRebuildPath": true, | ||
"settingFollowRedirects": "global", | ||
"_type": "request" | ||
}, | ||
{ | ||
"_id": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"parentId": null, | ||
"modified": 1631404635881, | ||
"created": 1631404635881, | ||
"name": "etnia", | ||
"description": "", | ||
"scope": "collection", | ||
"_type": "workspace" | ||
}, | ||
{ | ||
"_id": "req_faf5453680424e87ad7d58c14a8a24a8", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631409337799, | ||
"created": 1631405109175, | ||
"url": "localhost:8000/etnia/:id", | ||
"name": "update etnia", | ||
"description": "", | ||
"method": "PUT", | ||
"body": { | ||
"mimeType": "application/json", | ||
"text": "{\n\t\"nome\": \"guarani\"\n}" | ||
}, | ||
"parameters": [], | ||
"headers": [ | ||
{ | ||
"name": "Content-Type", | ||
"value": "application/json", | ||
"id": "pair_f6f5e554a3b54275bc3d86af78dafb1e" | ||
} | ||
], | ||
"authentication": {}, | ||
"metaSortKey": -1631405109175, | ||
"isPrivate": false, | ||
"settingStoreCookies": true, | ||
"settingSendCookies": true, | ||
"settingDisableRenderRequestBody": false, | ||
"settingEncodeUrl": true, | ||
"settingRebuildPath": true, | ||
"settingFollowRedirects": "global", | ||
"_type": "request" | ||
}, | ||
{ | ||
"_id": "req_02dfb963fc6844cc84fa66d741d41db6", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631409130588, | ||
"created": 1631404922695, | ||
"url": "localhost:8000/etnia/:id", | ||
"name": "get etnia", | ||
"description": "", | ||
"method": "GET", | ||
"body": {}, | ||
"parameters": [], | ||
"headers": [], | ||
"authentication": {}, | ||
"metaSortKey": -1631404922695, | ||
"isPrivate": false, | ||
"settingStoreCookies": true, | ||
"settingSendCookies": true, | ||
"settingDisableRenderRequestBody": false, | ||
"settingEncodeUrl": true, | ||
"settingRebuildPath": true, | ||
"settingFollowRedirects": "global", | ||
"_type": "request" | ||
}, | ||
{ | ||
"_id": "req_6fa808904a6342cab497a8cda2d384a7", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631404902909, | ||
"created": 1631404894217, | ||
"url": "localhost:8000/etnia", | ||
"name": "get etnias", | ||
"description": "", | ||
"method": "GET", | ||
"body": {}, | ||
"parameters": [], | ||
"headers": [], | ||
"authentication": {}, | ||
"metaSortKey": -1631404894217, | ||
"isPrivate": false, | ||
"settingStoreCookies": true, | ||
"settingSendCookies": true, | ||
"settingDisableRenderRequestBody": false, | ||
"settingEncodeUrl": true, | ||
"settingRebuildPath": true, | ||
"settingFollowRedirects": "global", | ||
"_type": "request" | ||
}, | ||
{ | ||
"_id": "req_66bdb6a6f5b540e794c2f837b02f0187", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631409314755, | ||
"created": 1631404680595, | ||
"url": "localhost:8000/etnia", | ||
"name": "create etnia", | ||
"description": "", | ||
"method": "POST", | ||
"body": { | ||
"mimeType": "application/json", | ||
"text": "{\n\t\"nome\": \"tupi\"\n}" | ||
}, | ||
"parameters": [], | ||
"headers": [ | ||
{ | ||
"name": "Content-Type", | ||
"value": "application/json", | ||
"id": "pair_5235154000704462b69e1b63ee66557b" | ||
} | ||
], | ||
"authentication": {}, | ||
"metaSortKey": -1631404680595, | ||
"isPrivate": false, | ||
"settingStoreCookies": true, | ||
"settingSendCookies": true, | ||
"settingDisableRenderRequestBody": false, | ||
"settingEncodeUrl": true, | ||
"settingRebuildPath": true, | ||
"settingFollowRedirects": "global", | ||
"_type": "request" | ||
}, | ||
{ | ||
"_id": "env_0ef7c1bde1d7152b29d23e59ed49dc83738096d9", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631404635885, | ||
"created": 1631404635885, | ||
"name": "Base Environment", | ||
"data": {}, | ||
"dataPropertyOrder": null, | ||
"color": null, | ||
"isPrivate": false, | ||
"metaSortKey": 1631404635885, | ||
"_type": "environment" | ||
}, | ||
{ | ||
"_id": "jar_0ef7c1bde1d7152b29d23e59ed49dc83738096d9", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631404635886, | ||
"created": 1631404635886, | ||
"name": "Default Jar", | ||
"cookies": [], | ||
"_type": "cookie_jar" | ||
}, | ||
{ | ||
"_id": "spc_0e5b2a7674d84501b8a5263efd8301b4", | ||
"parentId": "wrk_4c8affee210844bd8426b533bb7ba372", | ||
"modified": 1631404635882, | ||
"created": 1631404635882, | ||
"fileName": "etnia", | ||
"contents": "", | ||
"contentType": "yaml", | ||
"_type": "api_spec" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
const supertest = require("supertest"); | ||
const app = "localhost:8000"; | ||
|
||
describe("Testes Etnia", () => { | ||
describe("Testes de criação de Etnia", () => { | ||
it("Etnia - 200 - Criado com sucesso", async () => { | ||
const data = { nome: "tupi" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
const dataResult = { id_conteudo: 1, nome: "tupi" }; | ||
expect(result.body).toStrictEqual(dataResult); | ||
}); | ||
|
||
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); | ||
const dataResult = { id_conteudo: 2, nome: "tupi-guarani" }; | ||
expect(result.body).toStrictEqual(dataResult); | ||
}); | ||
|
||
it("Etnia - 400 - Nome Existente", async () => { | ||
const data = { nome: "tupi" }; | ||
const result = await supertest(app).post("/etnia").send(data); | ||
|
||
expect(result.status).toStrictEqual(400); | ||
expect(result.body).toStrictEqual({ error: "Nome já existente - Etnia" }); | ||
}); | ||
|
||
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).toStrictEqual({ | ||
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).toStrictEqual({ | ||
id_conteudo: 1, | ||
id_etnia: 1, | ||
nome: "tupi", | ||
}); | ||
}); | ||
|
||
it("Etnia - 200 - listando com sucesso - Todos", async () => { | ||
const result = await supertest(app).get("/etnia"); | ||
|
||
expect(result.status).toStrictEqual(200); | ||
expect(result.body).toStrictEqual([ | ||
{ id_conteudo: 1, id_etnia: 1, nome: "tupi" }, | ||
{ id_conteudo: 2, id_etnia: 2, nome: "tupi-guarani" }, | ||
]); | ||
}); | ||
|
||
it("Etnia - 404 - tentando listar id inexistente", async () => { | ||
const result = await supertest(app).get("/etnia/10"); | ||
|
||
expect(result.status).toStrictEqual(404); | ||
expect(result.body).toStrictEqual({ | ||
error: "Etnia não encontrada - Etnia", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Testes de atualização de Etnia", () => { | ||
it("Etnia - 200 - Atualizando com sucesso - Por ID", async () => { | ||
const data = { nome: "guarani" }; | ||
supertest(app) | ||
.put("/etnia/1") | ||
.send(data) | ||
.then(async (result) => { | ||
expect(result.status).toStrictEqual(200); | ||
expect(result.body).toStrictEqual(data); | ||
|
||
supertest(app) | ||
.get("/etnia/1") | ||
.then((resultDB) => { | ||
expect(result.body).toStrictEqual({ nome: resultDB.body.nome }); | ||
}); | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
}); | ||
|
||
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).toStrictEqual({ error: "Nome já existente - Etnia" }); | ||
}); | ||
|
||
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).toStrictEqual({ | ||
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).toStrictEqual({ | ||
error: "Etnia não encontrada - Etnia", | ||
}); | ||
}); | ||
}) | ||
.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).toStrictEqual({ | ||
error: "Etnia não encontrada - Etnia", | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.