From 4e6d75567493abf8ef3f53e20c9f5c01a0b43c2f Mon Sep 17 00:00:00 2001 From: ludeeus Date: Mon, 9 Oct 2023 13:55:33 +0000 Subject: [PATCH] Remove node-fetch dependency --- package.json | 1 - services/bots/src/cla-sign/cla-sign.service.ts | 1 - .../commands/home-assistant/versions.ts | 3 --- .../discord/services/common/message-data.ts | 1 - .../discord/services/esphome/component-data.ts | 1 - .../home-assistant/integration-data.ts | 1 - .../home-assistant/my-redirect-data.ts | 1 - .../github-webhook/handlers/month_of_wth.ts | 2 -- .../src/github-webhook/utils/integration.ts | 2 -- .../handlers/issue_comment_commands.spec.ts | 18 +++++++++--------- yarn.lock | 3 +-- 11 files changed, 10 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 2e4a947..4bd6bec 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "graphql": "^16.6.0", "js-yaml": "^4.1.0", "nestjs-pino": "^3.1.1", - "node-fetch": "2", "pino": "^8.4.2", "pino-http": "^7.0.0", "pino-pretty": "^9.1.0", diff --git a/services/bots/src/cla-sign/cla-sign.service.ts b/services/bots/src/cla-sign/cla-sign.service.ts index 7f3ac4d..25f8aaa 100644 --- a/services/bots/src/cla-sign/cla-sign.service.ts +++ b/services/bots/src/cla-sign/cla-sign.service.ts @@ -4,7 +4,6 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { createAppAuth } from '@octokit/auth-app'; import { DynamoDB } from 'aws-sdk'; -import fetch from 'node-fetch'; import { GithubClient } from '../github-webhook/github-webhook.model'; export class ServiceRequestError extends ServiceError {} diff --git a/services/bots/src/discord/commands/home-assistant/versions.ts b/services/bots/src/discord/commands/home-assistant/versions.ts index fe59cbd..15e4b3c 100644 --- a/services/bots/src/discord/commands/home-assistant/versions.ts +++ b/services/bots/src/discord/commands/home-assistant/versions.ts @@ -1,6 +1,3 @@ -import fetch from 'node-fetch'; - -import { getVersionInfo } from '@lib/common'; import { EmbedBuilder } from 'discord.js'; import { CommandHandler, DiscordCommandClass } from '../../discord.decorator'; import { diff --git a/services/bots/src/discord/services/common/message-data.ts b/services/bots/src/discord/services/common/message-data.ts index 211dd2b..f44d5c4 100644 --- a/services/bots/src/discord/services/common/message-data.ts +++ b/services/bots/src/discord/services/common/message-data.ts @@ -1,4 +1,3 @@ -import fetch from 'node-fetch'; import yaml from 'js-yaml'; import { Injectable } from '@nestjs/common'; diff --git a/services/bots/src/discord/services/esphome/component-data.ts b/services/bots/src/discord/services/esphome/component-data.ts index 72d55e8..392c1cd 100644 --- a/services/bots/src/discord/services/esphome/component-data.ts +++ b/services/bots/src/discord/services/esphome/component-data.ts @@ -1,4 +1,3 @@ -import fetch from 'node-fetch'; import { Injectable } from '@nestjs/common'; export interface ComponentData { diff --git a/services/bots/src/discord/services/home-assistant/integration-data.ts b/services/bots/src/discord/services/home-assistant/integration-data.ts index f952d9a..6e049bf 100644 --- a/services/bots/src/discord/services/home-assistant/integration-data.ts +++ b/services/bots/src/discord/services/home-assistant/integration-data.ts @@ -1,4 +1,3 @@ -import fetch from 'node-fetch'; import { Injectable } from '@nestjs/common'; export interface IntegrationData { diff --git a/services/bots/src/discord/services/home-assistant/my-redirect-data.ts b/services/bots/src/discord/services/home-assistant/my-redirect-data.ts index a145775..83da0b2 100644 --- a/services/bots/src/discord/services/home-assistant/my-redirect-data.ts +++ b/services/bots/src/discord/services/home-assistant/my-redirect-data.ts @@ -1,4 +1,3 @@ -import fetch from 'node-fetch'; import { Injectable } from '@nestjs/common'; interface Redirect { diff --git a/services/bots/src/github-webhook/handlers/month_of_wth.ts b/services/bots/src/github-webhook/handlers/month_of_wth.ts index 54ec1e8..b0944ce 100644 --- a/services/bots/src/github-webhook/handlers/month_of_wth.ts +++ b/services/bots/src/github-webhook/handlers/month_of_wth.ts @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - import { PullRequest, PullRequestOpenedEvent } from '@octokit/webhooks-types'; import { EventType, Organization } from '../github-webhook.const'; import { WebhookContext } from '../github-webhook.model'; diff --git a/services/bots/src/github-webhook/utils/integration.ts b/services/bots/src/github-webhook/utils/integration.ts index 2d51eea..437fe06 100644 --- a/services/bots/src/github-webhook/utils/integration.ts +++ b/services/bots/src/github-webhook/utils/integration.ts @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - export enum QualityScale { NO_SCORE = 'no score', SILVER = 'silver', diff --git a/tests/services/bots/github-webhook/handlers/issue_comment_commands.spec.ts b/tests/services/bots/github-webhook/handlers/issue_comment_commands.spec.ts index 3a9aed1..8889d2a 100644 --- a/tests/services/bots/github-webhook/handlers/issue_comment_commands.spec.ts +++ b/tests/services/bots/github-webhook/handlers/issue_comment_commands.spec.ts @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - import { WebhookContext } from '../../../../../services/bots/src/github-webhook/github-webhook.model'; import { mockWebhookContext } from '../../../../utils/test_context'; import { loadJsonFixture } from '../../../../utils/fixture'; @@ -7,17 +5,19 @@ import { IssueCommentCommands } from '../../../../../services/bots/src/github-we import { IssueCommentCreatedEvent } from '@octokit/webhooks-types'; import { EventType } from '../../../../../services/bots/src/github-webhook/github-webhook.const'; -// Globally mock fetch -jest.mock('node-fetch', () => jest.fn()); -fetch.mockImplementation(() => - Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }), -); - describe('IssueCommentCommands', () => { let handler: IssueCommentCommands; let mockContext: WebhookContext; + let mockedFetch: ReturnType; beforeEach(function () { + mockedFetch = jest.fn(global.fetch); + mockedFetch.mockImplementation(() => + Promise.resolve({ + json: () => Promise.resolve({ codeowners: ['@test'] }), + } as unknown as Response), + ); + (global.fetch as unknown) = mockedFetch; handler = new IssueCommentCommands(); mockContext = mockWebhookContext({ eventType: EventType.ISSUE_COMMENT_CREATED, @@ -54,7 +54,7 @@ describe('IssueCommentCommands', () => { ); }); it('not by codeowner', async () => { - fetch.mockImplementation(() => + mockedFetch.mockImplementation(() => Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }), ); mockContext.payload.comment.user.login = 'other'; diff --git a/yarn.lock b/yarn.lock index f578d7a..ed0eb95 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7093,7 +7093,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:2, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": +"node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": version: 2.6.7 resolution: "node-fetch@npm:2.6.7" dependencies: @@ -8223,7 +8223,6 @@ __metadata: jest: ^29.2.1 js-yaml: ^4.1.0 nestjs-pino: ^3.1.1 - node-fetch: 2 pino: ^8.4.2 pino-http: ^7.0.0 pino-pretty: ^9.1.0