1
0
Fork 0
spacetac/src/multi/RemoteStorage.spec.ts

51 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

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 => {
let storage = new FakeRemoteStorage();
let result = await storage.find("test", { key: 5 });
2017-10-26 21:47:13 +00:00
check.equals(result, null);
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" });
result = await storage.find("test", { key: 6 });
2017-10-26 21:47:13 +00:00
check.equals(result, null);
result = await storage.find("test", { key: 5, text: "thingy" });
2017-10-26 21:47:13 +00:00
check.equals(result, { key: 5, text: "thingy" });
result = await storage.find("notest", { key: 5 });
2017-10-26 21:47:13 +00:00
check.equals(result, null);
});
2017-10-26 21:47:13 +00:00
test.acase("inserts or updates objects", async check => {
let storage = new FakeRemoteStorage();
let result = await storage.search("test", { key: 5 });
2017-10-26 21:47:13 +00:00
check.equals(result, []);
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 }]);
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" }]);
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" }]);
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" }]);
});
});
}