-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat currency type optimistic cache (#3907)
* feat: currency type in optimisitc cache update * Add test for optimisitc currency cache * Refactor error message for currency filter to be more accurate * Fix --------- Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
01f21d2
commit 176d015
Showing
3 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
...enty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { CurrencyFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter'; | ||
import { isMatchingCurrencyFilter } from '@/object-record/record-filter/utils/isMatchingCurrencyFilter'; | ||
|
||
describe('isMatchingCurrencyFilter', () => { | ||
describe('eq', () => { | ||
it('value equals eq filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { eq: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value does not equal eq filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { eq: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('gt', () => { | ||
it('value is greater than gt filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { gt: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value is not greater than gt filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { gt: 20 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('gte', () => { | ||
it('value is greater than or equal to gte filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { gte: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value is not greater than or equal to gte filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { gte: 20 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('in', () => { | ||
it('value is in the array', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { in: [10, 20, 30] }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value is not in the array', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { in: [10, 30, 40] }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('lt', () => { | ||
it('value is less than lt filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { lt: 20 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value is not less than lt filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { lt: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('lte', () => { | ||
it('value is less than or equal to lte filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { lte: 20 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value is not less than or equal to lte filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { lte: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('neq', () => { | ||
it('value does not equal neq filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { neq: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 20 })).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('value equals neq filter', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { neq: 10 }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe('is', () => { | ||
it('value is NULL', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { is: 'NULL' }, | ||
}; | ||
expect( | ||
isMatchingCurrencyFilter({ currencyFilter, value: null as any }), | ||
).toBe(true); | ||
}); | ||
|
||
it('value is NOT_NULL', () => { | ||
const currencyFilter: CurrencyFilter = { | ||
amountMicros: { is: 'NOT_NULL' }, | ||
}; | ||
expect(isMatchingCurrencyFilter({ currencyFilter, value: 10 })).toBe( | ||
true, | ||
); | ||
}); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
...es/twenty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { CurrencyFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter'; | ||
|
||
export const isMatchingCurrencyFilter = ({ | ||
currencyFilter, | ||
value, | ||
}: { | ||
currencyFilter: CurrencyFilter; | ||
value: number; | ||
}) => { | ||
switch (true) { | ||
case currencyFilter.amountMicros?.eq !== undefined: { | ||
return value === currencyFilter.amountMicros.eq; | ||
} | ||
case currencyFilter.amountMicros?.neq !== undefined: { | ||
return value !== currencyFilter.amountMicros.neq; | ||
} | ||
case currencyFilter.amountMicros?.gt !== undefined: { | ||
return value > currencyFilter.amountMicros.gt; | ||
} | ||
case currencyFilter.amountMicros?.gte !== undefined: { | ||
return value >= currencyFilter.amountMicros.gte; | ||
} | ||
case currencyFilter.amountMicros?.lt !== undefined: { | ||
return value < currencyFilter.amountMicros.lt; | ||
} | ||
case currencyFilter.amountMicros?.lte !== undefined: { | ||
return value <= currencyFilter.amountMicros.lte; | ||
} | ||
case currencyFilter.amountMicros?.in !== undefined: { | ||
return currencyFilter.amountMicros.in.includes(value); | ||
} | ||
case currencyFilter.amountMicros?.is !== undefined: { | ||
if (currencyFilter.amountMicros.is === 'NULL') { | ||
return value === null; | ||
} else { | ||
return value !== null; | ||
} | ||
} | ||
default: { | ||
throw new Error( | ||
`Unexpected amountMicros for currency filter : ${JSON.stringify( | ||
currencyFilter.amountMicros, | ||
)}`, | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters