Skip to content

Commit

Permalink
Fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
OGPoyraz committed Jan 16, 2025
1 parent 4613b8c commit 445749e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
55 changes: 41 additions & 14 deletions packages/approval-controller/src/ApprovalController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,29 @@ describe('approval controller', () => {
origin: 'bar.baz',
type: 'myType',
});
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/no-floating-promises

approvalController.accept('foo', 'success');

Check failure on line 830 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

const result = await approvalPromise;
expect(result).toBe('success');
});

it('emits "accepted" event', async () => {
const acceptedEvent = jest.fn();
messenger.subscribe('ApprovalController:accepted', acceptedEvent);

const approvalPromise = approvalController.add({
id: 'foo',
origin: 'bar.baz',
type: 'myType',
});

approvalController.accept('foo', 'success');

Check failure on line 846 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

await approvalPromise;

expect(acceptedEvent.mock.calls[0][0]).toEqual({
approval: expect.objectContaining({
request: expect.objectContaining({
id: 'foo',
origin: 'bar.baz',
type: 'myType',
Expand All @@ -855,15 +869,11 @@ describe('approval controller', () => {
type: 'myType2',
});

// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
approvalController.accept('foo2', 'success2');

Check failure on line 872 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

let result = await approvalPromise2;
expect(result).toBe('success2');

// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
approvalController.accept('foo1', 'success1');

Check failure on line 877 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

result = await approvalPromise1;
Expand Down Expand Up @@ -1093,15 +1103,32 @@ describe('approval controller', () => {
});
approvalController.reject('foo', rejectedError);
await expect(approvalPromise).rejects.toThrow(rejectedError);
});

expect(rejectedEvent.mock.calls[0][0]).toEqual({
approval: expect.objectContaining({
id: 'foo',
origin: 'bar.baz',
type: TYPE,
}),
error: rejectedError,
it('emits "rejected" event', async () => {
const rejectedEvent = jest.fn();
messenger.subscribe('ApprovalController:rejected', rejectedEvent);

const rejectedError = new Error('failure');
const approvalPromise = approvalController.add({
id: 'foo',
origin: 'bar.baz',
type: TYPE,
});
approvalController.reject('foo', rejectedError);

try {
await approvalPromise;
} catch (error) {
expect(rejectedEvent.mock.calls[0][0]).toEqual({

Check failure on line 1123 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Avoid calling `expect` conditionally`
request: expect.objectContaining({

Check failure on line 1124 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Avoid calling `expect` conditionally`
id: 'foo',
origin: 'bar.baz',
type: TYPE,
}),
error: rejectedError,
});
}
});

it('rejects multiple approval promises out of order', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/approval-controller/src/ApprovalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export type ApprovalRejectedEvent = {
type: `${typeof controllerName}:rejected`;
payload: [
{
approval: ApprovalRequest<ApprovalRequestData>;
request: ApprovalRequest<ApprovalRequestData>;
error: Error;
},
];
Expand All @@ -342,7 +342,7 @@ export type ApprovalAcceptedEvent = {
type: `${typeof controllerName}:accepted`;
payload: [
{
approval: ApprovalRequest<ApprovalRequestData>;
request: ApprovalRequest<ApprovalRequestData>;
},
];
};
Expand Down Expand Up @@ -752,7 +752,7 @@ export class ApprovalController extends BaseController<
this.#delete(id);
}
this.messagingSystem.publish(`${controllerName}:accepted`, {
approval,
request: approval,
});
});
}
Expand All @@ -772,7 +772,7 @@ export class ApprovalController extends BaseController<
this.#delete(id);
callbacks.reject(error);
this.messagingSystem.publish(`${controllerName}:rejected`, {
approval: rejectedApproval,
request: rejectedApproval,
error: error as Error,
});
}
Expand Down

0 comments on commit 445749e

Please sign in to comment.