Skip to content

Commit

Permalink
RED-85 resolvido bug introduzido pelas transferências internas
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jun 9, 2024
1 parent f1bb5d5 commit 74887d0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 49 deletions.
8 changes: 8 additions & 0 deletions service-node-koa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ There are npm scripts to help on database migration:
```bash
npm run migrate:make new_script # give a proper name for the migrate
```

```bash
npm run migrate:latest # apply all pending migrates
```

```bash
npm run migrate:rollback # undo latest applied migrate batch
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export const up = async (knex) =>
knex.schema.table('movimentacao', tb => {
tb.dropNullable('categoria_id')
tb.foreign('categoria_id').references('categoria.id').onDelete('cascade')
tb.boolean('interna').defaultTo(false)
.comment('indica uma movimentação entre contas')
})
Expand Down
4 changes: 4 additions & 0 deletions service-node-koa/app/controllers/movimentacao.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("Movimentacao API test", () => {
const novaMovimentacao = {
tipo_movimentacao_id: 1,
descricao: "Teste movimentação",
categoria_id: categoria.id,
conta_id: conta.id,
valor: 100,
vencimento: "2024-02-04",
Expand All @@ -99,6 +100,7 @@ describe("Movimentacao API test", () => {
const novaMovimentacao = {
tipo_movimentacao_id: 1,
descricao: "Test movimentação",
categoria_id: categoria.id,
conta_id: conta.id,
valor: 100,
vencimento: "2024-02-04",
Expand All @@ -123,6 +125,7 @@ describe("Movimentacao API test", () => {
const novaMovimentacao = {
tipo_movimentacao_id: 1,
descricao: "Test movimentação",
categoria_id: categoria.id,
conta_id: conta.id,
valor: 100,
vencimento: "2024-02-04",
Expand Down Expand Up @@ -153,6 +156,7 @@ describe("Movimentacao API test", () => {
const novaMovimentacao = {
tipo_movimentacao_id: 1,
descricao: "Test movimentação",
categoria_id: categoria.id,
conta_id: conta.id,
valor: 100,
vencimento: "2024-02-04",
Expand Down
6 changes: 3 additions & 3 deletions service-node-koa/app/controllers/recorrencia.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
delRecorrencia,
findRecorrencia, geraLancamentos,
findRecorrencia,
geraLancamentos,
insertRecorrencia,
listRecorrencia,
updateRecorrencia
Expand Down Expand Up @@ -36,6 +37,5 @@ export const delRecorrenciaRequest = async ctx => {

export const geraLancamentosRequest = async ctx => {
const { usuario_id, id } = ctx.request.params
const result = await geraLancamentos({ usuario_id, id })
ctx.body = result
ctx.body = await geraLancamentos({ usuario_id, id })
}
101 changes: 55 additions & 46 deletions service-node-koa/app/controllers/recorrencia.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,107 +1,116 @@
import chai from 'chai'
import chaiHttp from 'chai-http'

import {app} from '../main.mjs'
import { app } from '../main.mjs'
import {
findRecorrencia,
getAdmin,
insertRecorrencia,
insertRecorrencia, listCategorias,
listContas,
listMovimentacaoByConta,
resetConta
} from "../services/index.mjs";
import {sign} from "../config/security/index.mjs";
import {endOfYear, startOfYear} from "date-fns";
} from '../services/index.mjs'
import { sign } from '../config/security/index.mjs'
import { endOfYear, startOfYear } from 'date-fns'

chai.should();
chai.use(chaiHttp);
chai.should()
chai.use(chaiHttp)

describe("Recorrencia API requests", () => {
describe('Recorrencia API requests', () => {

let user;
let authorization;
let conta;
let user
let authorization
let conta
let categoria

before(async () => {
user = await getAdmin()
await resetConta({usuario_id: user.id})
const {token} = sign(user)
await resetConta({ usuario_id: user.id })
const { token } = sign(user)
authorization = `Bearer ${token}`
conta = (await listContas({usuario_id: user.id}))[0]
conta = (await listContas({ usuario_id: user.id }))[0]
categoria = (await listCategorias({ usuario_id: user.id }))[0]
})

it("Should list recorrencias", async () => {
it('Should list recorrencias', async () => {
try {
const res = await chai
.request(app.callback())
.get(`/${user.id}/recorrencia`)
.set("Authorization", authorization)
res.should.have.status(200);
res.body.should.be.an("array");
.set('Authorization', authorization)
res.should.have.status(200)
res.body.should.be.an('array')
} catch (e) {
chai.expect.fail(e)
}
})

it("Should insert recorrencia", async () => {
const novaRecorrencia = {tipo_recorrencia_id: 1, conta_id: conta.id, descricao: "nova", valorParcela: 100.50}
it('Should insert recorrencia', async () => {
const novaRecorrencia = {
tipo_recorrencia_id: 1,
conta_id: conta.id,
categoria_id: categoria.id,
descricao: 'nova',
valorParcela: 100.50
}
const res = await chai
.request(app.callback())
.post(`/${user.id}/recorrencia`)
.send(novaRecorrencia)
.set("Authorization", authorization)
res.should.have.status(200);
res.body.should.be.an("array"); // [{id:1}]
.set('Authorization', authorization)
res.should.have.status(200)
res.body.should.be.an('array') // [{id:1}]
})

it("Should find recorrencia", async () => {
const [{id}] = await insertRecorrencia({
recorrencia: {tipo_recorrencia_id: 1, conta_id: conta.id, descricao: "nova", valorParcela: 100.50}
it('Should find recorrencia', async () => {
const [{ id }] = await insertRecorrencia({
recorrencia: { tipo_recorrencia_id: 1, conta_id: conta.id, descricao: 'nova', valorParcela: 100.50 }
})
const res = await chai
.request(app.callback())
.get(`/${user.id}/recorrencia/${id}`)
.set("Authorization", authorization)
res.should.have.status(200);
res.body.should.be.an("object");
.set('Authorization', authorization)
res.should.have.status(200)
res.body.should.be.an('object')
res.body.id.should.be.eq(id)
})

it("Should update recorrencia", async () => {
const [{id}] = await insertRecorrencia({
recorrencia: {tipo_recorrencia_id: 1, conta_id: conta.id, descricao: "nova", valorParcela: 100.50}
it('Should update recorrencia', async () => {
const [{ id }] = await insertRecorrencia({
recorrencia: { tipo_recorrencia_id: 1, conta_id: conta.id, descricao: 'nova', valorParcela: 100.50 }
})
const res = await chai
.request(app.callback())
.put(`/${user.id}/recorrencia/${id}`)
.set("Authorization", authorization)
.send({descricao: "atualizada"})
.set('Authorization', authorization)
.send({ descricao: 'atualizada' })
res.should.have.status(200)
res.body.should.be.ok
const recorrencia = await findRecorrencia({id})
recorrencia.descricao.should.be.eq("atualizada")
const recorrencia = await findRecorrencia({ id })
recorrencia.descricao.should.be.eq('atualizada')
})

it("should delete recorrencia", async () => {
const [{id}] = await insertRecorrencia({
recorrencia: {tipo_recorrencia_id: 1, conta_id: conta.id, descricao: "nova", valorParcela: 100.50}
it('should delete recorrencia', async () => {
const [{ id }] = await insertRecorrencia({
recorrencia: { tipo_recorrencia_id: 1, conta_id: conta.id, descricao: 'nova', valorParcela: 100.50 }
})
const res = await chai
.request(app.callback())
.del(`/${user.id}/recorrencia/${id}`)
.set("Authorization", authorization)
.set('Authorization', authorization)
res.should.have.status(200)
res.body.should.be.ok
const recorrencia = await findRecorrencia({id})
const recorrencia = await findRecorrencia({ id })
chai.expect(recorrencia).to.be.undefined
})

it("should check generated parcels", async () => {
const [{id}] = await insertRecorrencia({
it('should check generated parcels', async () => {
const [{ id }] = await insertRecorrencia({
recorrencia: {
tipo_recorrencia_id: 1,
conta_id: conta.id,
descricao: "ver parcelas",
categoria_id: categoria.id,
descricao: 'ver parcelas',
valorParcela: 100.50,
inicial: startOfYear(new Date()),
final: endOfYear(new Date())
Expand All @@ -111,11 +120,11 @@ describe("Recorrencia API requests", () => {
const res = await chai
.request(app.callback())
.get(`/${user.id}/recorrencia/${id}/lancamentos`)
.set("Authorization", authorization)
.set('Authorization', authorization)
res.should.have.status(200)
res.body.should.be.ok

const parcelas = await listMovimentacaoByConta({conta_id: conta.id})
const parcelas = await listMovimentacaoByConta({ conta_id: conta.id })
parcelas.should.be.ok
parcelas.should.be.an('array')
parcelas.length.should.be.eq(12)
Expand Down
2 changes: 2 additions & 0 deletions service-node-koa/app/services/movimentacao.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ describe('Movimentacao service test', () => {
it('Should save a new movimentacao', async () => {
const usuario = await getAdmin()
const [conta] = await listContas({ usuario_id: usuario.id })
const [categoria] = await listCategorias({ usuario_id: usuario.id, q: 'OUTROS' })
const result = await novaEntrada({
categoria_id: categoria.id,
conta_id: conta.id,
valor: 200,
descricao: 'teste dinheiro 2'
Expand Down

0 comments on commit 74887d0

Please sign in to comment.