From 3cb0f3fa7f06a7a8ca40842ea7a1e02d1bd6c2d8 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Feb 2015 16:09:29 -0800 Subject: [PATCH] [Tests] Add tests for persistence cache Add test cases for persistence cache to improve overall test coverage, WTD-672. --- .../test/CachingPersistenceDecoratorSpec.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/platform/persistence/cache/test/CachingPersistenceDecoratorSpec.js b/platform/persistence/cache/test/CachingPersistenceDecoratorSpec.js index 4088fda79e..115ea208b2 100644 --- a/platform/persistence/cache/test/CachingPersistenceDecoratorSpec.js +++ b/platform/persistence/cache/test/CachingPersistenceDecoratorSpec.js @@ -88,6 +88,36 @@ define( expect(mockCallback.calls[0].args[0]) .toBe(mockCallback.calls[1].args[0]); }); + + it("maintains the same cached instance between reads/writes", function () { + var testObject = { abc: "XYZ!" }; + + // Perform two reads with a write in between + decorator.readObject(testSpace, "someKey", "someValue") + .then(mockCallback); + decorator.updateObject(testSpace, "someKey", testObject); + decorator.readObject(testSpace, "someKey", "someValue") + .then(mockCallback); + + // Results should have been pointer-identical + expect(mockCallback.calls[0].args[0]) + .toBe(mockCallback.calls[1].args[0]); + + // But contents should have been equal to the written object + expect(mockCallback).toHaveBeenCalledWith(testObject); + }); + + it("is capable of reading/writing strings", function () { + // Efforts made to keep cached objects pointer-identical + // would break on strings - so make sure cache isn't + // breaking when we read/write strings. + decorator.createObject(testSpace, "someKey", "someValue"); + decorator.updateObject(testSpace, "someKey", "someOtherValue"); + decorator.readObject(testSpace, "someKey").then(mockCallback); + expect(mockCallback).toHaveBeenCalledWith("someOtherValue"); + + + }); }); } ); \ No newline at end of file