Skip to content

Commit

Permalink
fix transaction updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Jan 14, 2020
1 parent 7c05094 commit 8f4d84c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 35 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint": "eslint src --ext '.js,.jsx' --config .eslintrc",
"lint:fix": "npm run lint --fix",
"deploy:test": "npm run build && aws s3 sync build/ s3://entaxy-test --delete",
"postdeploy:test": "aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '/*'",
"deploy:staging": "npm run build && aws s3 sync build/ s3://staging.entaxy.io --delete",
"postdeploy:staging": "aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '/*'",
"deploy:production": "npm run build && aws s3 sync build/ s3://entaxy-production --delete",
Expand Down Expand Up @@ -143,4 +144,4 @@
}
}
}
}
}
1 change: 1 addition & 0 deletions src/core/Accounts/Transactions/TransactionDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ export default compose(
}
}

console.log({ ruleId: transaction.ruleId, rules: budget.rules })
const ruleAttributes = {}
if (transaction.ruleId) {
const rule = budget.rules[transaction.ruleId]
Expand Down
1 change: 0 additions & 1 deletion src/store/budget/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export default (state = initialState, { type, payload }) => {
return {
...state,
rules: {
...state.rules,
[payload.id]: payload
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/store/migrations/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid from 'uuid/v4'

const migrations = {
// Add accountType to accounts
0: (state) => {
Expand Down Expand Up @@ -45,6 +47,39 @@ const migrations = {
}, {})
}
}
// 3: (state) => {
// if (!state.budget) return state
// // collect accountIds
// state.transactions.list.forEach((transaction) => {
// if (transaction.categoryId === categoryId) {

// }
// })

// return {
// ...state,
// budget: {
// ...state.budget,
// rules: Object.keys(state.budget.rules).reduce((res, match) => {
// const ruleId = uuid()
// const { categoryId } = state.budget.rules[match]
// return {
// id: ruleId,
// accountId: account.id,
// attributes: { categoryId },
// filterBy: { description: { type: 'equals', value: match } }
// }
// })
// },
// exchangeRates: Object.keys(state.exchangeRates).reduce((result, currency) => {
// const { dates, ...exchangeRates } = state.exchangeRates[currency]
// return {
// ...result,
// [currency]: exchangeRates
// }
// }, {})
// }
// }
}

export default migrations
44 changes: 19 additions & 25 deletions src/store/transactions/__tests__/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import faker from 'faker'
import transactionReducer, { initialState } from '../reducer'
import types from '../types'

Expand Down Expand Up @@ -58,45 +59,38 @@ describe('transaction reducer', () => {
describe('UPDATE_TRANSACTION', () => {
it('should handle UPDATE_TRANSACTION', () => {
const type = types.UPDATE_TRANSACTION
const state = {
...initialState,
list: [
{ ...transaction, id: 1, description: 'old name 1' },
{ ...transaction, id: 2, description: 'old name 2' }
]
}
const payload = { id: 1, description: 'new name 1' }
const transactions = [
{ ...transaction, id: faker.random.uuid(), description: 'old name 1' },
{ ...transaction, id: faker.random.uuid(), description: 'old name 2' }
]
const state = { ...initialState, list: transactions }
const payload = { ...transactions[0], description: 'new name 1' }
expect(transactionReducer(state, { type, payload })).toEqual({
...state,
list: [
{ ...transaction, id: 1, description: 'new name 1' },
{ ...transaction, id: 2, description: 'old name 2' }
]
list: [{ ...transactions[0], description: 'new name 1' }, transactions[1]]
})
})
})

describe('UPDATE_TRANSACTIONS', () => {
it('should handle UPDATE_TRANSACTIONS', () => {
const type = types.UPDATE_TRANSACTIONS
const state = {
...initialState,
list: [
{ ...transaction, id: 1, description: 'old name 1' },
{ ...transaction, id: 2, description: 'old name 2' },
{ ...transaction, id: 3, description: 'old name 3' }
]
}
const transactions = [
{ ...transaction, id: faker.random.uuid(), description: 'old name 1' },
{ ...transaction, id: faker.random.uuid(), description: 'old name 2' },
{ ...transaction, id: faker.random.uuid(), description: 'old name 3' }
]
const state = { ...initialState, list: transactions }
const payload = {
1: { description: 'new name 1' },
2: { description: 'new name 2' }
[transactions[0].id]: { ...transactions[0], description: 'new name 1' },
[transactions[1].id]: { ...transactions[1], description: 'new name 2' }
}
expect(transactionReducer(state, { type, payload })).toEqual({
...state,
list: [
{ ...transaction, id: 1, description: 'new name 1' },
{ ...transaction, id: 2, description: 'new name 2' },
{ ...transaction, id: 3, description: 'old name 3' }
{ ...transactions[0], description: 'new name 1' },
{ ...transactions[1], description: 'new name 2' },
{ ...transactions[2], description: 'old name 3' }
]
})
})
Expand Down
10 changes: 2 additions & 8 deletions src/store/transactions/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ export default (state = initialState, { type, payload }) => {
return {
...state,
list: state.list.map((transaction) => {
if (transaction.id === payload.id) {
return { ...transaction, ...payload }
}
return transaction
return transaction.id === payload.id ? payload : transaction
})
}
case types.UPDATE_TRANSACTIONS:
// payload has the format { id1: transaction1, id2: transaction2, ... }
return {
...state,
list: state.list.map((transaction) => {
if (transaction.id.toString() in payload) {
return { ...transaction, ...payload[transaction.id] }
}
return transaction
return transaction.id in payload ? payload[transaction.id] : transaction
})
}
case types.DELETE_TRANSACTIONS:
Expand Down

0 comments on commit 8f4d84c

Please sign in to comment.