Skip to content

Commit 704f830

Browse files
committed
fix lint
1 parent 011b31f commit 704f830

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

‎packages/api/src/tasks/checkAlerts/transports/__tests__/generic.test.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,16 @@ describe('handleSendGenericWebhook — DNS resolution', () => {
103103
.mockImplementationOnce(jest.requireActual('undici').fetch);
104104
const lookupSpy = jest
105105
.spyOn(dns, 'lookup')
106-
.mockImplementation(((_h: string, _o: unknown, cb: any) =>
107-
cb(null, [{ address: '127.0.0.1', family: 4 }])) as any);
106+
.mockImplementation((...args: any[]) =>
107+
args[2](null, [{ address: '127.0.0.1', family: 4 }]),
108+
);
109+
const loopbackChannel: any = {
110+
type: 'webhook',
111+
channel: { ...webhook, url: 'http://127-0-0-1.nip.io/' },
112+
};
108113

109114
await expect(
110-
handleSendGenericWebhook(
111-
{
112-
type: 'webhook',
113-
channel: { ...webhook, url: 'http://127-0-0-1.nip.io/' },
114-
} as any,
115-
message,
116-
),
115+
handleSendGenericWebhook(loopbackChannel, message),
117116
).rejects.toThrow(WebhookUrlValidationError);
118117
expect(lookupSpy).toHaveBeenCalledTimes(1);
119118
}, 2000);

‎packages/api/src/utils/__tests__/validators.test.ts‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ describe('validators', () => {
339339
),
340340
);
341341

342+
const mockLookup = (err: Error | null, addresses: dns.LookupAddress[]) =>
343+
jest
344+
.spyOn(dns, 'lookup')
345+
.mockImplementation((...args: any[]) => args[2](err, addresses));
346+
342347
afterEach(() => jest.restoreAllMocks());
343348

344349
it('blocks a hostname that resolves to a private address', async () => {
@@ -348,10 +353,7 @@ describe('validators', () => {
348353
});
349354

350355
it('returns public addresses in the shape the caller asked for', async () => {
351-
jest
352-
.spyOn(dns, 'lookup')
353-
.mockImplementation(((_h: string, _o: unknown, cb: any) =>
354-
cb(null, [{ address: '93.184.216.34', family: 4 }])) as any);
356+
mockLookup(null, [{ address: '93.184.216.34', family: 4 }]);
355357

356358
await expect(lookup(validators, 'example.com')).resolves.toBe(
357359
'93.184.216.34',
@@ -361,12 +363,6 @@ describe('validators', () => {
361363
]);
362364
});
363365

364-
const mockLookup = (err: Error | null, addresses: dns.LookupAddress[]) =>
365-
jest
366-
.spyOn(dns, 'lookup')
367-
.mockImplementation(((_h: string, _o: unknown, cb: any) =>
368-
cb(err, addresses)) as any);
369-
370366
it.each([
371367
[
372368
'one private record among public ones',

0 commit comments

Comments
 (0)