summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2017-01-14 10:39:05 -0700
committermo khan <mo@mokhan.ca>2017-01-14 10:39:05 -0700
commitd71a03f916c99870b3f05b674a1ee8b900b78312 (patch)
tree59b622efed12d731bcbd892c6b20a4d781e9bc29
parent94621319c1cae887a10e1d22a299b8c4dca665df (diff)
create repository class.
-rw-r--r--.gitignore2
-rw-r--r--app/domain/__tests__/repository_spec.js23
-rw-r--r--app/domain/__tests__/user_spec.js35
-rw-r--r--app/domain/account.js8
-rw-r--r--app/domain/repository.js30
-rw-r--r--app/domain/user.js0
6 files changed, 98 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 7dddaca..f8ffe5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,3 +42,5 @@ android/app/libs
*.keystore
.env
+*.realm
+*.realm.lock
diff --git a/app/domain/__tests__/repository_spec.js b/app/domain/__tests__/repository_spec.js
new file mode 100644
index 0000000..a254267
--- /dev/null
+++ b/app/domain/__tests__/repository_spec.js
@@ -0,0 +1,23 @@
+import Repository from '../repository';
+
+describe("Repository", () => {
+ let subject = null;
+ const type = 'Account'
+
+ beforeEach(() => {
+ subject = new Repository();
+ });
+
+ afterEach(() => {
+ subject.deleteAll(type);
+ });
+
+ it ("can save an account", () => {
+ subject.save(type, {
+ authentication_token: 'secret'
+ })
+
+ expect(subject.count(type)).toEqual(1);
+ expect(subject.all(type)[0]['authentication_token']).toEqual('secret');
+ });
+});
diff --git a/app/domain/__tests__/user_spec.js b/app/domain/__tests__/user_spec.js
new file mode 100644
index 0000000..dfe4d26
--- /dev/null
+++ b/app/domain/__tests__/user_spec.js
@@ -0,0 +1,35 @@
+class User {
+ constructor(bodyWeight: 0) {
+ this.bodyWeight = bodyWeight;
+ }
+
+ switchTo(program) { }
+
+ nextWorkoutFor(routine) {
+ return new Workout(this.bodyWeight);
+ }
+}
+
+class StrongliftsProgram {
+ routine(name) {
+ }
+}
+
+class Workout {
+ constructor(bodyWeight = 0) {
+ this.bodyWeight = bodyWeight;
+ }
+}
+
+describe("User", () => {
+ it ("creates the next workout", function() {
+ const program = new StrongliftsProgram();
+ const user = new User(240);
+ const routineA = program.routine("A")
+
+ user.switchTo(program)
+ const workout = user.nextWorkoutFor(routineA);
+
+ expect(workout.bodyWeight).toEqual(240);
+ });
+});
diff --git a/app/domain/account.js b/app/domain/account.js
new file mode 100644
index 0000000..918c47c
--- /dev/null
+++ b/app/domain/account.js
@@ -0,0 +1,8 @@
+export default class Account {
+}
+Account.schema = {
+ name: 'Account',
+ properties: {
+ authentication_token: 'string'
+ }
+};
diff --git a/app/domain/repository.js b/app/domain/repository.js
new file mode 100644
index 0000000..8aff970
--- /dev/null
+++ b/app/domain/repository.js
@@ -0,0 +1,30 @@
+import Realm from 'realm';
+import Account from './account';
+
+export default class Repository {
+ constructor() {
+ this.realm = new Realm({
+ schema: [Account]
+ });
+ }
+
+ all(type) {
+ return this.realm.objects(type);
+ }
+
+ count(type) {
+ return this.all(type).length;
+ }
+
+ save(type, attributes) {
+ this.realm.write(() => {
+ this.realm.create(type, attributes);
+ });
+ }
+
+ deleteAll(type){
+ this.realm.write(() => {
+ this.realm.delete(this.all(type));
+ });
+ }
+}
diff --git a/app/domain/user.js b/app/domain/user.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/domain/user.js