aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/address-book-controller.js
blob: 51dc898b8d05441daf4decf69fec7fdbcbe2fc54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const assert = require('assert')
const extend = require('xtend')
const AddressBookController = require('../../app/scripts/controllers/address-book')

describe('address-book-controller', function() {
  var addressBookController

  beforeEach(function() {
    addressBookController = new AddressBookController()
  })

  describe('addres book management', function () {
    describe('#_getAddressBook', function () {
      it('should be empty by default.', function () {
        assert.equal(addressBookController._getAddressBook().length, 0)
      })
    })
    describe('#setAddressBook', function () {
      it('should properly set a new address.', function () {
        addressBookController.setAddressBook('0x01234', 'test')
        var addressBook = addressBookController._getAddressBook()
        assert.equal(addressBook.length, 1, 'incorrect address book length.')
        assert.equal(addressBook[0].address, '0x01234', 'incorrect addresss')
        assert.equal(addressBook[0].name, 'test', 'incorrect nickname')
      })

      it('should reject duplicates.', function () {
        addressBookController.setAddressBook('0x01234', 'test')
        addressBookController.setAddressBook('0x01234', 'test')
        var addressBook = addressBookController._getAddressBook()
        assert.equal(addressBook.length, 1, 'incorrect address book length.')
      })
    })
  })
})