Fix read status NULL progress handling in rule evaluator (#2821)
* Fix DOES_NOT_CONTAIN NULL handling for READ_STATUS and add null-progress tests * Fix IS_EMPTY/IS_NOT_EMPTY parity for readStatus in FE rule evaluator
This commit is contained in:
@@ -1449,6 +1449,28 @@ describe('BookRuleEvaluatorService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('readStatus is_empty / is_not_empty parity', () => {
|
||||
it('should match is_empty when book has no readStatus', () => {
|
||||
const book = createBook({readStatus: undefined});
|
||||
expect(service.evaluateGroup(book, rule('readStatus', 'is_empty', null))).toBe(true);
|
||||
});
|
||||
|
||||
it('should not match is_empty when book has a readStatus', () => {
|
||||
const book = createBook({readStatus: ReadStatus.READING});
|
||||
expect(service.evaluateGroup(book, rule('readStatus', 'is_empty', null))).toBe(false);
|
||||
});
|
||||
|
||||
it('should not match is_not_empty when book has no readStatus', () => {
|
||||
const book = createBook({readStatus: undefined});
|
||||
expect(service.evaluateGroup(book, rule('readStatus', 'is_not_empty', null))).toBe(false);
|
||||
});
|
||||
|
||||
it('should match is_not_empty when book has a readStatus', () => {
|
||||
const book = createBook({readStatus: ReadStatus.READ});
|
||||
expect(service.evaluateGroup(book, rule('readStatus', 'is_not_empty', null))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('unknown operator', () => {
|
||||
it('should return false for an unrecognized operator', () => {
|
||||
const book = createBook();
|
||||
|
||||
@@ -211,17 +211,21 @@ export class BookRuleEvaluatorService {
|
||||
}
|
||||
return Number(value) >= Number(ruleStart) && Number(value) <= Number(ruleEnd);
|
||||
|
||||
case 'is_empty':
|
||||
if (value == null) return true;
|
||||
if (typeof value === 'string') return value.trim() === '';
|
||||
if (Array.isArray(value)) return value.length === 0;
|
||||
case 'is_empty': {
|
||||
const emptyVal = rule.field === 'readStatus' ? book.readStatus : value;
|
||||
if (emptyVal == null) return true;
|
||||
if (typeof emptyVal === 'string') return emptyVal.trim() === '';
|
||||
if (Array.isArray(emptyVal)) return emptyVal.length === 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
case 'is_not_empty':
|
||||
if (value == null) return false;
|
||||
if (typeof value === 'string') return value.trim() !== '';
|
||||
if (Array.isArray(value)) return value.length > 0;
|
||||
case 'is_not_empty': {
|
||||
const notEmptyVal = rule.field === 'readStatus' ? book.readStatus : value;
|
||||
if (notEmptyVal == null) return false;
|
||||
if (typeof notEmptyVal === 'string') return notEmptyVal.trim() !== '';
|
||||
if (Array.isArray(notEmptyVal)) return notEmptyVal.length > 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 'includes_all': {
|
||||
const bookList = getArrayField(rule.field);
|
||||
|
||||
Reference in New Issue
Block a user