2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.Multi.Specs {
|
2017-10-25 22:45:53 +00:00
|
|
|
testing("FakeRemoteStorage", test => {
|
2017-10-26 21:47:13 +00:00
|
|
|
test.acase("can fetch a single record", async check => {
|
2017-05-04 23:19:28 +00:00
|
|
|
let storage = new FakeRemoteStorage();
|
|
|
|
|
|
|
|
let result = await storage.find("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, null);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
await storage.upsert("test", { key: 5 }, { text: "thingy" });
|
|
|
|
|
|
|
|
result = await storage.find("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, { key: 5, text: "thingy" });
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
result = await storage.find("test", { key: 6 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, null);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
result = await storage.find("test", { key: 5, text: "thingy" });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, { key: 5, text: "thingy" });
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
result = await storage.find("notest", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, null);
|
2017-05-04 23:19:28 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.acase("inserts or updates objects", async check => {
|
2017-05-04 23:19:28 +00:00
|
|
|
let storage = new FakeRemoteStorage();
|
|
|
|
|
|
|
|
let result = await storage.search("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, []);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
await storage.upsert("test", { key: 5 }, {});
|
|
|
|
|
|
|
|
result = await storage.search("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, [{ key: 5 }]);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
await storage.upsert("test", { key: 5 }, { text: "thingy" });
|
|
|
|
|
|
|
|
result = await storage.search("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, [{ key: 5, text: "thingy" }]);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
await storage.upsert("test", { key: 5 }, { text: "other thingy" });
|
|
|
|
|
|
|
|
result = await storage.search("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(result, [{ key: 5, text: "other thingy" }]);
|
2017-05-04 23:19:28 +00:00
|
|
|
|
|
|
|
await storage.upsert("test", { key: 5, text: "things" }, {});
|
|
|
|
|
|
|
|
result = await storage.search("test", { key: 5 });
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(sortedBy(result, (x: any) => x.text), [{ key: 5, text: "other thingy" }, { key: 5, text: "things" }]);
|
2017-05-04 23:19:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|