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.
121 lines
3.3 KiB
121 lines
3.3 KiB
import ScoreRepo from "../src/realm/repos/ScoreRepo";
|
|
import SystemRepo from "../src/realm/repos/SystemRepo";
|
|
import UserRepo from "../src/realm/repos/UserRepo";
|
|
import { SystemEntity } from "../src/realm/entities/System";
|
|
import MockRealm from "../__mock__/mockRealmObject";
|
|
import 'react-native-get-random-values';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
jest.useRealTimers();
|
|
|
|
test('ScoreRepo inits', () => {
|
|
let testRepo = new ScoreRepo({fakeRealm: true});
|
|
expect(testRepo.realmDB.fakeRealm).toEqual(true);
|
|
})
|
|
|
|
test('SystemRepo inits', () => {
|
|
let testRepo = new SystemRepo({fakeRealm: true});
|
|
expect(testRepo.realmDB.fakeRealm).toEqual(true);
|
|
})
|
|
|
|
test('UserRepo inits', () => {
|
|
let testRepo = new UserRepo({fakeRealm: true});
|
|
expect(testRepo.realmDB.fakeRealm).toEqual(true);
|
|
})
|
|
|
|
test('SystemRepo gets all values', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
let systemKey1 = {
|
|
id: uuidv4(),
|
|
key: 'key1',
|
|
value: 'val1'
|
|
};
|
|
|
|
let systemKey2 = {
|
|
id: uuidv4(),
|
|
key: 'key2',
|
|
value: 'val2'
|
|
};
|
|
|
|
mockRealm.create(SystemEntity.name, systemKey1);
|
|
mockRealm.create(SystemEntity.name, systemKey2);
|
|
|
|
let queried = testRepo.getAllSystemValues();
|
|
|
|
expect(queried[systemKey1.key]).toEqual('val1');
|
|
expect(queried[systemKey2.key]).toEqual('val2');
|
|
})
|
|
|
|
test('SystemRepo creates system value', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
|
|
let newSystemKey = {
|
|
key: 'newKey',
|
|
value: 'isNew'
|
|
};
|
|
|
|
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
|
|
let object = mockRealm[SystemEntity.name][0];
|
|
expect(object.value).toEqual('isNew');
|
|
})
|
|
|
|
test('SystemRepo handles creation of existing system value', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
|
|
let newSystemKey = {
|
|
key: 'newKey',
|
|
value: 'isNew'
|
|
};
|
|
|
|
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
|
|
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
|
|
let object = mockRealm[SystemEntity.name][0];
|
|
expect(object.value).toEqual('isNew');
|
|
})
|
|
|
|
test('SystemRepo deletes existing system value', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
|
|
let newSystemKey = {
|
|
key: 'newKey',
|
|
value: 'isNew'
|
|
};
|
|
|
|
testRepo.createSystemValue(newSystemKey.key, newSystemKey.value);
|
|
testRepo.deleteSystemValue(newSystemKey.key);
|
|
|
|
expect(mockRealm.deletedKeys[0].value).toEqual(newSystemKey.value);
|
|
})
|
|
|
|
test('SystemRepo deletes non-existing system value', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
|
|
testRepo.deleteSystemValue('key');
|
|
expect(mockRealm.deletedKeys.length).toEqual(0);
|
|
})
|
|
|
|
test('SystemRepo gets multiple system values', () => {
|
|
let mockRealm = new MockRealm({schemaVersion: 0});
|
|
let testRepo = new SystemRepo(mockRealm);
|
|
|
|
let systemKey1 = {
|
|
id: uuidv4(),
|
|
key: 'key1',
|
|
value: 'val1'
|
|
};
|
|
|
|
let systemKey2 = {
|
|
id: uuidv4(),
|
|
key: 'key1',
|
|
value: 'val1'
|
|
};
|
|
|
|
mockRealm.create(SystemEntity.name, systemKey1);
|
|
mockRealm.create(SystemEntity.name, systemKey2);
|
|
let response = testRepo.getSystemKeyValue(systemKey1.key);
|
|
expect(response).toEqual('Multiple system keys found for key1');
|
|
})
|