diff --git a/src/database/db.test.js b/src/database/db.test.js index 8bb25f4..4f2429b 100644 --- a/src/database/db.test.js +++ b/src/database/db.test.js @@ -6,6 +6,7 @@ import database from './db'; const realm = require('realm'); const _0Schema = require('./schema/v0.js'); const _1Schema = require('./schema/v1.js'); +const _2Schema = require('./schema/v2.js'); const execSync = require('child_process').execSync; const dbPath = () => 'database/'+Math.random(); @@ -173,6 +174,67 @@ describe('migrate', () => { }); + //If we can open the same path without a promise rejection that mean's we succeed. + //Realm will reject the promise if we miss somethig + test('migrate from 0.3.2 -> 0.3.3', (done) => { + + const dbp = dbPath(); + + const _032Factory = () => realm.open({ + path: dbp, + schema: _1Schema.schemata, + schemaVersion: 1, + migration: _1Schema.migration + }); + + const _033Factory = () => realm.open({ + path: dbp, + schema: _2Schema.schemata, + schemaVersion: 2, + migration: _2Schema.migration + }); + + _032Factory() + .then(db => { + + //Persist test data + db.write(() => { + db.create('Profile', { + id: 1, + name: "Florian", + location: "germany", + latitude: "-", + longitude: "-", + description: "", + image: "base64", + version: "1.0.0", + }); + }); + + db.close(); + return _033Factory(); + }) + .then(db => { + + const p = db.objects('Profile')[0]; + + expect(p.id).toEqual(1); + expect(p.name).toEqual("Florian"); + expect(p.location).toEqual("germany"); + expect(p.latitude).toEqual("-"); + expect(p.longitude).toEqual("-"); + expect(p.description).toEqual(""); + expect(p.image).toEqual("base64"); + expect(p.version).toEqual("1.0.0"); + expect(typeof p.uid).toEqual("string"); + + done(); + + }) + .catch(done.fail) + + }); + test('migrationtest', async () => { const path = dbPath(); diff --git a/src/database/schemata.js b/src/database/schemata.js index 00dbbd3..403ea9c 100644 --- a/src/database/schemata.js +++ b/src/database/schemata.js @@ -42,7 +42,7 @@ export { // This must be bumped each time a new file is added /** The latest schema version present in this codebase. */ -export const LatestSchemaVersion : number = 1; +export const LatestSchemaVersion : number = 2; const schemaModules = [ require('./schema/v0.js'), // Path must be hard-coded diff --git a/src/profile/profile.js b/src/profile/profile.js index e5bb63f..4d85685 100644 --- a/src/profile/profile.js +++ b/src/profile/profile.js @@ -6,6 +6,7 @@ import type {PublicProfile} from '../specification/publicProfile.js'; import type {ProfileType} from '../database/schemata'; import type {EthUtilsInterface} from '../ethereum/utils'; import type {PrivateKeyType} from '../specification/privateKey'; +const uString = require('unique-string'); export const PROFILE_VERSION = '1.0.0'; /** @@ -53,6 +54,7 @@ export default function profileFactory(db: DBInterface, ethUtils: EthUtilsInterf .write((realm: any) => { // Since we only support one profile at the moment, we can just set this always to 1 profile.id = 1; + profile.uid = uString(); realm.create('Profile', profile, true); }) @@ -78,6 +80,7 @@ export default function profileFactory(db: DBInterface, ethUtils: EthUtilsInterf longitude: profiles[0].longitude, image: profiles[0].image, version: profiles[0].version, + uid: profiles[0].uid, }; res(profile);