From 8109e8a1aea2f5a9eb655d317519f7b237ba9bdb Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Fri, 29 Jul 2022 23:53:52 -0500 Subject: [PATCH] rename repo tests --- squarenotsquare/__tests__/Repo-test.js | 75 +++++++++++++++++++++++++ squarenotsquare/__tests__/Repo-tests.js | 18 ------ 2 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 squarenotsquare/__tests__/Repo-test.js delete mode 100644 squarenotsquare/__tests__/Repo-tests.js diff --git a/squarenotsquare/__tests__/Repo-test.js b/squarenotsquare/__tests__/Repo-test.js new file mode 100644 index 0000000..c47109f --- /dev/null +++ b/squarenotsquare/__tests__/Repo-test.js @@ -0,0 +1,75 @@ +import ScoreRepo from "../src/realm/repos/ScoreRepo"; +import SystemRepo from "../src/realm/repos/SystemRepo"; +import UserRepo from "../src/realm/repos/UserRepo"; +import { System } from "../src/realm/entities/System"; +import { MockRealm } from "../__mock__/mockRealmObject"; +import 'react-native-get-random-values'; +import { v4 as uuidv4 } from 'uuid'; + +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(0); + let testRepo = new SystemRepo(mockRealm); + let systemKey1 = { + id: uuidv4(), + key: 'key1', + value: 'val1' + }; + + let systemKey2 = { + id: uuidv4(), + key: 'key2', + value: 'val2' + }; + + mockRealm.create(System.name, systemKey1); + mockRealm.create(System.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(0); + let testRepo = new SystemRepo(mockRealm); + + let newSystemKey = { + key: 'newKey', + value: 'isNew' + }; + + testRepo.createSystemValue(newSystemKey.key, newSystemKey.value); + let object = mockRealm[System.name][0]; + expect(object.value).toEqual('isNew'); +}) + +test('SystemRepo deletes existing system value', () => { + let mockRealm = new MockRealm(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); +}) \ No newline at end of file diff --git a/squarenotsquare/__tests__/Repo-tests.js b/squarenotsquare/__tests__/Repo-tests.js deleted file mode 100644 index a5f2f1a..0000000 --- a/squarenotsquare/__tests__/Repo-tests.js +++ /dev/null @@ -1,18 +0,0 @@ -import ScoreRepo from "../src/realm/repos/ScoreRepo"; -import SystemRepo from "../src/realm/repos/SystemRepo"; -import UserRepo from "../src/realm/repos/UserRepo"; - -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); -}) \ No newline at end of file