diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-05-31 07:04:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-31 07:04:02 +0800 |
commit | dc5477be3cc62dff912a9447c702edab66200f02 (patch) | |
tree | 4c4c4293bfbc2a80812d231af9c7e22877cebfbd /test/unit/app/personal-message-manager-test.js | |
parent | 5fc24930a7febd919ec6a8f6e9c14f2bac0ef2b2 (diff) | |
parent | e59f606adb65de85484b0fb258980543967ee5e1 (diff) | |
download | tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.gz tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.bz2 tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.lz tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.xz tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.zst tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.zip |
Merge pull request #4408 from MetaMask/v4.7.0rc2
Version 4.7.0 - rc2
Diffstat (limited to 'test/unit/app/personal-message-manager-test.js')
-rw-r--r-- | test/unit/app/personal-message-manager-test.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/test/unit/app/personal-message-manager-test.js b/test/unit/app/personal-message-manager-test.js new file mode 100644 index 000000000..b07167bff --- /dev/null +++ b/test/unit/app/personal-message-manager-test.js @@ -0,0 +1,107 @@ +const assert = require('assert') + +const PersonalMessageManager = require('../../../app/scripts/lib/personal-message-manager') + +describe('Personal Message Manager', function () { + let messageManager + + beforeEach(function () { + messageManager = new PersonalMessageManager() + }) + + describe('#getMsgList', function () { + it('when new should return empty array', function () { + var result = messageManager.messages + assert.ok(Array.isArray(result)) + assert.equal(result.length, 0) + }) + it('should also return transactions from local storage if any', function () { + + }) + }) + + describe('#addMsg', function () { + it('adds a Msg returned in getMsgList', function () { + var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + var result = messageManager.messages + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].id, 1) + }) + }) + + describe('#setMsgStatusApproved', function () { + it('sets the Msg status to approved', function () { + var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + messageManager.setMsgStatusApproved(1) + var result = messageManager.messages + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'approved') + }) + }) + + describe('#rejectMsg', function () { + it('sets the Msg status to rejected', function () { + var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + messageManager.rejectMsg(1) + var result = messageManager.messages + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'rejected') + }) + }) + + describe('#_updateMsg', function () { + it('replaces the Msg with the same id', function () { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + messageManager._updateMsg({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' }) + var result = messageManager.getMsg('1') + assert.equal(result.hash, 'foo') + }) + }) + + describe('#getUnapprovedMsgs', function () { + it('returns unapproved Msgs in a hash', function () { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + const result = messageManager.getUnapprovedMsgs() + assert.equal(typeof result, 'object') + assert.equal(result['1'].status, 'unapproved') + assert.equal(result['2'], undefined) + }) + }) + + describe('#getMsg', function () { + it('returns a Msg with the requested id', function () { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + assert.equal(messageManager.getMsg('1').status, 'unapproved') + assert.equal(messageManager.getMsg('2').status, 'approved') + }) + }) + + describe('#normalizeMsgData', function () { + it('converts text to a utf8 hex string', function () { + var input = 'hello' + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '0x68656c6c6f', 'predictably hex encoded') + }) + + it('tolerates a hex prefix', function () { + var input = '0x12' + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '0x12', 'un modified') + }) + + it('tolerates normal hex', function () { + var input = '12' + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '0x12', 'adds prefix') + }) + }) +}) |