Skip to content

Commit

Permalink
feat: fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sahand-zeynol committed Aug 10, 2022
1 parent c05fb92 commit 466e954
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
14 changes: 12 additions & 2 deletions api-tests/integration/capture/capture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const request = require('supertest');
require('dotenv').config();
const { expect } = require('chai');
require('../../setup');
const uuid = require('uuid');
const app = require('../../../server/app');
const capture2 = require('../../mock/capture2.json');
const capture1 = require('../../mock/capture1.json');
Expand All @@ -11,7 +12,7 @@ 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');
const { knex, addCapture, addTree } = require('../../utils');

describe('/captures', () => {
before(async () => {
Expand All @@ -27,10 +28,18 @@ describe('/captures', () => {
status: 'active',
})
.returning('id');

const [savedTree1] = await addTree({
...tree1,
created_at: '2021-05-04 11:24:43',
updated_at: '2021-05-04 11:24:43',
estimated_geometric_location: 'POINT(50 50)',
latest_capture_id: uuid.v4(),
attributes: { entries: tree1.attributes },
});
const [capture1GrowerAccountId] = growerAccount1;
const [capture2GrowerAccountId] = growerAccount2;
capture1.grower_account_id = capture1GrowerAccountId;
capture1.tree_id = savedTree1.id;
capture2.grower_account_id = capture2GrowerAccountId;
});

Expand All @@ -39,6 +48,7 @@ describe('/captures', () => {
await knex('tag').del();
await knex('capture').del();
await knex('grower_account').del();
await knex('tree').del();
});

describe('POST', () => {
Expand Down
7 changes: 6 additions & 1 deletion api-tests/integration/tree/potential_matches.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ describe('GET /trees/potential_matches', () => {

const [captureGrowerAccountId] = growerAccount1;
capture1.grower_account_id = captureGrowerAccountId;
capture1.tree_id = tree1.id;
});

afterEach(async () => {
await utils.delTree(tree1.id);
await utils.delCapture(capture1.id);
await utils.delTree(tree1.id);
});

after(async () => {
await knex('grower_account').del();
await knex('tree').del();
await knex('capture').del();
});

const extraInfo = {
Expand All @@ -49,6 +52,8 @@ describe('GET /trees/potential_matches', () => {
estimated_geographic_location: 'POINT(50 50)',
updated_at: '2021-05-04 11:24:43',
});
console.log(1111)
console.log(capture1)
const response = await request(app).get(
`/trees/potential_matches?capture_id=${capture1.id}`,
);
Expand Down
3 changes: 1 addition & 2 deletions api-tests/mock/capture1.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"id": "c02a5ae6-3727-11ec-8d3d-0242ac130003",
"reference_id": 1,
"tree_id": "f7647dc6-e2c0-407c-be9d-b831734598d7",
"lat": 50,
"lon": 50,
"device_configuration_id": "6091cf22-9774-40c3-986c-ef555069ae2a",
"session_id": "f97a0338-1d6a-4f19-a067-a7f0b573e3cd",
"image_url": "http://xxx",
"planting_organization_id": "3876b7df-0002-4bc7-adfa-097db2080311",
"captured_at": "2022-01-01 11:11:11"
}
}
2 changes: 1 addition & 1 deletion api-tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function parsePoint(json) {

module.exports = {
async addTree(json) {
await knex('tree').insert(parsePoint(json)).returning('*');
return knex('tree').insert(parsePoint(json)).returning('*');
},
async addCapture(json) {
return knex('capture').insert(parsePoint(json)).returning('*');
Expand Down
2 changes: 1 addition & 1 deletion server/repositories/TreeRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TreeRepository extends BaseRepository {
WHERE
t1.id IS NOT NULL
AND t2.id = :id
AND (t2.tree_id IS NULL OR t2.tree_id <> t1.id )
OR t2.tree_id IS NULL
`;
// 'SELECT t1.id, t1.image_url, t1.latest_capture_id, t1.lat, t1.lon, t1.species_id, t1.morphology, t1.age, t1.status, t1.created_at, t1.updated_at FROM tree t1 LEFT JOIN capture t2 ON ST_DWithin(t1.estimated_geometric_location, t2.estimated_geometric_location, :distance) WHERE t1.id= :id AND t2.id<> :id';
const data = await this._session.getDB().raw(query, { id, distance });
Expand Down

0 comments on commit 466e954

Please sign in to comment.