1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/test/unit/message-manager-test.js

87 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-02-01 20:54:01 +01:00
const assert = require('assert')
const MessageManger = require('../../app/scripts/lib/message-manager')
describe('Message Manager', function () {
2017-02-01 20:54:01 +01:00
let messageManager
2017-05-04 23:35:10 +02:00
beforeEach(function () {
messageManager = new MessageManger()
2017-02-01 20:54:01 +01:00
})
2017-05-04 23:35:10 +02:00
describe('#getMsgList', function () {
it('when new should return empty array', function () {
var result = messageManager.messages
2017-02-01 20:54:01 +01:00
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
2017-05-04 23:35:10 +02:00
it('should also return transactions from local storage if any', function () {
2017-02-01 20:54:01 +01:00
})
})
2017-05-04 23:35:10 +02:00
describe('#addMsg', function () {
it('adds a Msg returned in getMsgList', function () {
2017-02-01 20:54:01 +01:00
var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
var result = messageManager.messages
2017-02-01 20:54:01 +01:00
assert.ok(Array.isArray(result))
assert.equal(result.length, 1)
assert.equal(result[0].id, 1)
})
})
2017-05-04 23:35:10 +02:00
describe('#setMsgStatusApproved', function () {
it('sets the Msg status to approved', function () {
2017-02-01 20:54:01 +01:00
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.setMsgStatusApproved(1)
var result = messageManager.messages
2017-02-01 20:54:01 +01:00
assert.ok(Array.isArray(result))
assert.equal(result.length, 1)
assert.equal(result[0].status, 'approved')
})
})
2017-05-04 23:35:10 +02:00
describe('#rejectMsg', function () {
it('sets the Msg status to rejected', function () {
2017-02-01 20:54:01 +01:00
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.rejectMsg(1)
var result = messageManager.messages
2017-02-01 20:54:01 +01:00
assert.ok(Array.isArray(result))
assert.equal(result.length, 1)
assert.equal(result[0].status, 'rejected')
})
})
2017-05-04 23:35:10 +02:00
describe('#_updateMsg', function () {
it('replaces the Msg with the same id', function () {
2017-02-01 20:54:01 +01:00
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')
})
})
2017-05-04 23:35:10 +02:00
describe('#getUnapprovedMsgs', function () {
it('returns unapproved Msgs in a hash', function () {
2017-02-01 20:54:01 +01:00
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
2017-05-04 23:35:10 +02:00
const result = messageManager.getUnapprovedMsgs()
2017-02-01 20:54:01 +01:00
assert.equal(typeof result, 'object')
assert.equal(result['1'].status, 'unapproved')
assert.equal(result['2'], undefined)
})
})
2017-05-04 23:35:10 +02:00
describe('#getMsg', function () {
it('returns a Msg with the requested id', function () {
2017-02-01 20:54:01 +01:00
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')
})
})
})