aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-01-24 21:14:00 +0800
committerDan <danjm.com@gmail.com>2018-01-24 21:14:00 +0800
commit598390e83ec68feaef256c0cfa3a239c6595475a (patch)
tree5c357247d1c29e9edf9406775d4400ccda6083a6
parentb7ae77f57a0e2bc68e9548364baa120805a1420c (diff)
downloadtangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar.gz
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar.bz2
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar.lz
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar.xz
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.tar.zst
tangerine-wallet-browser-598390e83ec68feaef256c0cfa3a239c6595475a.zip
Finish tests for extension-store fetch and sync.
-rw-r--r--test/unit/extension-store-test.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/test/unit/extension-store-test.js b/test/unit/extension-store-test.js
index e3b5713fb..e32f37d3c 100644
--- a/test/unit/extension-store-test.js
+++ b/test/unit/extension-store-test.js
@@ -1,5 +1,18 @@
const assert = require('assert')
+const sinon = require('sinon')
+const KEYS_TO_SYNC = ['KeyringController', 'PreferencesController']
+const mockSyncGetResult = 123
+const syncGetStub = sinon.stub().callsFake((str, cb) => cb(mockSyncGetResult))
+const syncSetStub = sinon.stub().callsFake((str, cb) => cb())
+
+window.storage = {
+ sync: {
+ get: syncGetStub,
+ set: syncSetStub,
+ },
+}
+window.runtime = {}
const ExtensionStore = require('../../app/scripts/lib/extension-store')
describe('Extension Store', function () {
@@ -11,19 +24,44 @@ describe('Extension Store', function () {
describe('#fetch', function () {
it('should return a promise', function () {
-
+ const extensionStoreFetchResult = extensionStore.fetch()
+ assert.ok(Promise.resolve(extensionStoreFetchResult) === extensionStoreFetchResult)
})
- it('after promise resolution, should have loaded the proper data from the extension', function () {
-
+ it('after promise resolution, should have loaded the proper data from the extension', function (done) {
+ extensionStore.fetch()
+ .then((result) => {
+ assert.deepEqual(syncGetStub.getCall(0).args[0], KEYS_TO_SYNC.slice(0))
+ assert.equal(result, mockSyncGetResult)
+ done()
+ })
})
})
describe('#sync', function () {
it('should return a promise', function () {
-
+ const extensionStoreSyncResult = extensionStore.sync()
+ assert.ok(Promise.resolve(extensionStoreSyncResult) === extensionStoreSyncResult)
})
- it('after promise resolution, should have synced the proper data from the extension', function () {
-
+ it('after promise resolution, should have synced the proper data from the extension', function (done) {
+ const mockState = {
+ data: {
+ KeyringController: 5,
+ PreferencesController: 6,
+ someOtherData: 7
+ },
+ someOtherProp: {
+ evenMoreData: 8,
+ },
+ }
+ const expectedDataToSync = {
+ KeyringController: 5,
+ PreferencesController: 6,
+ }
+ extensionStore.sync(mockState)
+ .then(() => {
+ assert.deepEqual(syncSetStub.getCall(0).args[0], expectedDataToSync)
+ done()
+ })
})
})
})