Skip to content

Commit 125fa86

Browse files
authored
All: Fix format of geolocation data (#2673)
* Maintain geolocation data format through serialization. * Add test.
1 parent bf47237 commit 125fa86

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CliClient/tests/models_BaseItem.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,39 @@ describe('models_BaseItem', function() {
6969
expect(unserialized.user_created_time).toEqual(note.user_created_time);
7070
expect(unserialized.user_updated_time).toEqual(note.user_updated_time);
7171
}));
72+
73+
it('should serialize geolocation fields', asyncTest(async () => {
74+
const folder = await Folder.save({ title: 'folder' });
75+
let note = await Note.save({ title: 'note', parent_id: folder.id });
76+
note = await Note.load(note.id);
77+
78+
let serialized = await Note.serialize(note);
79+
let unserialized = await Note.unserialize(serialized);
80+
81+
expect(unserialized.latitude).toEqual('0.00000000');
82+
expect(unserialized.longitude).toEqual('0.00000000');
83+
expect(unserialized.altitude).toEqual('0.0000');
84+
85+
await Note.updateGeolocation(note.id);
86+
note = await Note.load(note.id);
87+
88+
serialized = await Note.serialize(note);
89+
unserialized = await Note.unserialize(serialized);
90+
91+
expect(unserialized.latitude).toEqual(note.latitude);
92+
expect(unserialized.longitude).toEqual(note.longitude);
93+
expect(unserialized.altitude).toEqual(note.altitude);
94+
}));
95+
96+
it('should serialize and unserialize notes', asyncTest(async () => {
97+
const folder = await Folder.save({ title: 'folder' });
98+
const note = await Note.save({ title: 'note', parent_id: folder.id });
99+
await Note.updateGeolocation(note.id);
100+
101+
const noteBefore = await Note.load(note.id);
102+
const serialized = await Note.serialize(noteBefore);
103+
const noteAfter = await Note.unserialize(serialized);
104+
105+
expect(noteAfter).toEqual(noteBefore);
106+
}));
72107
});

ReactNativeClient/lib/models/BaseItem.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ class BaseItem extends BaseModel {
257257
if (['title_diff', 'body_diff'].indexOf(propName) >= 0) {
258258
if (!propValue) return '';
259259
propValue = JSON.parse(propValue);
260+
} else if (['longitude', 'latitude', 'altitude'].indexOf(propName) >= 0) {
261+
const places = (propName === 'altitude') ? 4 : 8;
262+
propValue = Number(propValue).toFixed(places);
260263
} else {
261264
if (['created_time', 'updated_time', 'user_created_time', 'user_updated_time'].indexOf(propName) >= 0) {
262265
propValue = (!propValue) ? '0' : moment(propValue, 'YYYY-MM-DDTHH:mm:ss.SSSZ').format('x');

0 commit comments

Comments
 (0)