Created
November 19, 2018 10:20
-
-
Save programaths/2fa2b0bfca94fadd5dfbbaecad7c0749 to your computer and use it in GitHub Desktop.
Mocha test for REALM showing that if a class name is "ROLE" or "USER", it overrides "__ROLE" and "__USER" detection and leads duplicate or missing classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Realm = require('realm'); | |
const LOGIN_URL = `http://localhost:9080/`; | |
const SYS_UNAME = ''; | |
const SYS_PWD = ''; | |
async function loginSysUser29(){ | |
return Realm.Sync.User.login(LOGIN_URL,Realm.Sync.Credentials.usernamePassword(SYS_UNAME,SYS_PWD)); | |
} | |
const SYS_USER_CLASS = { | |
"name": "__User", | |
"primaryKey": "id", | |
"properties": { | |
"id": "string", | |
"role": "__Role" | |
} | |
}; | |
const ROLE_CLASS = { | |
"name": "Role", | |
"primaryKey": "name", | |
"properties": { | |
"name": "string", | |
"access": "string", | |
"premiumRequired": "bool" | |
} | |
}; | |
const USER_CLASS = { | |
"name": "User", | |
"primaryKey": "id", | |
"properties": { | |
"id": "string", | |
"email": "string", | |
"firstName": "string", | |
"lastName": "string", | |
"realmPath": "string", | |
"realmServerName": "string", | |
"permissions": "__Permission[]" | |
} | |
}; | |
const INVITATION_CLASS = { | |
"name": "Invitation", | |
"primaryKey": "id", | |
"properties": { | |
"id": "string", | |
"email": "string", | |
} | |
}; | |
describe('We should be able to omit system classes',async function () { | |
let sysUser = null; | |
before(async function(){ | |
sysUser = await loginSysUser29(); | |
}); | |
it('should allow using a User class',async function () { | |
const goodConfig = sysUser.createConfiguration({ | |
sync: { | |
url: "realm://localhost:9080/test-1" | |
}, | |
schema: [SYS_USER_CLASS, USER_CLASS, INVITATION_CLASS] | |
}); | |
try { | |
const goodRealm = await Realm.open(goodConfig); | |
await goodRealm.close(); | |
}catch (e) { | |
fail("Got an exception "+e.getMessage()); | |
} | |
}); | |
it('should allow using a User class, even when SYS_USER declared last',async function () { | |
const goodConfig = sysUser.createConfiguration({ | |
sync: { | |
url: "realm://localhost:9080/test-2" | |
}, | |
schema: [USER_CLASS, INVITATION_CLASS, SYS_USER_CLASS] | |
}); | |
try { | |
const goodRealm = await Realm.open(goodConfig); | |
await goodRealm.close(); | |
}catch (e) { | |
fail("Got an exception "+e.getMessage()); | |
} | |
}); | |
it('should allow using a Role class',async function(){ | |
const badConfig = sysUser.createConfiguration({ | |
sync: { | |
url: "realm://localhost:9080/test-3" | |
}, | |
schema: [SYS_USER_CLASS, ROLE_CLASS, INVITATION_CLASS] | |
}); | |
try { | |
const badRealm = await Realm.open(badConfig); | |
await badRealm.close(); | |
}catch (e) { | |
fail("Got an exception "+e.getMessage()); | |
} | |
}); | |
it('should allow using a Role class, even when SYS_USER declared last',async function(){ | |
const badConfig = sysUser.createConfiguration({ | |
sync: { | |
url: "realm://localhost:9080/test-4" | |
}, | |
schema: [ROLE_CLASS, INVITATION_CLASS, SYS_USER_CLASS] | |
}); | |
try { | |
const badRealm = await Realm.open(badConfig); | |
await badRealm.close(); | |
}catch (e) { | |
fail("Got an exception "+e.getMessage()); | |
} | |
}); | |
it('should error on __USER duplication',async function(){ | |
const badConfig = sysUser.createConfiguration({ | |
sync: { | |
url: "realm://localhost:9080/test-5" | |
}, | |
schema: [INVITATION_CLASS, SYS_USER_CLASS] | |
}); | |
try { | |
const badRealm = await Realm.open(badConfig); | |
await badRealm.close(); | |
fail("No exception"); | |
}catch (e) { | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment