diff --git a/server/__tests__/integration/capture/capture.spec.js b/server/__tests__/integration/capture/capture.spec.js index 4683b4f1..1aae19c4 100644 --- a/server/__tests__/integration/capture/capture.spec.js +++ b/server/__tests__/integration/capture/capture.spec.js @@ -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, @@ -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); @@ -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 () => { @@ -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 () => { @@ -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 () => { diff --git a/server/__tests__/integration/tree/potential_matches.spec.js b/server/__tests__/integration/tree/potential_matches.spec.js index 07366a4e..6381178e 100644 --- a/server/__tests__/integration/tree/potential_matches.spec.js +++ b/server/__tests__/integration/tree/potential_matches.spec.js @@ -22,7 +22,6 @@ describe('GET /trees/potential_matches', () => { after(async () => { await knex('grower_account') - .where({ ...grower_account2 }) .del(); }); diff --git a/server/__tests__/mock/capture2.json b/server/__tests__/mock/capture2.json index 24cbe413..e7974ff5 100644 --- a/server/__tests__/mock/capture2.json +++ b/server/__tests__/mock/capture2.json @@ -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", diff --git a/server/handlers/captureHandler.js b/server/handlers/captureHandler.js index cf88ad40..21118df4 100644 --- a/server/handlers/captureHandler.js +++ b/server/handlers/captureHandler.js @@ -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({