Skip to content

Commit

Permalink
fix: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZavenArra committed Feb 3, 2022
1 parent dfe65d4 commit f8008a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions server/__tests__/integration/capture/capture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const tag2 = require('../../mock/tag2.json');
const grower_account1 = require('../../mock/grower_account1.json');
const grower_account2 = require('../../mock/grower_account2.json');
const domain_event2 = require('../../mock/domain_event2.json');
const tree1 = require('../../mock/tree1.json');
const { knex, addCapture } = require('../../utils');

describe('/captures', () => {
const captureUpdates = {
tree_id: null,
// tree_id: null,
species_id: '12e2c0f6-b7df-43e3-8899-674e90b292d9',
morphology: 'yyggollohhprom',
age: 44,
Expand Down Expand Up @@ -110,9 +111,14 @@ describe('/captures', () => {
});

it('should update a capture', async () => {

const updates = {
tree_id: tree1.id
}

await request(app)
.patch(`/captures/${capture2.id}`)
.send(captureUpdates)
.send(updates)
.set('Accept', 'application/json')
.expect(204);

Expand All @@ -121,7 +127,7 @@ describe('/captures', () => {
.expect(200);
// expect(result.body.attributes.entries).to.eql(captureUpdates.attributes.entries);
// delete copy.attributes;
expect(result.body).to.include({ ...captureUpdates });
expect(result.body).to.include({ ...updates });
});

after(async () => {
Expand All @@ -146,27 +152,23 @@ describe('/captures', () => {
});
});

// TODO: do not check changes from a different test in a another test
// this test is just to check changes from the PATCH test, they must be combined
it.skip('should get captures', async () => {
it('should get captures', async () => {
const result = await request(app).get(`/captures`).expect(200);
const copy = { ...updatedModCapture };
expect(result.body.length).to.eql(2);
expect(result.body[1].attributes.entries).to.eql(copy.attributes.entries);
delete copy.attributes;
expect(result.body[1]).to.include({ ...copy });
expect(result.body.captures.length).to.eql(2);
// console.log(result.body.captures[1]);
// expect(result.body.captures[1]).to.include({ ...capture1 });
});

it('should get only captures with tree associated', async () => {
const result = await request(app).get(`/captures?tree_associated=true`).expect(200);
expect(result.body.length).to.eql(1);
expect(result.body[0].id).to.eql("c02a5ae6-3727-11ec-8d3d-0242ac130003");
expect(result.body.captures.length).to.eql(1);
expect(result.body.captures[0].id).to.eql("c02a5ae6-3727-11ec-8d3d-0242ac130003");
});

it('should get only captures without tree associated', async () => {
const result = await request(app).get(`/captures?tree_associated=false`).expect(200);
expect(result.body.length).to.eql(1);
expect(result.body[0].id).to.eql("d2c69205-b13f-4ab6-bb5e-33dc504fa0c2");
expect(result.body.captures.length).to.eql(1);
expect(result.body.captures[0].id).to.eql("d2c69205-b13f-4ab6-bb5e-33dc504fa0c2");
});

it('should delete a capture', async () => {
Expand All @@ -178,7 +180,7 @@ describe('/captures', () => {

const result = await request(app).get(`/captures`).expect(200);
const copy = { ...updatedModCapture };
expect(result.body.length).to.eql(1);
expect(result.body.captures.length).to.eql(1);
});

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('GET /trees/potential_matches', () => {

after(async () => {
await knex('grower_account')
.where({ ...grower_account2 })
.del();
});

Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/mock/capture2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "d2c69205-b13f-4ab6-bb5e-33dc504fa0c2",
"reference_id": "215606",
"reference_id": 215606,
"session_id": "f97a0338-1d6a-4f19-a067-a7f0b573e3cd",
"image_url": "https://treetracker-dev-images.s3.eu-central-1.amazonaws.com/2020.05.15.16.18.46_37.42138089_-121.87534965_92b10ff4-4d37-43e9-8dd7-ed79e23d1102_IMG_20200511_150539_503676129060555307.jpg",
"lat": "37.42138089",
Expand Down
1 change: 1 addition & 0 deletions server/handlers/captureHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const capturePostSchema = Joi.object({

const capturePatchSchema = Joi.object({
tree_id: Joi.string(),
status: Joi.string()
}).unknown(false);

const captureIdParamSchema = Joi.object({
Expand Down

0 comments on commit f8008a6

Please sign in to comment.