Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fontes/infraestrutura/roteador/roteador.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,20 @@

adicionarRotaToken() {
this.aplicacao.post('/token', (req: Request, res: any) => {
if (req.body.email && req.body.senha) {
const { email, senha } = req.body;
const usuario = users.find((u) => {
return u.email === email && u.senha === senha;
});
if (usuario) {
const payload = {
id: usuario.id
};
const token = jwt.encode(payload, devolverVariavelAmbiente('chaveSecreta') as string);
users.find((u) => u.id === usuario.id).token = token;
const user = users.find((u) => u.id === usuario.id);

Check warning on line 220 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 220 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 220 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (user) {
user.token = token;

Check warning on line 222 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 223 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 223 in fontes/infraestrutura/roteador/roteador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return res.json({ token });
} else {
res.sendStatus(401);
Expand Down
3 changes: 2 additions & 1 deletion fontes/liquido.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ export class Liquido implements LiquidoInterface {
.replace(new RegExp(`\\${caminho.sep}`, 'g'), '/')
.replace(new RegExp(`/$`, 'g'), '')
.replace(new RegExp(`\\[(.+)\\]`, 'g'), ':$1');
return rotaResolvida;

return rotaResolvida === '' ? '/' : rotaResolvida;
}

async analisarArquivo(arquivo: string): Promise<Declaracao[] | null> {
Expand Down
6 changes: 3 additions & 3 deletions testes/liquido.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Liquido', () => {
});

expect(expected.length).toBeGreaterThanOrEqual(2);
expect(expected[0]).toBe('');
expect(expected[0]).toBe('/');
expect(expected[1]).toBe('/middlewares');
});

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Liquido', () => {
await instanciaTeste.iniciar();

expect(instanciaTeste.arquivosPitugues.length).toBeGreaterThan(0);
expect(instanciaTeste.rotasPitugues).toContain('');
expect(instanciaTeste.rotasPitugues).toContain('/');

jest.restoreAllMocks();
});
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Liquido', () => {
);
const rota = liquido.resolverCaminhoRota(arquivo, 'pitugues');

expect(rota).toBe('');
expect(rota).toBe('/');
});

it('Deve remover extensão .pitu do caminho', () => {
Expand Down
2 changes: 1 addition & 1 deletion testes/middlewares-integracao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Testes de Integração - Middlewares', () => {
const arquivo = caminho.join(__dirname, 'exemplos', 'rotas', 'inicial.delegua');
const rota = liquido.resolverCaminhoRota(arquivo, 'delegua');

expect(rota).toBe('');
expect(rota).toBe('/');
});

it('Deve resolver caminho de arquivo em subdiretório', () => {
Expand Down
Loading