-
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 #19 from fga-eps-mds/develop
Minor Release
- Loading branch information
Showing
31 changed files
with
621 additions
and
27 deletions.
There are no files selected for viewing
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
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,139 @@ | ||
const modelTronco = require("../../../models/Tronco"); | ||
const modelLingua = require("../../../models/Lingua"); | ||
const modelConteudo = require("../../../models/Conteudo"); | ||
require("../../../database"); | ||
|
||
describe("\n## TESTES TRONCO\n", () => { | ||
const troncoName = "Macro-Jê123"; | ||
const linguaNome = ["tupi-guarani", "tupi-guarani2"]; | ||
|
||
describe("Listagem de Tronco", () => { | ||
it("Listando com metodo getAll() com banco vazio", async () => { | ||
const tronco = await modelTronco.getAll(); | ||
expect(tronco.length).toEqual(0); | ||
}); | ||
it("Listando com metodo searchByID(1) com banco vazio", async () => { | ||
const tronco = await modelTronco.searchById(1); | ||
expect(tronco).toEqual(null); | ||
}); | ||
}); | ||
describe("Criação de Tronco", () => { | ||
it("Criando tronco com o metodo create() - 1", async () => { | ||
const tronco = await modelTronco.create({ nome: "Macro-Jê" }); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 1, | ||
nome: "Macro-Jê", | ||
id_conteudo: 8, | ||
}); | ||
}); | ||
it("Criando tronco com o metodo create() - 2", async () => { | ||
const tronco = await modelTronco.create({ nome: "Macro-Jê1" }); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 2, | ||
nome: "Macro-Jê1", | ||
id_conteudo: 9, | ||
}); | ||
}); | ||
}); | ||
describe("Atualização de Tronco", () => { | ||
it("Atualizando tronco, com o metodo searchById(1)", async () => { | ||
await modelTronco.editById({ nome: "Macro-Jê12" }, 1); | ||
const tronco = await modelTronco.searchById(1); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 1, | ||
nome: "Macro-Jê12", | ||
id_conteudo: 8, | ||
linguas: [], | ||
}); | ||
}); | ||
it("Atualizando tronco, com o metodo searchById(2)", async () => { | ||
await modelTronco.editById({ nome: troncoName }, 2); | ||
const tronco = await modelTronco.searchById(2); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 2, | ||
nome: troncoName, | ||
id_conteudo: 9, | ||
linguas: [], | ||
}); | ||
}); | ||
}); | ||
describe("Deleção de Tronco", () => { | ||
it("Deletando Tronco, com o metodo delete(8) através do conteudo", async () => { | ||
await modelConteudo.delete(8); | ||
const tronco = await modelTronco.searchById(1); | ||
expect(tronco).toEqual(null); | ||
}); | ||
}); | ||
describe("Relacionamento Lingua e Tronco", () => { | ||
it("Criando lingua com um tronco - 1", async () => { | ||
const linguas = await modelLingua.create({ | ||
nome: linguaNome[0], | ||
id_tronco: 2, | ||
}); | ||
expect(linguas).toMatchObject({ | ||
id_conteudo: 10, | ||
id_tronco: 2, | ||
id_lingua: 4, | ||
nome: linguaNome[0], | ||
}); | ||
}); | ||
it("Listando tronco com relacionamento searchById(2) - 1", async () => { | ||
const tronco = await modelTronco.searchById(2); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 2, | ||
id_conteudo: 9, | ||
nome: troncoName, | ||
linguas: [ | ||
{ | ||
id_lingua: 4, | ||
id_conteudo: 10, | ||
nome: linguaNome[0], | ||
}, | ||
], | ||
}); | ||
}); | ||
it("Criando lingua com um tronco - 2", async () => { | ||
const linguas = await modelLingua.create({ | ||
nome: linguaNome[1], | ||
id_tronco: 2, | ||
}); | ||
expect(linguas).toMatchObject({ | ||
id_conteudo: 11, | ||
id_tronco: 2, | ||
id_lingua: 5, | ||
nome: linguaNome[1], | ||
}); | ||
}); | ||
it("Listando tronco com relacionamento searchById(2) - 2", async () => { | ||
const tronco = await modelTronco.searchById(2); | ||
expect(tronco).toMatchObject({ | ||
id_tronco: 2, | ||
id_conteudo: 9, | ||
nome: troncoName, | ||
linguas: [ | ||
{ | ||
id_lingua: 4, | ||
id_conteudo: 10, | ||
nome: linguaNome[0], | ||
}, | ||
{ | ||
id_lingua: 5, | ||
id_conteudo: 11, | ||
nome: linguaNome[1], | ||
}, | ||
], | ||
}); | ||
}); | ||
it("Resgatando tronco com id da lingua", async () => { | ||
const tronco = await modelTronco.getTrunkByLanguage(4); | ||
expect(tronco).toMatchObject({ | ||
id_lingua: 4, | ||
nome: linguaNome[0], | ||
tronco: { | ||
id_tronco: 2, | ||
nome: troncoName, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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,3 +1,4 @@ | ||
require("./Etnia"); | ||
require("./Lingua"); | ||
require("./Palavra"); | ||
require("./Tronco"); |
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,20 @@ | ||
import Tronco from "../../models/Tronco"; | ||
import { HttpException } from "../../error/HttpException"; | ||
|
||
export async function create(request, response) { | ||
const { nome } = request.body; | ||
if (!nome) { | ||
throw new HttpException(400, `Nome inválido - Tronco - ${nome}`); | ||
} | ||
|
||
const nameAlreadyExists = await Tronco.searchByName(nome); | ||
if (nameAlreadyExists) { | ||
throw new HttpException(400, `Nome já existente - Tronco - ${nome}`); | ||
} | ||
|
||
const tronco = await Tronco.create({ | ||
nome, | ||
}); | ||
|
||
response.send(tronco); | ||
} |
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,23 @@ | ||
import Tronco from "../../models/Tronco"; | ||
import { HttpException } from "../../error/HttpException"; | ||
import Conteudo from "../../models/Conteudo"; | ||
|
||
export async function deleteOne(request, response) { | ||
const { id_tronco } = request.params; | ||
if (!id_tronco) { | ||
throw new HttpException(400, `ID inválido - Tronco - ID ${id_tronco}`); | ||
} | ||
|
||
const troncoFound = await Tronco.searchById(id_tronco); | ||
if (!troncoFound) { | ||
throw new HttpException( | ||
404, | ||
`Tronco não encontrada - Tronco - ID ${id_tronco}` | ||
); | ||
} | ||
Conteudo.delete(troncoFound.id_conteudo); | ||
|
||
response.send({ | ||
Result: "Tronco deletado com sucesso", | ||
}); | ||
} |
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,11 @@ | ||
import Tronco from "../../models/Tronco"; | ||
import { HttpException } from "../../error/HttpException"; | ||
|
||
export async function getAll(request, response) { | ||
const etniasEncontrada = await Tronco.getAll(); | ||
if (!etniasEncontrada.length) { | ||
throw new HttpException(404, "Nenhum tronco encontrado - Tronco"); | ||
} | ||
|
||
response.send(etniasEncontrada); | ||
} |
Oops, something went wrong.