Skip to content

Commit 47a2043

Browse files
authored
Remove node-fetch dependency (#212)
1 parent 65bc094 commit 47a2043

File tree

11 files changed

+10
-24
lines changed

11 files changed

+10
-24
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"graphql": "^16.6.0",
5353
"js-yaml": "^4.1.0",
5454
"nestjs-pino": "^3.1.1",
55-
"node-fetch": "2",
5655
"pino": "^8.4.2",
5756
"pino-http": "^7.0.0",
5857
"pino-pretty": "^9.1.0",

services/bots/src/cla-sign/cla-sign.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Injectable } from '@nestjs/common';
44
import { ConfigService } from '@nestjs/config';
55
import { createAppAuth } from '@octokit/auth-app';
66
import { DynamoDB } from 'aws-sdk';
7-
import fetch from 'node-fetch';
87
import { GithubClient } from '../github-webhook/github-webhook.model';
98

109
export class ServiceRequestError extends ServiceError {}

services/bots/src/discord/commands/home-assistant/versions.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import fetch from 'node-fetch';
2-
3-
import { getVersionInfo } from '@lib/common';
41
import { EmbedBuilder } from 'discord.js';
52
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';
63
import {

services/bots/src/discord/services/common/message-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import yaml from 'js-yaml';
32

43
import { Injectable } from '@nestjs/common';

services/bots/src/discord/services/esphome/component-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { Injectable } from '@nestjs/common';
32

43
export interface ComponentData {

services/bots/src/discord/services/home-assistant/integration-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { Injectable } from '@nestjs/common';
32

43
export interface IntegrationData {

services/bots/src/discord/services/home-assistant/my-redirect-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { Injectable } from '@nestjs/common';
32

43
interface Redirect {

services/bots/src/github-webhook/handlers/month_of_wth.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fetch from 'node-fetch';
2-
31
import { PullRequest, PullRequestOpenedEvent } from '@octokit/webhooks-types';
42
import { EventType, Organization } from '../github-webhook.const';
53
import { WebhookContext } from '../github-webhook.model';

services/bots/src/github-webhook/utils/integration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fetch from 'node-fetch';
2-
31
export enum QualityScale {
42
NO_SCORE = 'no score',
53
SILVER = 'silver',

tests/services/bots/github-webhook/handlers/issue_comment_commands.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import fetch from 'node-fetch';
2-
31
import { WebhookContext } from '../../../../../services/bots/src/github-webhook/github-webhook.model';
42
import { mockWebhookContext } from '../../../../utils/test_context';
53
import { loadJsonFixture } from '../../../../utils/fixture';
64
import { IssueCommentCommands } from '../../../../../services/bots/src/github-webhook/handlers/issue_comment_commands/handler';
75
import { IssueCommentCreatedEvent } from '@octokit/webhooks-types';
86
import { EventType } from '../../../../../services/bots/src/github-webhook/github-webhook.const';
97

10-
// Globally mock fetch
11-
jest.mock('node-fetch', () => jest.fn());
12-
fetch.mockImplementation(() =>
13-
Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }),
14-
);
15-
168
describe('IssueCommentCommands', () => {
179
let handler: IssueCommentCommands;
1810
let mockContext: WebhookContext<IssueCommentCreatedEvent>;
11+
let mockedFetch: ReturnType<typeof jest.fn>;
1912

2013
beforeEach(function () {
14+
mockedFetch = jest.fn(global.fetch);
15+
mockedFetch.mockImplementation(() =>
16+
Promise.resolve({
17+
json: () => Promise.resolve({ codeowners: ['@test'] }),
18+
} as unknown as Response),
19+
);
20+
(global.fetch as unknown) = mockedFetch;
2121
handler = new IssueCommentCommands();
2222
mockContext = mockWebhookContext<IssueCommentCreatedEvent>({
2323
eventType: EventType.ISSUE_COMMENT_CREATED,
@@ -54,7 +54,7 @@ describe('IssueCommentCommands', () => {
5454
);
5555
});
5656
it('not by codeowner', async () => {
57-
fetch.mockImplementation(() =>
57+
mockedFetch.mockImplementation(() =>
5858
Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }),
5959
);
6060
mockContext.payload.comment.user.login = 'other';

0 commit comments

Comments
 (0)