Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Fix Bug 1467449 - ASRouter sets bundle to null
Browse files Browse the repository at this point in the history
  • Loading branch information
piatra committed Jun 8, 2018
1 parent 7e54494 commit dcd14a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/ASRouter.jsm
Expand Up @@ -253,12 +253,8 @@ class _ASRouter {
return state.messages.filter(item => !state.blockList.includes(item.id));
}

async sendNextMessage(target) {
_sendMessageToTarget(message, target) {
let bundledMessages;
const msgs = this._getUnblockedMessages();
let message = await ASRouterTargeting.findMatchingMessage(msgs);
await this.setState({lastMessageId: message ? message.id : null});

// If this message needs to be bundled with other messages of the same template, find them and bundle them together
if (message && message.bundled) {
bundledMessages = this._getBundledMessages(message);
Expand All @@ -274,18 +270,19 @@ class _ASRouter {
}
}

async sendNextMessage(target) {
const msgs = this._getUnblockedMessages();
let message = await ASRouterTargeting.findMatchingMessage(msgs);
await this.setState({lastMessageId: message ? message.id : null});

this._sendMessageToTarget(message, target);
}

async setMessageById(id) {
await this.setState({lastMessageId: id});
const newMessage = this.getMessageById(id);
if (newMessage) {
// If this message needs to be bundled with other messages of the same template, find them and bundle them together
if (newMessage.bundled) {
let bundledMessages = this._getBundledMessages(newMessage);
this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, {type: "SET_BUNDLED_MESSAGES", data: bundledMessages});
} else {
this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, {type: "SET_MESSAGE", data: newMessage});
}
}

this._sendMessageToTarget(newMessage, this.messageChannel);
}

async blockById(idOrIds) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/asrouter/ASRouter.test.js
Expand Up @@ -348,6 +348,13 @@ describe("ASRouter", () => {

assert.calledWith(channel.sendAsyncMessage, PARENT_TO_CHILD_MESSAGE_NAME, {type: "SET_MESSAGE", data: testMessage});
});

it("should broadcast CLEAR_ALL if provided id did not resolve to a message", async () => {
const msg = fakeAsyncMessage({type: "OVERRIDE_MESSAGE", data: {id: -1}});
await Router.onMessage(msg);

assert.calledWith(channel.sendAsyncMessage, PARENT_TO_CHILD_MESSAGE_NAME, {type: "CLEAR_ALL"});
});
});

describe("#onMessage: Onboarding actions", () => {
Expand Down

0 comments on commit dcd14a7

Please sign in to comment.