Skip to content

Commit

Permalink
Merge pull request #2 from fga-eps-mds/working_crud_etnia
Browse files Browse the repository at this point in the history
CRUD de Etnias e testes unitários
  • Loading branch information
pedroeagle authored Sep 12, 2021
2 parents c8dc75f + 7c06231 commit 577af93
Show file tree
Hide file tree
Showing 34 changed files with 969 additions and 4,843 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = {
plugins: ["prettier"],
rules: {
"prettier/prettier": "error",
"no-unused-vars": ["error", { argsIgnorePattern: "next" }],
},
};
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules
coverage
build
.env
postgres
postgres
yarn.lock
package-lock.json
Binary file added database.sqlite
Binary file not shown.
183 changes: 183 additions & 0 deletions insomnia/Insomnia_2021-09-11.json
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"
}
]
}
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,41 @@
"author": "gabrieldvpereira <gdavi.gd@gmail.com>",
"license": "MIT",
"scripts": {
"orm:create": "sequelize migration:create --name",
"orm:run": "sequelize db:migrate",
"orm:revert": "sequelize db:migrate:undo",
"orm:revertAll": "sequelize db:migrate:undo:all",
"orm:runAll": "sequelize db:migrate && sequelize db:seed:all",
"seed:create": "sequelize seed:generate --name",
"seed:run": "sequelize db:seed:all",
"seed:revert": "sequelize db:seed:undo",
"seed:revertAll": "sequelize db:seed:undo:all",
"start": "sequelize db:migrate && nodemon --exec sucrase-node src/server.js",
"test": "jest",
"test": "sequelize db:migrate:undo:all && sequelize db:migrate && jest",
"lint": "eslint --ext .js,.ts,.tsx src/"
},
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"firebase": "^9.0.1",
"multer": "^1.4.3",
"pg": "^8.7.1",
"sequelize": "^6.6.5"
"sequelize": "^6.6.5",
"youch": "^2.2.2"
},
"devDependencies": {
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.1.0",
"node-pre-gyp": "^0.17.0",
"nodemon": "^2.0.12",
"prettier": "^2.3.2",
"sucrase": "^3.20.1"
"sequelize-cli": "^6.2.0",
"sqlite3": "^5.0.2",
"sucrase": "^3.20.1",
"supertest": "^6.1.6"
}
}
145 changes: 145 additions & 0 deletions src/__tests__/integration/Etnia/index.example
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",
});
});
});
});
Loading

0 comments on commit 577af93

Please sign in to comment.