Skip to content

Commit 05ea7b3

Browse files
test: use seed data
1 parent d0a4804 commit 05ea7b3

File tree

3 files changed

+90
-89
lines changed

3 files changed

+90
-89
lines changed

__tests__/e2e/countries.spec.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1+
import exampleCountry from '@mocks/countries/exampleCountry.json';
12
import supertest from 'supertest';
2-
import app from '../../server/app';
3+
import app from 'app';
34

4-
describe('', () => {
5-
it('countries/6632544', async () => {
6-
const response = await supertest(app).get('/countries/6632544');
7-
expect(response.status).toBe(200);
8-
expect(response.body).toMatchObject({
9-
id: 6632544,
10-
name: 'China',
11-
});
5+
it('countries/6632544', async () => {
6+
const response = await supertest(app).get(`/countries/${exampleCountry.id}`);
7+
expect(response.status).toBe(200);
8+
expect(response.body).toMatchObject({
9+
id: 6632544,
10+
name: 'China',
1211
});
12+
});
1313

14-
// 103.819073145824,36.5617653792527
15-
it('countries?lat=36.5617653792527&lon=103.819073145824', async () => {
16-
const response = await supertest(app).get(
17-
'/countries?lat=36.5617653792527&lon=103.819073145824',
18-
);
14+
// 103.819073145824,36.5617653792527
15+
it('countries?lat=36.5617653792527&lon=103.819073145824', async () => {
16+
const response = await supertest(app).get(
17+
'/countries?lat=36.5617653792527&lon=103.819073145824',
18+
);
19+
expect(response.status).toBe(200);
20+
expect(response.body.countries[0]).toMatchObject({
21+
id: 6632544,
22+
name: 'China',
23+
});
24+
});
25+
26+
it.skip(
27+
'countries/leaderboard',
28+
async () => {
29+
const response = await supertest(app).get('/countries/leaderboard');
1930
expect(response.status).toBe(200);
2031
expect(response.body.countries[0]).toMatchObject({
21-
id: 6632544,
22-
name: 'China',
32+
id: expect.any(Number),
33+
name: expect.any(String),
34+
planted: expect.any(String),
35+
centroid: expect.stringMatching(/coordinates/),
2336
});
24-
});
25-
26-
it(
27-
'countries/leaderboard',
28-
async () => {
29-
const response = await supertest(app).get('/countries/leaderboard');
30-
expect(response.status).toBe(200);
31-
expect(response.body.countries[0]).toMatchObject({
32-
id: expect.any(Number),
33-
name: expect.any(String),
34-
planted: expect.any(String),
35-
centroid: expect.stringMatching(/coordinates/),
36-
});
37-
},
38-
1000 * 60,
39-
);
40-
});
37+
},
38+
1000 * 60,
39+
);
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1+
import exampleOrganizations from '@mocks/organizations/exampleOrganization.json';
2+
import examplePlanter from '@mocks/planters/examplePlanter.json';
13
import supertest from 'supertest';
2-
import app from '../../server/app';
4+
import app from 'app';
35

4-
describe('organizations', () => {
5-
it('organizations/{id}', async () => {
6-
const response = await supertest(app).get('/organizations/1');
6+
it('organizations/{id}', async () => {
7+
const response = await supertest(app).get(
8+
`/organizations/${exampleOrganizations.id}`,
9+
);
10+
expect(response.status).toBe(200);
11+
expect(response.body).toMatchObject({
12+
id: 1,
13+
links: {
14+
featured_trees: expect.stringMatching(/trees/),
15+
associated_planters: expect.stringMatching(/planters/),
16+
species: expect.stringMatching(/species/),
17+
},
18+
});
19+
});
20+
21+
it(
22+
'organizations?planter_id=1&limit=1',
23+
async () => {
24+
const response = await supertest(app).get(
25+
`/organizations?planter_id=${examplePlanter.id}&limit=1`,
26+
);
727
expect(response.status).toBe(200);
8-
expect(response.body).toMatchObject({
9-
id: 1,
28+
expect(response.body.organizations).toBeInstanceOf(Array);
29+
expect(response.body.organizations[0]).toMatchObject({
30+
id: expect.any(Number),
1031
links: {
1132
featured_trees: expect.stringMatching(/trees/),
1233
associated_planters: expect.stringMatching(/planters/),
1334
species: expect.stringMatching(/species/),
1435
},
1536
});
16-
});
17-
18-
it(
19-
'organizations?planter_id=1&limit=1',
20-
async () => {
21-
const response = await supertest(app).get(
22-
'/organizations?planter_id=1&limit=1',
23-
);
24-
expect(response.status).toBe(200);
25-
expect(response.body.organizations).toBeInstanceOf(Array);
26-
expect(response.body.organizations[0]).toMatchObject({
27-
id: expect.any(Number),
28-
links: {
29-
featured_trees: expect.stringMatching(/trees/),
30-
associated_planters: expect.stringMatching(/planters/),
31-
species: expect.stringMatching(/species/),
32-
},
33-
});
34-
},
35-
1000 * 30,
36-
);
37-
});
37+
},
38+
1000 * 30,
39+
);

__tests__/e2e/planters.spec.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1+
import exampleOrganizations from '@mocks/organizations/exampleOrganization.json';
2+
import examplePlanter from '@mocks/planters/examplePlanter.json';
13
import supertest from 'supertest';
2-
import app from '../../server/app';
4+
import app from 'app';
35

4-
describe('planters', () => {
5-
it('planters/{id}', async () => {
6-
const response = await supertest(app).get('/planters/1');
6+
it('planters/{id}', async () => {
7+
const response = await supertest(app).get(`/planters/${examplePlanter.id}`);
8+
expect(response.status).toBe(200);
9+
expect(response.body).toMatchObject({
10+
id: 1,
11+
links: {
12+
featured_trees: expect.stringMatching(/trees/),
13+
associated_organizations: expect.stringMatching(/organizations/),
14+
species: expect.stringMatching(/species/),
15+
},
16+
});
17+
});
18+
19+
it(
20+
'planters?organization_id=1&limit=1',
21+
async () => {
22+
const response = await supertest(app).get(
23+
`/planters?organization_id=${exampleOrganizations.id}&limit=1`,
24+
);
725
expect(response.status).toBe(200);
8-
expect(response.body).toMatchObject({
26+
expect(response.body.planters).toBeInstanceOf(Array);
27+
expect(response.body.planters[0]).toMatchObject({
928
id: 1,
29+
organization_id: 1,
1030
links: {
1131
featured_trees: expect.stringMatching(/trees/),
1232
associated_organizations: expect.stringMatching(/organizations/),
1333
species: expect.stringMatching(/species/),
1434
},
1535
});
16-
});
17-
18-
it(
19-
'planters?organization_id=1&limit=1',
20-
async () => {
21-
const response = await supertest(app).get(
22-
'/planters?organization_id=1&limit=1',
23-
);
24-
expect(response.status).toBe(200);
25-
expect(response.body.planters).toBeInstanceOf(Array);
26-
expect(response.body.planters[0]).toMatchObject({
27-
id: 1,
28-
organization_id: 1,
29-
links: {
30-
featured_trees: expect.stringMatching(/trees/),
31-
associated_organizations: expect.stringMatching(/organizations/),
32-
species: expect.stringMatching(/species/),
33-
},
34-
});
35-
},
36-
1000 * 30,
37-
);
38-
});
36+
},
37+
1000 * 30,
38+
);

0 commit comments

Comments
 (0)