diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/lib/encryptor-test.js | 71 | ||||
-rw-r--r-- | test/unit/config-manager-test.js | 6 | ||||
-rw-r--r-- | test/unit/notice-controller-test.js | 115 |
3 files changed, 118 insertions, 74 deletions
diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js deleted file mode 100644 index 897d22740..000000000 --- a/test/integration/lib/encryptor-test.js +++ /dev/null @@ -1,71 +0,0 @@ -var encryptor = require('../../../app/scripts/lib/encryptor') - -QUnit.module('encryptor') - -QUnit.test('encryptor:serializeBufferForStorage', function (assert) { - assert.expect(1) - var buf = new Buffer(2) - buf[0] = 16 - buf[1] = 1 - - var output = encryptor.serializeBufferForStorage(buf) - - var expect = '0x1001' - assert.equal(expect, output) -}) - -QUnit.test('encryptor:serializeBufferFromStorage', function (assert) { - assert.expect(2) - var input = '0x1001' - var output = encryptor.serializeBufferFromStorage(input) - - assert.equal(output[0], 16) - assert.equal(output[1], 1) -}) - -QUnit.test('encryptor:encrypt & decrypt', function(assert) { - var done = assert.async(); - var password, data, encrypted - - password = 'a sample passw0rd' - data = { foo: 'data to encrypt' } - - encryptor.encrypt(password, data) - .then(function(encryptedStr) { - assert.equal(typeof encryptedStr, 'string', 'returns a string') - return encryptor.decrypt(password, encryptedStr) - }) - .then(function (decryptedObj) { - assert.deepEqual(decryptedObj, data, 'decrypted what was encrypted') - done() - }) - .catch(function(reason) { - assert.ifError(reason, 'threw an error') - done(reason) - }) - -}) - -QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) { - var done = assert.async(); - var password, data, encrypted, wrongPassword - - password = 'a sample passw0rd' - wrongPassword = 'a wrong password' - data = { foo: 'data to encrypt' } - - encryptor.encrypt(password, data) - .then(function(encryptedStr) { - assert.equal(typeof encryptedStr, 'string', 'returns a string') - return encryptor.decrypt(wrongPassword, encryptedStr) - }) - .then(function (decryptedObj) { - assert.equal(!decryptedObj, true, 'Wrong password should not decrypt') - done() - }) - .catch(function(reason) { - done() - }) -}) - - diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 206460ffb..477188b67 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,12 +1,12 @@ const assert = require('assert') const extend = require('xtend') -const STORAGE_KEY = 'metamask-persistance-key' -var configManagerGen = require('../lib/mock-config-manager') -var configManager const rp = require('request-promise') const nock = require('nock') +var configManagerGen = require('../lib/mock-config-manager') +const STORAGE_KEY = 'metamask-persistance-key' describe('config-manager', function() { + var configManager beforeEach(function() { window.localStorage = {} // Hacking localStorage support into JSDom diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js new file mode 100644 index 000000000..4aa4c8e7b --- /dev/null +++ b/test/unit/notice-controller-test.js @@ -0,0 +1,115 @@ +const assert = require('assert') +const extend = require('xtend') +const rp = require('request-promise') +const nock = require('nock') +const configManagerGen = require('../lib/mock-config-manager') +const NoticeController = require('../../app/scripts/notice-controller') +const STORAGE_KEY = 'metamask-persistance-key' +// Hacking localStorage support into JSDom +window.localStorage = {} + +describe('notice-controller', function() { + var noticeController + + beforeEach(function() { + let configManager = configManagerGen() + noticeController = new NoticeController({ + configManager: configManager, + }) + }) + + describe('notices', function() { + describe('#getNoticesList', function() { + it('should return an empty array when new', function() { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + var result = noticeController.getNoticesList() + assert.equal(result.length, 0) + }) + }) + + describe('#setNoticesList', function() { + it('should set data appropriately', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + var testListId = noticeController.getNoticesList()[0].id + assert.equal(testListId, 0) + }) + }) + + describe('#updateNoticeslist', function() { + it('should integrate the latest changes from the source', function() { + var testList = [{ + id:55, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.updateNoticesList().then(() => { + var newList = noticeController.getNoticesList() + assert.ok(newList[0].id === 55) + assert.ok(newList[1]) + }) + }) + it('should not overwrite any existing fields', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.updateNoticesList().then(() => { + var newList = noticeController.getNoticesList() + assert.equal(newList[0].id, 0) + assert.equal(newList[0].title, "Futuristic Notice") + assert.equal(newList.length, 1) + }) + }) + }) + + describe('#markNoticeRead', function () { + it('should mark a notice as read', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.markNoticeRead(testList[0]) + var newList = noticeController.getNoticesList() + assert.ok(newList[0].read) + }) + }) + + describe('#getLatestUnreadNotice', function () { + it('should retrieve the latest unread notice', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:false,title:"Current Notice"}, + {id:2,read:false,title:"Future Notice"}, + ] + noticeController.setNoticesList(testList) + var latestUnread = noticeController.getLatestUnreadNotice() + assert.equal(latestUnread.id, 2) + }) + it('should return undefined if no unread notices exist.', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:true,title:"Current Notice"}, + {id:2,read:true,title:"Future Notice"}, + ] + noticeController.setNoticesList(testList) + var latestUnread = noticeController.getLatestUnreadNotice() + assert.ok(!latestUnread) + }) + }) + }) + +}) |