Greenstand / Greenstand/treetracker-query-api

GET planter by organization_id is not returning correct data

Open
#93 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
18
Forks
65
PR merge metrics
No merged PRs in 30d

Description

The current test route: `planters?organization_id=1&limit=1`
This route only passes the test because the organization and planter both have id=1. But the truth is that the planter id is being overwritten by the object id.

If we use a different route such as: `/planters?organization_id=178&limit=1` then the return object will have id=178. This is the organization id, but it is supposed to return the planter object which has id=2001.

Example of a test that should pass based on current database:
```ts
it(
'get planter by organization id',
async () => {
const response = await supertest(app).get(
'/planters?organization_id=178&limit=1',
);
expect(response.status).toBe(200);
expect(response.body.planters).toBeInstanceOf(Array);
expect(response.body.planters[0]).toMatchObject({
id: 2001,
organization_id: 1,
links: {
featured_trees: expect.stringMatching(/trees/),
associated_organizations: expect.stringMatching(/organizations/),
species: expect.stringMatching(/species/),
},
});
},
1000 * 30,
);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.