Sfoglia il codice sorgente

Finish state database tests.

Afshin Darian 8 anni fa
parent
commit
8ac836ff26
1 ha cambiato i file con 57 aggiunte e 0 eliminazioni
  1. 57 0
      test/src/statedb/statedb.spec.ts

+ 57 - 0
test/src/statedb/statedb.spec.ts

@@ -103,6 +103,20 @@ describe('StateDB', () => {
         .catch(done);
     });
 
+    it('should resolve a nonexistent key fetch with null', done => {
+      let { localStorage } = window;
+      localStorage.clear();
+
+      let db = new StateDB({ namespace: 'test-namespace' });
+      let key = 'foo:bar';
+
+      expect(localStorage.length).to.be(0);
+      db.fetch(key)
+        .then(fetched => { expect(fetched).to.be(null); })
+        .then(done)
+        .catch(done);
+    });
+
   });
 
   describe('#fetchNamespace()', () => {
@@ -152,4 +166,47 @@ describe('StateDB', () => {
 
   });
 
+  describe('#remove()', () => {
+
+    it('should remove a stored key', done => {
+      let { localStorage } = window;
+      localStorage.clear();
+
+      let db = new StateDB({ namespace: 'test-namespace' });
+      let key = 'foo:bar';
+      let value = { baz: 'qux' };
+
+      expect(localStorage.length).to.be(0);
+      db.save(key, value)
+        .then(() => { expect(localStorage).to.have.length(1); })
+        .then(() => db.remove(key))
+        .then(() => { expect(localStorage).to.be.empty(); })
+        .then(done)
+        .catch(done);
+    });
+
+  });
+
+  describe('#save()', () => {
+
+    it('should save a key and a value', done => {
+      let { localStorage } = window;
+      localStorage.clear();
+
+      let db = new StateDB({ namespace: 'test-namespace' });
+      let key = 'foo:bar';
+      let value = { baz: 'qux' };
+
+      expect(localStorage.length).to.be(0);
+      db.save(key, value)
+        .then(() => db.fetch(key))
+        .then(fetched => { expect(fetched).to.eql(value); })
+        .then(() => db.remove(key))
+        .then(() => { expect(localStorage).to.be.empty(); })
+        .then(done)
+        .catch(done);
+    });
+
+  });
+
 });