Skip to content

Commit a80e8d7

Browse files
GudahttMajorLift
authored andcommitted
Fix AbstractMessageManager error (#367)
The error thrown when trying to set the status of a non-existent message was broken. The first variable in the error message resolved to `undefined`. It has been updated to reference the type of the controller that threw the error.
1 parent db8cf75 commit a80e8d7

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/message-manager/AbstractMessageManager.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class AbstractTestManager extends AbstractMessageManager<TypedMessage, TypedMess
1111
delete messageParams.version;
1212
return Promise.resolve(messageParams);
1313
}
14+
15+
setMessageStatus(messageId: string, status: string) {
16+
return super.setMessageStatus(messageId, status);
17+
}
1418
}
1519
const typedMessage = [
1620
{
@@ -175,4 +179,29 @@ describe('AbstractTestManager', () => {
175179
expect(message.status).toEqual('approved');
176180
}
177181
});
182+
183+
describe('setMessageStatus', () => {
184+
it('should set the given message status', () => {
185+
const controller = new AbstractTestManager();
186+
controller.addMessage({
187+
id: messageId,
188+
messageParams: { from: '0x1234', data: 'test' },
189+
status: 'status',
190+
time: 10,
191+
type: 'type',
192+
});
193+
const messageBefore = controller.getMessage(messageId);
194+
expect(messageBefore && messageBefore.status).toEqual('status');
195+
196+
controller.setMessageStatus(messageId, 'newstatus');
197+
const messageAfter = controller.getMessage(messageId);
198+
expect(messageAfter && messageAfter.status).toEqual('newstatus');
199+
});
200+
201+
it('should throw an error if message is not found', () => {
202+
const controller = new AbstractTestManager();
203+
204+
expect(() => controller.setMessageStatus(messageId, 'newstatus')).toThrow('AbstractMessageManager: Message not found for id: 1.');
205+
});
206+
});
178207
});

src/message-manager/AbstractMessageManager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ export abstract class AbstractMessageManager<
9999
*/
100100
protected setMessageStatus(messageId: string, status: string) {
101101
const message = this.getMessage(messageId);
102-
/* istanbul ignore if */
103102
if (!message) {
104-
throw new Error(`${this.context[name]}- Message not found for id: ${messageId}.`);
103+
throw new Error(`${this.name}: Message not found for id: ${messageId}.`);
105104
}
106105
message.status = status;
107106
this.updateMessage(message);

0 commit comments

Comments
 (0)