Skip to content

Commit

Permalink
Teste de unidade campos de empresa
Browse files Browse the repository at this point in the history
  • Loading branch information
staubjoao committed Mar 27, 2023
1 parent ad1ef4d commit 9cff246
Show file tree
Hide file tree
Showing 2,968 changed files with 48,909 additions and 1,013,659 deletions.
4 changes: 2 additions & 2 deletions backend/config/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"development": {
"username": "root",
"password": "Adminroot20*",
"password": "mysql",
"database": "busca_emprego",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": "Adminroot20*",
"password": "mysql",
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
Expand Down
214 changes: 22 additions & 192 deletions backend/controllers/curriculoController.js
Original file line number Diff line number Diff line change
@@ -1,195 +1,25 @@
const models = require('../models');
const { campos, getJSON } = require('../utils/curriculos');

const createItensModels = async (req, valueBody, model, value, candidato) => {
const getModel = models[`${model}`];

const promises = await Promise.all(
req.body[`${valueBody}`].map((itemModel) =>
getModel.create(getJSON(value, itemModel, candidato))
)
);

return promises;
};

const curriculo = {
createCurriculo: async (req, res) => {
const { idCandidato } = req.params;
const curriculos = models.Curriculo;
let candidato = await curriculos.findOne({
where: {
id: idCandidato,
const { listarCurriculoPorId } = require('./caminho/para/a/funcao/listarCurriculoPorId');

test('listarCurriculoPorId deve retornar o currículo correto', async () => {
const id = '1';
const resultadoEsperado = {
nome: 'Fulano de Tal',
idade: 30,
experienciaProfissional: [
{
empresa: 'Empresa A',
cargo: 'Analista de Sistemas',
periodo: '2010-2015'
},
});

try {
const itemsModels = await Promise.all(
campos.map(async (item) => {
return await createItensModels(
req,
item.valueBody,
item.model,
item.value,
candidato
);
})
);
const findEmptyItem = itemsModels.find((item) => item.length === 0);
if (findEmptyItem) {
return res.json({
message: 'Há campos vazios!',
ok: false,
});
{
empresa: 'Empresa B',
cargo: 'Gerente de Projetos',
periodo: '2015-2020'
}
return res.json({
message: 'Currículo salvo com sucesso!',
ok: true,
});
} catch (e) {
console.log('ERRP', e);
return res.json({
message: 'Que pena, algo deu errado :(',
ok: false,
});
}
},

listarCurriculos: async (req, res) => {
const curriculovaga = models.CurriculosVagas

await curriculovaga
.findAll({
where: { VagaId: req.params.idVaga },
include: [
{
model: models.Curriculo,
required: true
}
]
})
.then(curriculos => res.json({ curriculos }))
.catch(erro => {
return res.status(400).json({
error: true,
message: erro
})
})
},

listarCurriculo: async (req, res) => {
console.log(req.params.idCurriculo)
const curriculo = models.Curriculo
const cursos = models.Cursos
const experiencias = models.Experiencias
const idiomas = models.Idiomas
const idiomasCurriculo = models.CurriculosIdiomas
const cursosCurriculo = models.CurriculosCursos
const experienciasCurriculo = models.CurriculosExperiencias
const instituicao = models.Instituicao
const cursosInstituicoes = models.CursosInstituicoes

await curriculo.findOne({
where: { id: req.params.idCurriculo },
include: [
{
model: idiomas,
attributes: ['idioma'],
through: {
model: idiomasCurriculo,
attributes: ['nivel']
}
},
{
model: cursos,
attributes: ['curso'],
through: {
model: cursosCurriculo,
attributes: ['inicio', 'termino'],
},
include: [
{
model: instituicao,
attributes: ['nome', 'cidade', 'pais'],
tableName: 'Instituicoes',
through: {
attributes: [],
model: cursosInstituicoes,
}
}
]
},
{
model: experiencias,
attributes: ['empresa', 'endereco', 'ramo'],
through: {
model: experienciasCurriculo,
attributes: ['inicio', 'termino', 'cidade', 'pais', 'salario', 'cargo']
}
}
]
})
.then(curriculo => res.json({ curriculo }))
.catch(erro => {
return res.status(400).json({
error: true,
message: erro
})
})
},

candidatar: async (req, res) => {
const { idVaga, idCandidato } = req.body;

let vagaExists = await vaga.findOne({
where: {
id: idVaga,
},
});

let candidatoExists = await candidatoModel.findOne({
where: {
id: idCandidato,
},
});

if (!vagaExists) {
return res.json({ ok: false, data: 'Vaga não existe no banco' });
}

if (!candidatoExists) {
return res.json({ ok: false, data: 'Candidato(a) não existe no banco' });
}

let alreadyCandidato = await curriculoVaga.findOne({
where: {
VagaId: idVaga,
CurriculoId: idCandidato,
},
});

if (alreadyCandidato) {
return res.json({
ok: false,
data: 'Candidato(a) já se candidatou à vaga',
});
}

try {
const response = await curriculoVaga.create({
VagaId: idVaga,
CurriculoId: idCandidato,
});

res.json({ ok: true, data: 'Parabéns! Você se candidatou à vaga' });
} catch (e) {
res.status(500);
return res.json({
data: e,
ok: false,
});
}
},
};
]
};

module.exports = curriculo;
const resultadoObtido = await listarCurriculoPorId(id);

expect(resultadoObtido).toEqual(resultadoEsperado);
});
13 changes: 12 additions & 1 deletion backend/node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion backend/node_modules/.bin/browserslist-lint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions backend/node_modules/.bin/browserslist-lint.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions backend/node_modules/.bin/browserslist-lint.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions backend/node_modules/.bin/browserslist.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions backend/node_modules/.bin/browserslist.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion backend/node_modules/.bin/css-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions backend/node_modules/.bin/css-beautify.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9cff246

Please sign in to comment.