Skip to content

Commit

Permalink
Merge pull request #78 from kosssi/master
Browse files Browse the repository at this point in the history
feat: Don't filter uncategorized operation to have more matching ➕
  • Loading branch information
kosssi authored Jan 22, 2018
2 parents b9290d1 + 9054c79 commit e53850c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions libs/linker/billsToOperation/operationsFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ const { getIdentifiers, getDateRangeFromBill, getAmountRangeFromBill } = require

const HEALTH_VENDORS = ['Ameli', 'Harmonie', 'Malakoff Mederic', 'MGEN'] // TODO: to import from each konnector
const HEALTH_CAT_ID_OPERATION = '400610' // TODO: import it from cozy-bank
const UNCATEGORIZED_CAT_ID_OPERATION = '0' // TODO: import it from cozy-bank

// helpers

const getCategoryId = o => o.manualCategoryId || o.automaticCategoryId
const getCategoryId = o => {
return o.manualCategoryId
|| o.automaticCategoryId
|| UNCATEGORIZED_CAT_ID_OPERATION
}

const checkOperationCategory = (operation, categoryId) => {
return categoryId === getCategoryId(operation)
}
const isHealthOperation = operation => {
return HEALTH_CAT_ID_OPERATION === getCategoryId(operation)
return checkOperationCategory(operation, HEALTH_CAT_ID_OPERATION)
}
const isUncategorizedOperation = operation => {
return checkOperationCategory(operation, UNCATEGORIZED_CAT_ID_OPERATION)
}

const isHealthBill = bill => {
Expand All @@ -42,8 +53,8 @@ const filterByAmounts = ({ minAmount, maxAmount }) => operation => {

const filterByCategory = bill => operation => {
return isHealthBill(bill)
? isHealthOperation(operation)
: !isHealthOperation(operation)
? isHealthOperation(operation) || isUncategorizedOperation(operation)
: !isHealthOperation(operation) || isUncategorizedOperation(operation)
}

// combine filters
Expand Down
6 changes: 6 additions & 0 deletions libs/linker/billsToOperation/operationsFilters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ describe('operationsFilters', () => {
const fByCategory = filterByCategory({vendor: 'Ameli'})
expect(fByCategory({ manualCategoryId: '400610' })).toBeTruthy()
expect(fByCategory({ automaticCategoryId: '400610' })).toBeTruthy()
expect(fByCategory({ manualCategoryId: '0' })).toBeTruthy()
expect(fByCategory({ automaticCategoryId: '0' })).toBeTruthy()
expect(fByCategory({})).toBeTruthy()
expect(fByCategory({ manualCategoryId: '400611' })).toBeFalsy()
expect(fByCategory({ automaticCategoryId: '400611' })).toBeFalsy()
})
test('not health bill', () => {
const fByCategory = filterByCategory({vendor: 'SFR'})
expect(fByCategory({ manualCategoryId: '400610' })).toBeFalsy()
expect(fByCategory({ automaticCategoryId: '400610' })).toBeFalsy()
expect(fByCategory({ manualCategoryId: '0' })).toBeTruthy()
expect(fByCategory({ automaticCategoryId: '0' })).toBeTruthy()
expect(fByCategory({})).toBeTruthy()
expect(fByCategory({ manualCategoryId: '400611' })).toBeTruthy()
expect(fByCategory({ automaticCategoryId: '400611' })).toBeTruthy()
})
Expand Down

0 comments on commit e53850c

Please sign in to comment.