aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-02-02 03:54:01 +0800
committerFrankie <frankie.diamond@gmail.com>2017-02-02 03:54:01 +0800
commit1b16b4624186265ccbb6f8106e1bf9ff997e2528 (patch)
tree56dad7e72c2983b786c454a398ed098415eff290 /test
parentf40629e5ae7d284e871d9dcd8b62fce34b6f2b39 (diff)
downloadtangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.gz
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.bz2
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.lz
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.xz
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.zst
tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.zip
code clan up and tests
Diffstat (limited to 'test')
-rw-r--r--test/unit/message-manager-test.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/unit/message-manager-test.js b/test/unit/message-manager-test.js
new file mode 100644
index 000000000..68b977058
--- /dev/null
+++ b/test/unit/message-manager-test.js
@@ -0,0 +1,98 @@
+const assert = require('assert')
+const extend = require('xtend')
+const EventEmitter = require('events')
+
+const MessageManger = require('../../app/scripts/lib/message-manager')
+
+describe('Transaction Manager', function() {
+ let messageManager
+
+ beforeEach(function() {
+ messageManager = new MessageManger ()
+ })
+
+ describe('#getMsgList', function() {
+ it('when new should return empty array', function() {
+ var result = messageManager.getMsgList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 0)
+ })
+ it('should also return transactions from local storage if any', function() {
+
+ })
+ })
+
+ describe('#_saveMsgList', function() {
+ it('saves the submitted data to the Msg list', function() {
+ var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }]
+ messageManager._saveMsgList(target)
+ var result = messageManager.getMsgList()
+ assert.equal(result[0].foo, 'bar')
+ })
+ })
+
+ 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.getMsgList()
+ 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.getMsgList()
+ 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.getMsgList()
+ 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' })
+ let 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')
+ })
+ })
+})