Skip to content

Commit

Permalink
fix: remove unset grower ID from captures filter (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcharlton authored Dec 13, 2021
1 parent f0250ea commit 533506a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
9 changes: 2 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/GrowerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const GrowerDetail = (props) => {

async function getCaptureCountGrower(active, approved, growerId) {
let filter = new FilterModel();
filter.planterId = growerId;
filter.planterId = growerId?.toString();
filter.active = active;
filter.approved = approved;
const countResponse = await treeTrackerApi.getCaptureCount(filter);
Expand Down
15 changes: 4 additions & 11 deletions src/models/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,15 @@ export default class Filter {
where.active = this.active;
}

if (this.planterId !== undefined) {
if (this.planterId) {
where.planterId = this.planterId;
}

if (
this.deviceIdentifier !== undefined &&
this.deviceIdentifier.length > 0
) {
if (this.deviceIdentifier) {
where.deviceIdentifier = this.deviceIdentifier;
}

if (
this.planterIdentifier !== undefined &&
this.planterIdentifier.length > 0
) {
if (this.planterIdentifier) {
where.planterIdentifier = this.planterIdentifier;
}

Expand Down Expand Up @@ -129,7 +123,7 @@ export default class Filter {

/*
* A fn to count the number of current applied filters
*/
*/
countAppliedFilters() {
let numFilters = 0;

Expand Down Expand Up @@ -183,5 +177,4 @@ export default class Filter {

return numFilters;
}

}
16 changes: 9 additions & 7 deletions src/models/Filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ describe('Filter, with initial values about this filter object', () => {
beforeEach(() => {
filter = new Filter();
filter.uuid = '11942400-6617-4c6c-bf5e';
filter.captureId = 10;
filter.captureId = '10';
filter.dateStart = '2019-07-25';
filter.dateEnd = '2019-07-30';
filter.approved = true;
filter.active = true;
filter.planterId = 1;
filter.planterId = '1';
filter.deviceIdentifier = '1';
filter.planterIdentifier = '1';
});

it('getWhereObj() should be: ', () => {
expect(filter.getWhereObj()).toEqual(expect.objectContaining({ uuid: '11942400-6617-4c6c-bf5e' }));
expect(filter.getWhereObj()).toEqual(
expect.objectContaining({ uuid: '11942400-6617-4c6c-bf5e' }),
);
});

it('getWhereObj() should be: ', () => {
expect(filter.getWhereObj()).toEqual(expect.objectContaining({ id: 10 }));
expect(filter.getWhereObj()).toEqual(expect.objectContaining({ id: '10' }));
});

it('getWhereObj() should match: timeCreated between', () => {
Expand Down Expand Up @@ -63,7 +65,7 @@ describe('Filter, with initial values about this filter object', () => {

it('getWhereObj() should match: planterId=1', () => {
expect(filter.getWhereObj()).toEqual(
expect.objectContaining({ planterId: 1 }),
expect.objectContaining({ planterId: '1' }),
);
});

Expand Down Expand Up @@ -91,10 +93,10 @@ describe('Filter, with initial values about this filter object', () => {
//}}}
});

describe('set planterId = undefined', () => {
describe('set planterId = ""', () => {
//{{{
beforeEach(() => {
filter.planterId = undefined;
filter.planterId = '';
});

it('loopback object should not match any [planterId]', () => {
Expand Down

0 comments on commit 533506a

Please sign in to comment.