notices - markAllNoticesRead - use async/await

feature/default_network_editable
kumavis 6 years ago
parent 781a39c039
commit a64855ef49
  1. 2
      app/scripts/metamask-controller.js
  2. 23
      app/scripts/notice-controller.js
  3. 5
      test/unit/app/controllers/notice-controller-test.js
  4. 11
      test/unit/ui/app/actions.spec.js

@ -473,7 +473,7 @@ module.exports = class MetamaskController extends EventEmitter {
// notices
checkNotices: noticeController.updateNoticesList.bind(noticeController),
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
markAllNoticesRead: noticeController.markAllNoticesRead.bind(noticeController),
markAllNoticesRead: nodeify(noticeController.markAllNoticesRead, noticeController),
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),

@ -58,20 +58,15 @@ module.exports = class NoticeController extends EventEmitter {
}
}
markAllNoticesRead (cb) {
cb = cb || function (err) { if (err) throw err }
try {
const noticeList = this.getNoticesList()
noticeList.forEach(notice => {
notice.read = true
notice.body = ''
})
this.setNoticesList(noticeList)
const latestNotice = this.getNextUnreadNotice()
cb(null, latestNotice)
} catch (err) {
cb(err)
}
async markAllNoticesRead () {
const noticeList = this.getNoticesList()
noticeList.forEach(notice => {
notice.read = true
notice.body = ''
})
this.setNoticesList(noticeList)
const latestNotice = this.getNextUnreadNotice()
return latestNotice
}

@ -40,7 +40,7 @@ describe('notice-controller', function () {
})
describe('#markAllNoticesRead', () => {
it('marks all notices read', (done) => {
it('marks all notices read', async () => {
const testList = [{
id: 0,
read: false,
@ -57,11 +57,10 @@ describe('notice-controller', function () {
noticeController.setNoticesList(testList)
noticeController.markAllNoticesRead()
await noticeController.markAllNoticesRead()
const unreadNotices = noticeController.getUnreadNotices()
assert.equal(unreadNotices.length, 0)
done()
})
})

@ -1321,14 +1321,11 @@ describe('Actions', () => {
completeOnboardingSpy.restore()
})
it('', (done) => {
it('completing onboarding marks all notices as read', async () => {
const store = mockStore()
store.dispatch(actions.setCompletedOnboarding())
.then(() => {
assert.equal(markAllNoticesReadSpy.callCount, 1)
assert.equal(completeOnboardingSpy.callCount, 1)
})
done()
await store.dispatch(actions.setCompletedOnboarding())
assert.equal(markAllNoticesReadSpy.callCount, 1)
assert.equal(completeOnboardingSpy.callCount, 1)
})
})

Loading…
Cancel
Save