Skip to content

All: Fix format of geolocation data #2673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions CliClient/tests/models_BaseItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,50 @@ describe('models_BaseItem', function() {
}));

it('should correctly unserialize note timestamps', asyncTest(async () => {
let folder = await Folder.save({ title: 'folder' });
let note = await Note.save({ title: 'note', parent_id: folder.id });
const folder = await Folder.save({ title: 'folder' });
const note = await Note.save({ title: 'note', parent_id: folder.id });

let serialized = await Note.serialize(note);
let unserialized = await Note.unserialize(serialized);
const serialized = await Note.serialize(note);
const unserialized = await Note.unserialize(serialized);

expect(unserialized.created_time).toEqual(note.created_time);
expect(unserialized.updated_time).toEqual(note.updated_time);
expect(unserialized.user_created_time).toEqual(note.user_created_time);
expect(unserialized.user_updated_time).toEqual(note.user_updated_time);
}));

it('should serialize geolocation fields', asyncTest(async () => {
const folder = await Folder.save({ title: 'folder' });
let note = await Note.save({ title: 'note', parent_id: folder.id });
note = await Note.load(note.id);

let serialized = await Note.serialize(note);
let unserialized = await Note.unserialize(serialized);

expect(unserialized.latitude).toEqual('0.00000000');
expect(unserialized.longitude).toEqual('0.00000000');
expect(unserialized.altitude).toEqual('0.0000');

await Note.updateGeolocation(note.id);
note = await Note.load(note.id);

serialized = await Note.serialize(note);
unserialized = await Note.unserialize(serialized);

expect(unserialized.latitude).toEqual(note.latitude);
expect(unserialized.longitude).toEqual(note.longitude);
expect(unserialized.altitude).toEqual(note.altitude);
}));

it('should serialize and unserialize notes', asyncTest(async () => {
const folder = await Folder.save({ title: 'folder' });
const note = await Note.save({ title: 'note', parent_id: folder.id });
await Note.updateGeolocation(note.id);

const noteBefore = await Note.load(note.id);
const serialized = await Note.serialize(noteBefore);
const noteAfter = await Note.unserialize(serialized);

expect(noteAfter).toEqual(noteBefore);
}));
});
3 changes: 3 additions & 0 deletions ReactNativeClient/lib/models/BaseItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class BaseItem extends BaseModel {
if (['title_diff', 'body_diff'].indexOf(propName) >= 0) {
if (!propValue) return '';
propValue = JSON.parse(propValue);
} else if (['longitude', 'latitude', 'altitude'].indexOf(propName) >= 0) {
const places = (propName === 'altitude') ? 4 : 8;
propValue = Number(propValue).toFixed(places);
} else {
if (['created_time', 'updated_time', 'user_created_time', 'user_updated_time'].indexOf(propName) >= 0) {
propValue = (!propValue) ? '0' : moment(propValue, 'YYYY-MM-DDTHH:mm:ss.SSSZ').format('x');
Expand Down