From 7987c6c3fabb83392138689c2773a2e0c741cc82 Mon Sep 17 00:00:00 2001 From: Oscar de Brito Date: Sun, 2 Jul 2023 20:52:23 -0300 Subject: [PATCH 01/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona filtro no FlowController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: YanWerlley Co-authored-by: Sérgio Cipriano --- src/controllers/FlowController.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/controllers/FlowController.js b/src/controllers/FlowController.js index 2065d18d..cf3c422f 100644 --- a/src/controllers/FlowController.js +++ b/src/controllers/FlowController.js @@ -6,6 +6,7 @@ import FlowUser from "../models/FlowUser.js"; import FlowProcess from "../models/FlowProcess.js"; import { QueryTypes } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; +import { filterByName } from "../utils/filters.js" class FlowController { static #stagesSequencesFromFlowStages(flowStages) { @@ -143,21 +144,26 @@ class FlowController { let where; if (req.headers.test !== "ok") { const { idUnit, idRole } = await tokenToUser(req); - where = idRole === 5 ? {} : { idUnit }; + const unitFilter = idRole === 5 ? {} : { idUnit }; + where = { + ...filterByName(req), + ...unitFilter, + }; } else { where = {}; } + const { limit, offset } = req.query; const flows = limit ? await Flow.findAll({ - where, - offset: parseInt(offset), - limit: parseInt(limit), - }) + where, + offset: parseInt(offset), + limit: parseInt(limit), + }) : await Flow.findAll({ - where, - }); + where, + }); const totalCount = await Flow.count({ where }); const totalPages = Math.ceil(totalCount / limit); From e604c97beb61342fdf0aff96837764ff8126f100 Mon Sep 17 00:00:00 2001 From: Oscar de Brito Date: Sun, 2 Jul 2023 20:53:39 -0300 Subject: [PATCH 02/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona filtro no ProcessController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: YanWerlley Co-authored-by: Sérgio Cipriano --- src/controllers/ProcessController.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProcessController.js b/src/controllers/ProcessController.js index 88421a87..e3833b7e 100644 --- a/src/controllers/ProcessController.js +++ b/src/controllers/ProcessController.js @@ -7,6 +7,7 @@ import Stage from "../models/Stage.js"; import Database from "../database/index.js"; import { QueryTypes } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; +import { filterByNicknameAndRecord } from "../utils/filters.js" const isRecordValid = (record) => { const regex = /^\d{20}$/; @@ -49,7 +50,11 @@ class ProcessController { let where; if (req.headers.test !== "ok") { const { idUnit, idRole } = await tokenToUser(req); - where = idRole === 5 ? {} : { idUnit }; + const unitFilter = idRole === 5 ? {} : { idUnit }; + where = { + ...filterByNicknameAndRecord(req), + ...unitFilter, + }; } else { where = {}; } @@ -247,7 +252,7 @@ class ProcessController { type: QueryTypes.SELECT, } ); - + const totalCount = countQuery[0].total; const totalPages = Math.ceil(totalCount / limit) || 0; From 5f08c5dd3e646215191ceb3947a480b1c20f0eda Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 20:37:22 -0300 Subject: [PATCH 03/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona filtro no StageController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: Sérgio Cipriano --- src/controllers/StageController.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/StageController.js b/src/controllers/StageController.js index 9c767d5e..05361e39 100644 --- a/src/controllers/StageController.js +++ b/src/controllers/StageController.js @@ -2,13 +2,18 @@ import Stage from "../models/Stage.js"; import FlowStage from "../models/FlowStage.js"; import { Op } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; +import { filterByName } from "../utils/filters.js" class StageController { async index(req, res) { let where; if (req.headers.test !== "ok") { const { idUnit, idRole } = await tokenToUser(req); - where = idRole === 5 ? {} : { idUnit }; + const unitFilter = idRole === 5 ? {} : { idUnit }; + where = { + ...filterByName(req), + ...unitFilter, + }; } else { where = {}; } From 23658d69d6ce71a1a469c9b45e8fefa1799a25b4 Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 20:38:10 -0300 Subject: [PATCH 04/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona filtro no UnitController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: Sérgio Cipriano --- src/controllers/UnitController.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controllers/UnitController.js b/src/controllers/UnitController.js index e4dcb711..a0e9f2a7 100644 --- a/src/controllers/UnitController.js +++ b/src/controllers/UnitController.js @@ -1,11 +1,16 @@ import Unit from "../models/Unit.js"; import User from "../models/User.js"; import { ROLE } from "../schemas/role.js"; +import { filterByName } from "../utils/filters.js" class UnitController { async index(req, res) { try { + const where = { + ...filterByName(req), + }; const units = await Unit.findAll({ + where, offset: req.query.offset, limit: req.query.limit, }); From 95d7a25daffdf69fd6b26dd1e2b0a1094135da69 Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 20:38:51 -0300 Subject: [PATCH 05/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona filtro no UserController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: Sérgio Cipriano --- src/controllers/UserContoller.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/UserContoller.js b/src/controllers/UserContoller.js index 1a204617..d59c0643 100644 --- a/src/controllers/UserContoller.js +++ b/src/controllers/UserContoller.js @@ -2,6 +2,7 @@ import { tokenToUser } from "../middleware/authMiddleware.js"; import { Op } from "sequelize"; import User from "../models/User.js"; import jwt from "jsonwebtoken"; +import { filterByFullName } from "../utils/filters.js" const cpfFilter = (cpf) => cpf.replace(/[^0-9]/g, ""); const jwtToken = process.env.JWT_SECRET || "ABC"; @@ -11,6 +12,7 @@ const generateToken = (id) => { expiresIn: "3d", }); }; + class UserController { async login(req, res) { try { @@ -81,7 +83,11 @@ class UserController { let where; if (req.headers.test !== "ok") { const { idUnit, idRole } = await tokenToUser(req); - where = idRole === 5 ? {} : { idUnit }; + const unitFilter = idRole === 5 ? {} : { idUnit }; + where = { + ...filterByFullName(req), + ...unitFilter, + }; } else { where = {}; } From beae14d85a5f14d5a9403e1f7c235b9877afb5ae Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 20:39:56 -0300 Subject: [PATCH 06/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona rotas dos filtros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: Sérgio Cipriano --- src/routes.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index f29dd5d2..9e856e01 100644 --- a/src/routes.js +++ b/src/routes.js @@ -10,7 +10,7 @@ import { ROLE } from "./schemas/role.js"; const routes = Router(); -routes.get("/", (req, res) => { +routes.get("/", (_req, res) => { res.json({ status: "OK", message: "Up and running", @@ -21,6 +21,7 @@ routes.get("/priorities", ProcessController.getPriorities); //Rotas de processos routes.get("/processes", ProcessController.index); +routes.get("/processes/:filter", ProcessController.index); routes.get( "/processes/:idFlow", protect, @@ -68,6 +69,8 @@ routes.get("/flows/process/:record", FlowController.indexByRecord); routes.get("/flows", FlowController.index); +routes.get("/flows/:filter", FlowController.index); + routes.get("/flow/:idFlow", FlowController.getById); routes.get("/flowStages", FlowController.getFlowStages); @@ -88,6 +91,8 @@ routes.post("/newStage", StageController.store); routes.get("/stages", StageController.index); +routes.get("/stages/:filter", StageController.index); + routes.get("/stage/:id", StageController.getById); routes.delete("/deleteStage/:id", StageController.delete); @@ -97,6 +102,8 @@ routes.post("/newUnit", UnitController.store); routes.get("/units", UnitController.index); +routes.get("/units/:filter", UnitController.index); + routes.put("/setUnitAdmin", UnitController.setUnitAdmin); routes.put("/removeUnitAdmin", UnitController.removeUnitAdmin); From af2deb146aec7cba32c30c67732be2c4f4aa34a7 Mon Sep 17 00:00:00 2001 From: Oscar de Brito Date: Sun, 2 Jul 2023 20:58:10 -0300 Subject: [PATCH 07/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona rotas dos filtros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: YanWerlley Co-authored-by: Sérgio Cipriano --- src/utils/filters.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/utils/filters.js diff --git a/src/utils/filters.js b/src/utils/filters.js new file mode 100644 index 00000000..46d9406c --- /dev/null +++ b/src/utils/filters.js @@ -0,0 +1,31 @@ +import { Op } from "sequelize"; + +export function filterByNicknameAndRecord(req) { + const { filter } = req.query; + return filter + ? { + [Op.or]: [ + { record: { [Op.like]: `%${filter}%` } }, + { nickname: { [Op.like]: `%${filter}%` } }, + ], + } + : {}; +} + +export function filterByName(req) { + const { filter } = req.query; + return filter + ? { + [Op.or]: [{ name: { [Op.like]: `%${filter}%` } }], + } + : {}; +} + +export function filterByFullName(req) { + const { filter } = req.query; + return filter + ? { + [Op.or]: [{ fullName: { [Op.like]: `%${filter}%` } }], + } + : {}; +} From bb1eab84b0014dc30c8b31201ef1dbdf8fb12cd7 Mon Sep 17 00:00:00 2001 From: Oscar de Brito Date: Sun, 2 Jul 2023 21:04:36 -0300 Subject: [PATCH 08/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona teste do filtro por nickname e record MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: YanWerlley Co-authored-by: Sérgio Cipriano --- src/tests/__tests__/test_filters.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/tests/__tests__/test_filters.js diff --git a/src/tests/__tests__/test_filters.js b/src/tests/__tests__/test_filters.js new file mode 100644 index 00000000..1d52caac --- /dev/null +++ b/src/tests/__tests__/test_filters.js @@ -0,0 +1,23 @@ +import "sequelize"; +import { Op } from "sequelize"; +import { + filterByNicknameAndRecord, +} from "../../utils/filters.js"; + +describe("filter test", () => { + test("test filterByNicknameAndRecord", async () => { + const filter = "123"; + const expectFilter = { + [Op.or]: [ + { record: { [Op.like]: `%${filter}%` } }, + { nickname: { [Op.like]: `%${filter}%` } }, + ], + }; + const sendedObject = { + query: { + filter: filter, + }, + }; + expect(filterByNicknameAndRecord(sendedObject)).toEqual(expectFilter); + }); +}); \ No newline at end of file From cbb985aac15c202c3ff348e56f222a0d72d631c8 Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 21:08:31 -0300 Subject: [PATCH 09/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona teste do filtro por nome MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: Sérgio Cipriano --- src/tests/__tests__/test_filters.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests/__tests__/test_filters.js b/src/tests/__tests__/test_filters.js index 1d52caac..0054fb04 100644 --- a/src/tests/__tests__/test_filters.js +++ b/src/tests/__tests__/test_filters.js @@ -1,6 +1,7 @@ import "sequelize"; import { Op } from "sequelize"; import { + filterByName, filterByNicknameAndRecord, } from "../../utils/filters.js"; @@ -20,4 +21,17 @@ describe("filter test", () => { }; expect(filterByNicknameAndRecord(sendedObject)).toEqual(expectFilter); }); + + test("test filterByName", async () => { + const filter = "teste"; + const expectFilter = { + [Op.or]: [{ name: { [Op.like]: `%${filter}%` } }], + }; + const sendedObject = { + query: { + filter: filter, + }, + }; + expect(filterByName(sendedObject)).toEqual(expectFilter); + }); }); \ No newline at end of file From 6e57bf92c5ad4e21edef60ca5483aa7ecf96e7a3 Mon Sep 17 00:00:00 2001 From: Sergio de Almeida Cipriano Junior Date: Sun, 2 Jul 2023 21:14:23 -0300 Subject: [PATCH 10/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Executa prettify Co-authored-by: OscarDeBrito Co-authored-by: YanWerlley --- src/controllers/FlowController.js | 14 +++++++------- src/controllers/ProcessController.js | 12 ++++++------ src/controllers/StageController.js | 2 +- src/controllers/UnitController.js | 2 +- src/controllers/UserContoller.js | 2 +- src/tests/__tests__/test_filters.js | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/controllers/FlowController.js b/src/controllers/FlowController.js index cf3c422f..f20f98c1 100644 --- a/src/controllers/FlowController.js +++ b/src/controllers/FlowController.js @@ -6,7 +6,7 @@ import FlowUser from "../models/FlowUser.js"; import FlowProcess from "../models/FlowProcess.js"; import { QueryTypes } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; -import { filterByName } from "../utils/filters.js" +import { filterByName } from "../utils/filters.js"; class FlowController { static #stagesSequencesFromFlowStages(flowStages) { @@ -157,13 +157,13 @@ class FlowController { const flows = limit ? await Flow.findAll({ - where, - offset: parseInt(offset), - limit: parseInt(limit), - }) + where, + offset: parseInt(offset), + limit: parseInt(limit), + }) : await Flow.findAll({ - where, - }); + where, + }); const totalCount = await Flow.count({ where }); const totalPages = Math.ceil(totalCount / limit); diff --git a/src/controllers/ProcessController.js b/src/controllers/ProcessController.js index e3833b7e..96ec6a66 100644 --- a/src/controllers/ProcessController.js +++ b/src/controllers/ProcessController.js @@ -7,7 +7,7 @@ import Stage from "../models/Stage.js"; import Database from "../database/index.js"; import { QueryTypes } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; -import { filterByNicknameAndRecord } from "../utils/filters.js" +import { filterByNicknameAndRecord } from "../utils/filters.js"; const isRecordValid = (record) => { const regex = /^\d{20}$/; @@ -296,9 +296,9 @@ class ProcessController { const startingProcess = process.status === "notStarted" && status === "inProgress" ? { - idStage: flowStages[0].idStageA, - effectiveDate: new Date(), - } + idStage: flowStages[0].idStageA, + effectiveDate: new Date(), + } : {}; let tempProgress = []; if (process.status === "notStarted" && status === "inProgress") { @@ -310,7 +310,7 @@ class ProcessController { const stageEndDate = new Date(stageStartDate); stageEndDate.setDate( stageEndDate.getDate() + - handleVerifyDate(stageStartDate, currentStage.duration) + handleVerifyDate(stageStartDate, currentStage.duration) ); const progressData = { @@ -435,7 +435,7 @@ class ProcessController { const stageEndDate = new Date(stageStartDate); stageEndDate.setDate( stageEndDate.getDate() + - handleVerifyDate(stageStartDate, currentToStage.duration) + handleVerifyDate(stageStartDate, currentToStage.duration) ); maturityDate = stageEndDate; diff --git a/src/controllers/StageController.js b/src/controllers/StageController.js index 05361e39..a985e920 100644 --- a/src/controllers/StageController.js +++ b/src/controllers/StageController.js @@ -2,7 +2,7 @@ import Stage from "../models/Stage.js"; import FlowStage from "../models/FlowStage.js"; import { Op } from "sequelize"; import { tokenToUser } from "../middleware/authMiddleware.js"; -import { filterByName } from "../utils/filters.js" +import { filterByName } from "../utils/filters.js"; class StageController { async index(req, res) { diff --git a/src/controllers/UnitController.js b/src/controllers/UnitController.js index a0e9f2a7..96851200 100644 --- a/src/controllers/UnitController.js +++ b/src/controllers/UnitController.js @@ -1,7 +1,7 @@ import Unit from "../models/Unit.js"; import User from "../models/User.js"; import { ROLE } from "../schemas/role.js"; -import { filterByName } from "../utils/filters.js" +import { filterByName } from "../utils/filters.js"; class UnitController { async index(req, res) { diff --git a/src/controllers/UserContoller.js b/src/controllers/UserContoller.js index d59c0643..4ccdc43f 100644 --- a/src/controllers/UserContoller.js +++ b/src/controllers/UserContoller.js @@ -2,7 +2,7 @@ import { tokenToUser } from "../middleware/authMiddleware.js"; import { Op } from "sequelize"; import User from "../models/User.js"; import jwt from "jsonwebtoken"; -import { filterByFullName } from "../utils/filters.js" +import { filterByFullName } from "../utils/filters.js"; const cpfFilter = (cpf) => cpf.replace(/[^0-9]/g, ""); const jwtToken = process.env.JWT_SECRET || "ABC"; diff --git a/src/tests/__tests__/test_filters.js b/src/tests/__tests__/test_filters.js index 0054fb04..45ba7976 100644 --- a/src/tests/__tests__/test_filters.js +++ b/src/tests/__tests__/test_filters.js @@ -34,4 +34,4 @@ describe("filter test", () => { }; expect(filterByName(sendedObject)).toEqual(expectFilter); }); -}); \ No newline at end of file +}); From 9b19e04436508b92e4938a6902be9181ef3537a8 Mon Sep 17 00:00:00 2001 From: YanWerlley Date: Sun, 2 Jul 2023 21:28:16 -0300 Subject: [PATCH 11/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Adiciona teste do filtro por fullname Co-authored-by: OscarDeBrito --- src/tests/__tests__/test_filters.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests/__tests__/test_filters.js b/src/tests/__tests__/test_filters.js index 45ba7976..899a54d3 100644 --- a/src/tests/__tests__/test_filters.js +++ b/src/tests/__tests__/test_filters.js @@ -3,6 +3,7 @@ import { Op } from "sequelize"; import { filterByName, filterByNicknameAndRecord, + filterByFullName, } from "../../utils/filters.js"; describe("filter test", () => { @@ -34,4 +35,17 @@ describe("filter test", () => { }; expect(filterByName(sendedObject)).toEqual(expectFilter); }); + + test("test filterByFullname", async () => { + const filter = "Teste silva"; + const expectFilter = { + [Op.or]: [{ fullName: { [Op.like]: `%${filter}%` } }], + }; + const sendedObject = { + query: { + filter: filter, + }, + }; + expect(filterByFullName(sendedObject)).toEqual(expectFilter); + }); }); From fc8b23ed58380f7c39c3245c9023b5f3a00e1cc9 Mon Sep 17 00:00:00 2001 From: Sergio de Almeida Cipriano Junior Date: Sun, 2 Jul 2023 21:47:08 -0300 Subject: [PATCH 12/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Testes para casos sem filtro Co-authored-by: OscarDeBrito Co-authored-by: YanWerlley --- src/tests/__tests__/test_filters.js | 116 ++++++++++++++++++---------- 1 file changed, 77 insertions(+), 39 deletions(-) diff --git a/src/tests/__tests__/test_filters.js b/src/tests/__tests__/test_filters.js index 899a54d3..3d4dc109 100644 --- a/src/tests/__tests__/test_filters.js +++ b/src/tests/__tests__/test_filters.js @@ -1,51 +1,89 @@ -import "sequelize"; import { Op } from "sequelize"; import { - filterByName, filterByNicknameAndRecord, + filterByName, filterByFullName, } from "../../utils/filters.js"; -describe("filter test", () => { - test("test filterByNicknameAndRecord", async () => { - const filter = "123"; - const expectFilter = { - [Op.or]: [ - { record: { [Op.like]: `%${filter}%` } }, - { nickname: { [Op.like]: `%${filter}%` } }, - ], - }; - const sendedObject = { - query: { - filter: filter, - }, - }; - expect(filterByNicknameAndRecord(sendedObject)).toEqual(expectFilter); +describe("filters", () => { + describe("filterByNicknameAndRecord", () => { + it("should return the correct filter object when filter is provided", () => { + const req = { + query: { + filter: "John", + }, + }; + + const result = filterByNicknameAndRecord(req); + + expect(result).toEqual({ + [Op.or]: [ + { record: { [Op.like]: "%John%" } }, + { nickname: { [Op.like]: "%John%" } }, + ], + }); + }); + + it("should return an empty object when filter is not provided", () => { + const req = { + query: {}, + }; + + const result = filterByNicknameAndRecord(req); + + expect(result).toEqual({}); + }); }); - test("test filterByName", async () => { - const filter = "teste"; - const expectFilter = { - [Op.or]: [{ name: { [Op.like]: `%${filter}%` } }], - }; - const sendedObject = { - query: { - filter: filter, - }, - }; - expect(filterByName(sendedObject)).toEqual(expectFilter); + describe("filterByName", () => { + it("should return the correct filter object when filter is provided", () => { + const req = { + query: { + filter: "Smith", + }, + }; + + const result = filterByName(req); + + expect(result).toEqual({ + [Op.or]: [{ name: { [Op.like]: "%Smith%" } }], + }); + }); + + it("should return an empty object when filter is not provided", () => { + const req = { + query: {}, + }; + + const result = filterByName(req); + + expect(result).toEqual({}); + }); }); - test("test filterByFullname", async () => { - const filter = "Teste silva"; - const expectFilter = { - [Op.or]: [{ fullName: { [Op.like]: `%${filter}%` } }], - }; - const sendedObject = { - query: { - filter: filter, - }, - }; - expect(filterByFullName(sendedObject)).toEqual(expectFilter); + describe("filterByFullName", () => { + it("should return the correct filter object when filter is provided", () => { + const req = { + query: { + filter: "John Doe", + }, + }; + + const result = filterByFullName(req); + + expect(result).toEqual({ + [Op.or]: [{ fullName: { [Op.like]: "%John Doe%" } }], + }); + }); + + it("should return an empty object when filter is not provided", () => { + const req = { + query: {}, + }; + + const result = filterByFullName(req); + + expect(result).toEqual({}); + }); }); }); From 651bfe254e8575d065b4c66c87a88c83d25f3d36 Mon Sep 17 00:00:00 2001 From: Sergio de Almeida Cipriano Junior Date: Sun, 2 Jul 2023 21:56:31 -0300 Subject: [PATCH 13/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Remove console.log usado para teste Co-authored-by: OscarDeBrito Co-authored-by: YanWerlley --- src/controllers/ProcessController.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controllers/ProcessController.js b/src/controllers/ProcessController.js index 96ec6a66..5a8c2b49 100644 --- a/src/controllers/ProcessController.js +++ b/src/controllers/ProcessController.js @@ -352,7 +352,6 @@ class ProcessController { return res.status(200).json({ process, flows: flowProcesses }); } catch (error) { - console.log(error); return res.status(500).json(error); } } @@ -487,7 +486,6 @@ class ProcessController { message: `Impossível atualizar processo '${record}' para etapa '${to}`, }); } catch (error) { - console.log(error); return res.status(500).json({ error, message: `Erro ao atualizar processo '${record}' para etapa '${to}`, From 043210a1525e107f76384b9c16335f170fb8cffe Mon Sep 17 00:00:00 2001 From: Sergio de Almeida Cipriano Junior Date: Sun, 2 Jul 2023 23:21:08 -0300 Subject: [PATCH 14/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Aumenta cobertura Co-authored-by: OscarDeBrito Co-authored-by: YanWerlley --- src/utils/filters.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/utils/filters.js b/src/utils/filters.js index 46d9406c..69c6e7a4 100644 --- a/src/utils/filters.js +++ b/src/utils/filters.js @@ -1,31 +1,28 @@ import { Op } from "sequelize"; export function filterByNicknameAndRecord(req) { - const { filter } = req.query; - return filter + return req.query.filter ? { [Op.or]: [ - { record: { [Op.like]: `%${filter}%` } }, - { nickname: { [Op.like]: `%${filter}%` } }, + { record: { [Op.like]: `%${req.query.filter}%` } }, + { nickname: { [Op.like]: `%${req.query.filter}%` } }, ], } : {}; } export function filterByName(req) { - const { filter } = req.query; - return filter + return req.query.filter ? { - [Op.or]: [{ name: { [Op.like]: `%${filter}%` } }], + [Op.or]: [{ name: { [Op.like]: `%${req.query.filter}%` } }], } : {}; } export function filterByFullName(req) { - const { filter } = req.query; - return filter + return req.query.filter ? { - [Op.or]: [{ fullName: { [Op.like]: `%${filter}%` } }], + [Op.or]: [{ fullName: { [Op.like]: `%${req.query.filter}%` } }], } : {}; } From a805b07d16c2b5552350836473c3744988fe84cf Mon Sep 17 00:00:00 2001 From: Sergio de Almeida Cipriano Junior Date: Sun, 2 Jul 2023 23:54:49 -0300 Subject: [PATCH 15/15] (fga-eps-mds/2023-1-CAPJu-Doc#122) - Testa caso de senha errada MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: OscarDeBrito Co-authored-by: YanWerlley Co-authored-by: Vinícius Vieira de Souza --- src/tests/__tests__/test_user_routes.js | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/tests/__tests__/test_user_routes.js b/src/tests/__tests__/test_user_routes.js index 87df0bdc..372b442d 100644 --- a/src/tests/__tests__/test_user_routes.js +++ b/src/tests/__tests__/test_user_routes.js @@ -774,6 +774,32 @@ describe("user endpoints", () => { expect(response.body.message).toBe("Usuário inexistente"); }); + it("should return error for wrong password", async () => { + const testUser = { + fullName: "Nomen Nomes", + cpf: "86891382424", + email: "aaa@bb.com", + password: "spw123456", + idUnit: 1, + idRole: 3, + }; + + await supertest(app).post("/newUser").send(testUser); + + await supertest(app).post(`/acceptRequest/${testUser.cpf}`); + + const response = await supertest(app) + .post("/login") + .send({ + cpf: testUser.cpf, + password: "senha_qualquer", + }) + .expect(401); + + expect(response.body.message).toBe("Senha ou usuário incorretos"); + expect(response.body.error).toBe("Impossível autenticar"); + }); + test("get all users", async () => { const testUser = { fullName: "Nomenni Nomesos",