A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/lib/message-manager.test.js

129 lines
3.7 KiB

import assert from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import MessageManager from './message-manager';
describe('Message Manager', function () {
let messageManager;
8 years ago
beforeEach(function () {
messageManager = new MessageManager();
});
8 years ago
describe('#getMsgList', function () {
it('when new should return empty array', function () {
const result = messageManager.messages;
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
});
});
8 years ago
describe('#addMsg', function () {
it('adds a Msg returned in getMsgList', function () {
const Msg = {
id: 1,
status: TRANSACTION_STATUSES.APPROVED,
metamaskNetworkId: 'unit test',
};
messageManager.addMsg(Msg);
const result = messageManager.messages;
assert.ok(Array.isArray(result));
assert.equal(result.length, 1);
assert.equal(result[0].id, 1);
});
});
8 years ago
describe('#setMsgStatusApproved', function () {
it('sets the Msg status to approved', function () {
const Msg = {
id: 1,
status: 'unapproved',
metamaskNetworkId: 'unit test',
};
messageManager.addMsg(Msg);
messageManager.setMsgStatusApproved(1);
const result = messageManager.messages;
assert.ok(Array.isArray(result));
assert.equal(result.length, 1);
assert.equal(result[0].status, TRANSACTION_STATUSES.APPROVED);
});
});
8 years ago
describe('#rejectMsg', function () {
it('sets the Msg status to rejected', function () {
const Msg = {
id: 1,
status: 'unapproved',
metamaskNetworkId: 'unit test',
};
messageManager.addMsg(Msg);
messageManager.rejectMsg(1);
const result = messageManager.messages;
assert.ok(Array.isArray(result));
assert.equal(result.length, 1);
assert.equal(result[0].status, TRANSACTION_STATUSES.REJECTED);
});
});
8 years ago
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: TRANSACTION_STATUSES.APPROVED,
metamaskNetworkId: 'unit test',
});
messageManager._updateMsg({
id: '1',
status: 'blah',
hash: 'foo',
metamaskNetworkId: 'unit test',
});
const result = messageManager.getMsg('1');
assert.equal(result.hash, 'foo');
});
});
8 years ago
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: TRANSACTION_STATUSES.APPROVED,
metamaskNetworkId: 'unit test',
});
const result = messageManager.getUnapprovedMsgs();
assert.equal(typeof result, 'object');
assert.equal(result['1'].status, 'unapproved');
assert.equal(result['2'], undefined);
});
});
8 years ago
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: TRANSACTION_STATUSES.APPROVED,
metamaskNetworkId: 'unit test',
});
assert.equal(messageManager.getMsg('1').status, 'unapproved');
assert.equal(
messageManager.getMsg('2').status,
TRANSACTION_STATUSES.APPROVED,
);
});
});
});