forked from fga-eps-mds/2022-2-CAPJu-Service
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #24 from fga-eps-mds/feat/122-remover-filtragem
Remove filtragem do lado do cliente
- Loading branch information
Showing
9 changed files
with
189 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Op } from "sequelize"; | ||
import { | ||
filterByNicknameAndRecord, | ||
filterByName, | ||
filterByFullName, | ||
} from "../../utils/filters.js"; | ||
|
||
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({}); | ||
}); | ||
}); | ||
|
||
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({}); | ||
}); | ||
}); | ||
|
||
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({}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -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: "[email protected]", | ||
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", | ||
|
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,28 @@ | ||
import { Op } from "sequelize"; | ||
|
||
export function filterByNicknameAndRecord(req) { | ||
return req.query.filter | ||
? { | ||
[Op.or]: [ | ||
{ record: { [Op.like]: `%${req.query.filter}%` } }, | ||
{ nickname: { [Op.like]: `%${req.query.filter}%` } }, | ||
], | ||
} | ||
: {}; | ||
} | ||
|
||
export function filterByName(req) { | ||
return req.query.filter | ||
? { | ||
[Op.or]: [{ name: { [Op.like]: `%${req.query.filter}%` } }], | ||
} | ||
: {}; | ||
} | ||
|
||
export function filterByFullName(req) { | ||
return req.query.filter | ||
? { | ||
[Op.or]: [{ fullName: { [Op.like]: `%${req.query.filter}%` } }], | ||
} | ||
: {}; | ||
} |