You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
990 B

import { SystemEntity } from "../src/realm/entities/System";
import { UserEntity } from "../src/realm/entities/User";
export default class MockRealm{
constructor(params){
this.schemaVersion = params.schemaVersion;
this[SystemEntity.name] = [];
this[UserEntity.name] = [];
this.deletedKeys = [];
}
create(repoName, entity){
this[repoName].push(entity);
}
objects(repoName){
let objects = this[repoName];
objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects;
objects.sorted = this.sorted ? this.sorted.bind(this, repoName) : () => objects;
return objects;
}
write(callback){
callback();
}
delete(key){
this.deletedKeys.push(key);
}
static defaultPath = '';
static schemaVersion(path, key){
if (path === 'negTest') {
return -1;
} else if (path === 'breakDB') {
throw 'Existing DB is broken';
} else {
return 0;
}
}
close(){
return null;
}
}