Skip to content

Commit ef5edf1

Browse files
committed
Account for missing forms array in existing observation
1 parent 3237693 commit ef5edf1

File tree

3 files changed

+2
-91
lines changed

3 files changed

+2
-91
lines changed

routes/observations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ module.exports = function(app, security) {
331331
const {forms = []} = req.observation.properties || {}
332332
forms.map(observationForm => {
333333
if (existingObservation) {
334-
const exisitingForm = existingObservation.properties.forms.find(exisitingForm => exisitingForm._id.toString() === observationForm.id);
334+
const { forms: exisitingForms = [] } = existingObservation.properties || {}
335+
const exisitingForm = exisitingForms.find(exisitingForm => exisitingForm._id.toString() === observationForm.id);
335336
if (exisitingForm) {
336337
observationForm._id = exisitingForm._id;
337338
delete observationForm.id;

test/attachment/attachmentCreateTest.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ describe("creating attachments", function() {
8080
}
8181

8282
describe('required permissions', function() {
83-
84-
let mockObservation;
85-
8683
beforeEach(function() {
8784
sinon.mock(TeamModel)
8885
.expects('find')

test/export/exportTest.js

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -67,93 +67,6 @@ describe("export tests", function () {
6767

6868
const userId = mongoose.Types.ObjectId();
6969

70-
it("should export observations as kml - deprecated", function (done) {
71-
72-
mockTokenWithPermission('READ_OBSERVATION_ALL');
73-
74-
const eventId = 1;
75-
const mockEvent = new EventModel({
76-
_id: eventId,
77-
name: 'Mock Event',
78-
collectionName: 'observations1'
79-
});
80-
81-
sinon.mock(EventModel)
82-
.expects('findById')
83-
.twice()
84-
.onFirstCall()
85-
.yields(null, mockEvent)
86-
.onSecondCall()
87-
.yields(null, mockEvent);
88-
89-
sinon.mock(UserModel)
90-
.expects('find')
91-
.chain('exec')
92-
.yields(null, [{
93-
username: 'user1'
94-
}, {
95-
username: 'user2'
96-
}]);
97-
98-
sinon.mock(DeviceModel)
99-
.expects('find')
100-
.chain('exec')
101-
.resolves([{
102-
uid: '1'
103-
}, {
104-
uid: '2'
105-
}]);
106-
107-
const ObservationModel = observationModel({
108-
_id: 1,
109-
name: 'Event 1',
110-
collectionName: 'observations1',
111-
style: {}
112-
});
113-
const mockObservation = new ObservationModel({
114-
_id: mongoose.Types.ObjectId(),
115-
type: 'Feature',
116-
geometry: {
117-
type: "Point",
118-
coordinates: [0, 0]
119-
},
120-
properties: {
121-
timestamp: Date.now(),
122-
forms: []
123-
}
124-
});
125-
126-
sinon.mock(ObservationModel)
127-
.expects('find')
128-
.chain('exec')
129-
.yields(null, [mockObservation]);
130-
131-
sinon.mock(IconModel)
132-
.expects('find')
133-
.yields(null, [{
134-
relativePath: 'mock/path'
135-
}]);
136-
137-
const fs = {
138-
'/var/lib/mage/icons/1': {}
139-
};
140-
mockfs(fs);
141-
142-
request(app)
143-
.get('/api/kml?eventId=1&observations=true&locations=false&attachments=false')
144-
.set('Accept', 'application/json')
145-
.set('Authorization', 'Bearer 12345')
146-
.expect(200)
147-
.expect(function (res) {
148-
res.headers.should.have.property('content-type').that.equals('application/zip');
149-
res.headers.should.have.property('content-disposition').that.equals('attachment; filename="mage-kml.zip"');
150-
})
151-
.end(function (err) {
152-
mockfs.restore();
153-
done(err);
154-
});
155-
});
156-
15770
it("should export observations as kml", function (done) {
15871

15972
mockTokenWithPermission('READ_OBSERVATION_ALL');

0 commit comments

Comments
 (0)