Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
feat(AccountInfo): notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgithubusername committed Jul 28, 2016
1 parent 1c9fd41 commit 54e4bd4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/account-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ function AccountInfo (object) {
this._isMobileVerified = Boolean(object.sms_verified);

this._currency = object.currency;

var notifications = {};
if (object.notifications_type) {
var mapped = object.notifications_type.map(Math.log2);
notifications = {
email: Boolean(~mapped.indexOf(0)),
http: Boolean(~mapped.indexOf(2)),
sms: Boolean(~mapped.indexOf(5))
};
}
this._notifications = notifications;
}

Object.defineProperties(AccountInfo.prototype, {
Expand Down Expand Up @@ -65,5 +76,9 @@ Object.defineProperties(AccountInfo.prototype, {
'currency': {
configurable: false,
get: function () { return this._currency; }
},
'notifications': {
configurable: false,
get: function () { return this._notifications; }
}
});
22 changes: 21 additions & 1 deletion tests/account_info_spec.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe "AccountInfo", ->
# Typical result from get-info:
o =
btc_currency: "BTC"
notifications_type: []
notifications_type: [32]
language: "nl"
notifications_on: 2,
ip_lock_on:0,
Expand Down Expand Up @@ -87,3 +87,23 @@ describe "AccountInfo", ->
it "should get the users currency", ->
i = new AccountInfo(o)
expect(i.currency).toEqual("EUR")

it "should get the notification status", ->
i = new AccountInfo(o)
expect(i.notifications.email).toEqual(false)
expect(i.notifications.sms).toEqual(true)

it "should have email notifications enabled", ->
o.notifications_type = [1]
i = new AccountInfo(o)
expect(i.notifications.email).toEqual(true)

it "should have SMS notifications enabled", ->
o.notifications_type = [32]
i = new AccountInfo(o)
expect(i.notifications.sms).toEqual(true)

it "should have HTTP notifications enabled", ->
o.notifications_type = [4]
i = new AccountInfo(o)
expect(i.notifications.http).toEqual(true)

0 comments on commit 54e4bd4

Please sign in to comment.