Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement denormalized trees API #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 73 additions & 42 deletions __tests__/e2e/trees.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@ import supertest from 'supertest';
import app from '../../server/app';

describe('trees', () => {
it('trees/{id}', async () => {
const response = await supertest(app).get('/trees/952022');
expect(response.status).toBe(200);
expect(response.body).toMatchObject({
id: 952022,
lat: expect.anything(),
lon: expect.anything(),
species_id: 113,
species_name: 'bob',
country_name: 'China',
country_id: 6632544,
organization_id: 11,
organization_name: 'FCC',
});
});
it(
'trees/{id}',
async () => {
const response = await supertest(app).get('/trees/192');
expect(response.status).toBe(200);
expect(response.body).toMatchObject({
id: 192,
lat: expect.anything(),
lon: expect.anything(),
species_id: 4,
species_name: 'species_name_3',
country_name: 'Ashmore and Cartier Islands',
country_id: 230,
organization_id: 13,
organization_name: 'ISAP',
});
},
1000 * 30,
);

it(
'trees/{uuid}',
async () => {
const response = await supertest(app).get(
'/trees/c48ebfc0-bbe4-4a3a-8cff-7e5f4ff12977',
);
expect(response.status).toBe(200);
expect(response.body).toMatchObject({
id: 270,
lat: expect.anything(),
lon: expect.anything(),
species_id: 2,
species_name: 'species_name_3',
country_name: 'Sierra Leone',
country_id: 64,
organization_id: 5,
organization_name: 'UEMG',
});
},
1000 * 30,
);

it('Unknown tree', async () => {
const response = await supertest(app).get('/trees/1');
Expand All @@ -31,14 +57,6 @@ describe('trees', () => {
});
});

it('trees?limit=1&offset=0', async () => {
const response = await supertest(app).get('/trees?limit=1&offset=0');
expect(response.status).toBe(200);
expect(response.body).toMatchObject({
trees: expect.anything(),
});
});

it(
'trees?limit=1&organization_id=11',
async () => {
Expand All @@ -57,19 +75,20 @@ describe('trees', () => {
);

it(
'trees?startDate=2021-02-26&endDate=2021-12-22',
'trees?startDate=2022-02-23&endDate=2022-02-24',
async () => {
const response = await supertest(app).get(
'/trees?startDate=2021-02-26&endDate=2021-12-22',
'/trees?startDate=2022-02-23&endDate=2022-02-24',
);
expect(response.status).toBe(200);
expect(response.body.total).toBe(96);
for (let i = 0; i < response.body.trees.length; i++) {
expect(
new Date(response.body.trees[i].time_created).getTime(),
).toBeGreaterThanOrEqual(new Date('2021-02-26T00:00:00Z').getTime());
).toBeGreaterThanOrEqual(new Date('2022-02-23T00:00:00Z').getTime());
expect(
new Date(response.body.trees[i].time_created).getTime(),
).toBeLessThan(new Date('2021-12-23T00:00:00Z').getTime());
).toBeLessThan(new Date('2022-02-24T00:00:00Z').getTime());
}
},
1000 * 60,
Expand All @@ -83,54 +102,66 @@ describe('trees', () => {
// expect(response.body).toMatchObject({
// trees: expect.anything(),
// });
expect(response.body.trees.length).toBe(3);
expect(response.body.trees[0]).toMatchObject({
id: expect.any(Number),
});
},
1000 * 10,
1000 * 30,
);

it(
'trees?tag=photoless',
async () => {
const response = await supertest(app).get('/trees?tag=photoless');
const expectedIds = [186685, 878654];
const expectedIds = [238];
expect(response.status).toBe(200);
expect(response.body.total).toBe(2);
const returnedIds = [
response.body.trees[0].id,
response.body.trees[1].id,
];
expect(response.body.total).toBe(1);
const returnedIds = [response.body.trees[0].id];
expect(returnedIds).toEqual(expectedIds);
},
1000 * 30,
);

it(
'trees?planter_id=3584&desc=true',
'trees?planter_id=5840&desc=true',
async () => {
const response = await supertest(app).get(
'/trees?planter_id=5840&limit=1&order_by=id',
);
expect(response.status).toBe(200);
expect(response.body.trees[0]).toMatchObject({
id: 270,
planter_id: 5840,
});
},
1000 * 30,
);

it(
'trees?planter_id=5840&desc=false',
async () => {
const response = await supertest(app).get(
'/trees?planter_id=3584&limit=1&order_by=created_at',
'/trees?planter_id=5840&order_by=id&desc=false&limit=1',
);
expect(response.status).toBe(200);
expect(response.body.trees[0]).toMatchObject({
id: 938209,
planter_id: 3584,
id: 171,
planter_id: 5840,
});
},
1000 * 30,
);

it(
'trees?planter_id=3584&desc=false',
'trees?wallet_id=9b25795c-a07b-4487-92cf-b9b784d5dfc0',
async () => {
const response = await supertest(app).get(
'/trees?planter_id=3584&order_by=created_at&desc=false&limit=1',
'/trees?wallet_id=9b25795c-a07b-4487-92cf-b9b784d5dfc0',
);
expect(response.status).toBe(200);
expect(response.body.trees[0]).toMatchObject({
id: 937190,
planter_id: 3584,
wallet_id: '9b25795c-a07b-4487-92cf-b9b784d5dfc0',
});
},
1000 * 30,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

Loading
Loading