Skip to content

Commit

Permalink
refactor: storage tests (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viatorus authored Sep 27, 2017
1 parent ed939af commit 2ab7a1e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@
import {Loki} from "../../../loki/src/loki";
import {LokiFSStorage} from "../../src/fs_storage";

describe("testing persistence adapter", function () {
describe("testing fs storage", function () {
it("LokiFSStorage", function (done) {
const db = new Loki("myTestApp");

const adapter = {adapter: new LokiFSStorage()};
db.initializePersistence(adapter)
.then(() => {
db.addCollection("myColl").insert({name: "Hello World"});
return db.saveDatabase().then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase()
.then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
});
});
return db.saveDatabase();
})
.then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase();
}).then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
})
.then(() => {
const db3 = new Loki("other");
return db3.initializePersistence(adapter)
.then(() => {
return db3.loadDatabase()
.then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
return db3.loadDatabase();
}).then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
})
.then(() => {
Expand Down
33 changes: 16 additions & 17 deletions packages/indexed-storage/spec/web/indexed_storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {Loki} from "../../../loki/src/loki";
import {LokiIndexedStorage} from "../../src/indexed_storage";

describe("testing persistence adapter", function () {
describe("testing indexed storage", function () {
it("LokiIndexedStorage", function (done) {
const db = new Loki("myTestApp");

Expand All @@ -11,27 +11,26 @@ describe("testing persistence adapter", function () {
db.initializePersistence(adapter)
.then(() => {
db.addCollection("myColl").insert({name: "Hello World"});
return db.saveDatabase().then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase()
.then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
});
});
return db.saveDatabase();
})
.then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase();
}).then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
})
.then(() => {
const db3 = new Loki("other");
return db3.initializePersistence(adapter)
.then(() => {
return db3.loadDatabase()
.then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
return db3.loadDatabase();
}).then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
})
.then(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/indexed-storage/src/indexed_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {Loki} from "../../loki/src/loki";
adapter.saveDatabase("UserDatabase", JSON.stringify(myDb));
adapter.loadDatabase("UserDatabase"); // will log the serialized db to console
adapter.deleteDatabase("UserDatabase");
Should usercallback be still used?
*/

/**
Expand Down
33 changes: 16 additions & 17 deletions packages/local-storage/spec/web/local_storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {Loki} from "../../../loki/src/loki";
import {LokiLocalStorage} from "../../src/local_storage";

describe("testing persistence adapter", function () {
describe("testing local storage", function () {
it("LokiLocalStorage", function (done) {
const db = new Loki("myTestApp");

Expand All @@ -11,27 +11,26 @@ describe("testing persistence adapter", function () {
db.initializePersistence(adapter)
.then(() => {
db.addCollection("myColl").insert({name: "Hello World"});
return db.saveDatabase().then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase()
.then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
});
});
return db.saveDatabase();
})
.then(() => {
const db2 = new Loki("myTestApp");
return db2.initializePersistence(adapter)
.then(() => {
return db2.loadDatabase();
}).then(() => {
expect(db2.getCollection("myColl").find()[0].name).toEqual("Hello World");
});
})
.then(() => {
const db3 = new Loki("other");
return db3.initializePersistence(adapter)
.then(() => {
return db3.loadDatabase()
.then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
return db3.loadDatabase();
}).then(() => {
expect(false).toEqual(true);
}, () => {
expect(true).toEqual(true);
});
})
.then(() => {
Expand Down

0 comments on commit 2ab7a1e

Please sign in to comment.