Skip to content

Commit

Permalink
fix: add boolean number to datastorepredicateobject operand (#3636)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
Co-authored-by: Caleb Pollman <cpollman@amazon.com>
  • Loading branch information
3 people authored Apr 4, 2023
1 parent 32fba2a commit 61f525f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-mugs-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react": patch
---

fix: add boolean number to datastorepredicateobject operand (internal)
21 changes: 21 additions & 0 deletions packages/react/src/primitives/shared/__tests__/datastore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('createDataStorePredicate', () => {
operand: '25',
};

const booleanPredicateObject = {
field: 'isActive',
operator: 'eq',
operand: true,
};

test('should generate a simple predicate', () => {
const predicate = createDataStorePredicate<Post>(namePredicateObject);

Expand All @@ -35,6 +41,21 @@ describe('createDataStorePredicate', () => {
expect(namePredicate).toHaveBeenCalledWith(namePredicateObject.operand);
});

test('should generate a simple boolean predicate', () => {
const predicate = createDataStorePredicate<Post>(booleanPredicateObject);

const booleanPredicate = jest.fn();

const condition: any = {
[booleanPredicateObject.field]: {
[booleanPredicateObject.operator]: booleanPredicate,
},
};

predicate(condition);
expect(booleanPredicate).toHaveBeenCalledWith(booleanPredicateObject.operand);
});

test('should generate a group predicate: or', () => {
const predicateObject: DataStorePredicateObject = {
or: [namePredicateObject, agePredicateObject],
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/primitives/types/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ export type DataStorePredicateObject = {
and?: DataStorePredicateObject[];
or?: DataStorePredicateObject[];
field?: string;
operand?: string;
operand?: string | boolean | number;
operator?: string;
};

0 comments on commit 61f525f

Please sign in to comment.