Skip to content

Commit

Permalink
Merge pull request #69 from PolymerElements/indexeddb-mirror-session-…
Browse files Browse the repository at this point in the history
…dirty-check

Ignore session changes when session is undefined.
  • Loading branch information
cdata authored Sep 29, 2016
2 parents a9c34e9 + f5f723a commit 6b7b7df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app-indexeddb-mirror/app-indexeddb-mirror-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
* the session has been validated.
*/
validateSession: function(session) {
if (session === undefined) {
// Ignore session `undefined` conventionally, as it means the session
// (such as the user ID) has not been initialized yet.
return;
}

return this.post({
type: 'app-mirror-validate-session',
session: session
Expand Down
36 changes: 35 additions & 1 deletion test/app-indexeddb-mirror/app-indexeddb-mirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@
<template>
<app-indexeddb-mirror
session="test"
key="basic-mirror" log>
key="basic-mirror">
</app-indexeddb-mirror>
</template>
</test-fixture>

<test-fixture id="NoSessionMirror">
<template>
<app-indexeddb-mirror
key="basic-mirror">
</app-indexeddb-mirror>
</template>
</test-fixture>
Expand Down Expand Up @@ -113,6 +121,32 @@
});
});

suite('when session is set lazily', function() {
var secondMirror;

setup(function() {
mirror.data = {
foo: 'bar'
};
secondMirror = fixture('NoSessionMirror');
return Promise.all([
mirror.transactionsComplete,
secondMirror.transactionsComplete
]);
});

test('the data is preserved', function() {
if (!mirror.client.supportsMirroring) {
return;
}

secondMirror.session = 'test';
return secondMirror.transactionsComplete.then(function() {
return expectPersistedValue('basic-mirror', mirror.data);
});
});
});

suite('when offline', function() {
test('boots up with persisted value', function() {
if (!mirror.client.supportsMirroring) {
Expand Down

0 comments on commit 6b7b7df

Please sign in to comment.