From 054433d09aace16e913ffa1e4905c5a1594c041d Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 1 Aug 2023 17:34:52 -0400 Subject: [PATCH] Fixes failing tests: block_actions.user.name is optional, as it can still be present, e.g. in Home tab actions. Fix related test, too. Bumping eslint-plugin-import dependency, fixing up lint errors. --- .github/workflows/ci-build.yml | 2 ++ package.json | 2 +- src/receivers/AwsLambdaReceiver.spec.ts | 2 +- src/receivers/AwsLambdaReceiver.ts | 2 +- src/receivers/ExpressReceiver.spec.ts | 4 ++-- src/receivers/ExpressReceiver.ts | 4 ++-- src/receivers/HTTPModuleFunctions.spec.ts | 4 ++-- src/receivers/HTTPModuleFunctions.ts | 2 +- src/receivers/HTTPReceiver.spec.ts | 4 ++-- src/receivers/HTTPReceiver.ts | 2 +- src/receivers/HTTPResponseAck.spec.ts | 2 +- src/receivers/HTTPResponseAck.ts | 2 +- src/receivers/SocketModeReceiver.spec.ts | 4 ++-- src/receivers/SocketModeReceiver.ts | 2 +- src/receivers/http-utils.ts | 2 +- src/receivers/verify-request.spec.ts | 2 +- src/receivers/verify-request.ts | 4 ++-- src/types/actions/block-action.spec.ts | 2 +- src/types/actions/block-action.ts | 7 +++++-- 19 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 69d1cdf80..b1822ed30 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -25,6 +25,8 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm install + - name: Print eslint version + run: ./node_modules/.bin/eslint -v - run: npm run build - run: npm test - run: npm run coverage diff --git a/package.json b/package.json index 4661e671c..64e852304 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "eslint": "^7.26.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-typescript": "^12.3.1", - "eslint-plugin-import": "^2.22.1", + "eslint-plugin-import": "^2.28.0", "eslint-plugin-jsdoc": "^30.6.1", "eslint-plugin-jsx-a11y": "^6.5.1", "eslint-plugin-node": "^11.1.0", diff --git a/src/receivers/AwsLambdaReceiver.spec.ts b/src/receivers/AwsLambdaReceiver.spec.ts index 135afc0ce..813b32758 100644 --- a/src/receivers/AwsLambdaReceiver.spec.ts +++ b/src/receivers/AwsLambdaReceiver.spec.ts @@ -1,8 +1,8 @@ +import crypto from 'crypto'; import sinon from 'sinon'; import { Logger, LogLevel } from '@slack/logger'; import { assert } from 'chai'; import 'mocha'; -import crypto from 'crypto'; import rewiremock from 'rewiremock'; import { WebClientOptions } from '@slack/web-api'; import AwsLambdaReceiver, { AwsHandler } from './AwsLambdaReceiver'; diff --git a/src/receivers/AwsLambdaReceiver.ts b/src/receivers/AwsLambdaReceiver.ts index 87339f746..717201a34 100644 --- a/src/receivers/AwsLambdaReceiver.ts +++ b/src/receivers/AwsLambdaReceiver.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Logger, ConsoleLogger, LogLevel } from '@slack/logger'; import querystring from 'querystring'; import crypto from 'crypto'; +import { Logger, ConsoleLogger, LogLevel } from '@slack/logger'; import tsscmp from 'tsscmp'; import App from '../App'; import { Receiver, ReceiverEvent } from '../types/receiver'; diff --git a/src/receivers/ExpressReceiver.spec.ts b/src/receivers/ExpressReceiver.spec.ts index 78bdb6b4f..8497be08f 100644 --- a/src/receivers/ExpressReceiver.spec.ts +++ b/src/receivers/ExpressReceiver.spec.ts @@ -1,11 +1,11 @@ import 'mocha'; +import { Readable } from 'stream'; +import { EventEmitter } from 'events'; import sinon, { SinonFakeTimers, SinonSpy } from 'sinon'; import { assert } from 'chai'; import rewiremock from 'rewiremock'; import { Logger, LogLevel } from '@slack/logger'; import { Application, IRouter, Request, Response } from 'express'; -import { Readable } from 'stream'; -import { EventEmitter } from 'events'; import { Override, mergeOverrides, createFakeLogger } from '../test-helpers'; import { ErrorCode, CodedError, ReceiverInconsistentStateError, AppInitializationError, AuthorizationError } from '../errors'; import { HTTPModuleFunctions as httpFunc } from './HTTPModuleFunctions'; diff --git a/src/receivers/ExpressReceiver.ts b/src/receivers/ExpressReceiver.ts index a87ce24e3..56865fe62 100644 --- a/src/receivers/ExpressReceiver.ts +++ b/src/receivers/ExpressReceiver.ts @@ -4,10 +4,10 @@ import { createServer, Server, ServerOptions } from 'http'; import type { IncomingMessage, ServerResponse } from 'http'; import { createServer as createHttpsServer, Server as HTTPSServer, ServerOptions as HTTPSServerOptions } from 'https'; import { ListenOptions } from 'net'; -import express, { Request, Response, Application, RequestHandler, Router, IRouter } from 'express'; -import rawBody from 'raw-body'; import querystring from 'querystring'; import crypto from 'crypto'; +import express, { Request, Response, Application, RequestHandler, Router, IRouter } from 'express'; +import rawBody from 'raw-body'; import tsscmp from 'tsscmp'; import { Logger, ConsoleLogger, LogLevel } from '@slack/logger'; import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOptions, InstallPathOptions } from '@slack/oauth'; diff --git a/src/receivers/HTTPModuleFunctions.spec.ts b/src/receivers/HTTPModuleFunctions.spec.ts index c0c353d2d..0b52bab46 100644 --- a/src/receivers/HTTPModuleFunctions.spec.ts +++ b/src/receivers/HTTPModuleFunctions.spec.ts @@ -1,8 +1,8 @@ import 'mocha'; -import sinon from 'sinon'; -import { assert } from 'chai'; import { IncomingMessage, ServerResponse } from 'http'; import { createHmac } from 'crypto'; +import sinon from 'sinon'; +import { assert } from 'chai'; import { ReceiverMultipleAckError, diff --git a/src/receivers/HTTPModuleFunctions.ts b/src/receivers/HTTPModuleFunctions.ts index 6191e1a6e..1ea84a2e5 100644 --- a/src/receivers/HTTPModuleFunctions.ts +++ b/src/receivers/HTTPModuleFunctions.ts @@ -1,8 +1,8 @@ /* eslint-disable import/prefer-default-export */ import { parse as qsParse } from 'querystring'; +import type { IncomingMessage, ServerResponse } from 'http'; import rawBody from 'raw-body'; import type { Logger } from '@slack/logger'; -import type { IncomingMessage, ServerResponse } from 'http'; import { CodedError, ErrorCode } from '../errors'; import { BufferedIncomingMessage } from './BufferedIncomingMessage'; import { verifySlackRequest } from './verify-request'; diff --git a/src/receivers/HTTPReceiver.spec.ts b/src/receivers/HTTPReceiver.spec.ts index 3babd615a..6fc766435 100644 --- a/src/receivers/HTTPReceiver.spec.ts +++ b/src/receivers/HTTPReceiver.spec.ts @@ -1,11 +1,11 @@ import 'mocha'; +import { EventEmitter } from 'events'; +import { IncomingMessage, ServerResponse } from 'http'; import sinon, { SinonSpy } from 'sinon'; import { assert } from 'chai'; import rewiremock from 'rewiremock'; import { Logger, LogLevel } from '@slack/logger'; -import { EventEmitter } from 'events'; import { InstallProvider } from '@slack/oauth'; -import { IncomingMessage, ServerResponse } from 'http'; import { match } from 'path-to-regexp'; import { ParamsDictionary } from 'express-serve-static-core'; import { Override, mergeOverrides } from '../test-helpers'; diff --git a/src/receivers/HTTPReceiver.ts b/src/receivers/HTTPReceiver.ts index 0424540e5..c569bd87c 100644 --- a/src/receivers/HTTPReceiver.ts +++ b/src/receivers/HTTPReceiver.ts @@ -2,9 +2,9 @@ import { createServer, Server, ServerOptions, RequestListener, IncomingMessage, ServerResponse } from 'http'; import { createServer as createHttpsServer, Server as HTTPSServer, ServerOptions as HTTPSServerOptions } from 'https'; import { ListenOptions } from 'net'; +import { URL } from 'url'; import { Logger, ConsoleLogger, LogLevel } from '@slack/logger'; import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOptions, InstallPathOptions } from '@slack/oauth'; -import { URL } from 'url'; import { match } from 'path-to-regexp'; import { ParamsDictionary } from 'express-serve-static-core'; import { ParamsIncomingMessage } from './ParamsIncomingMessage'; diff --git a/src/receivers/HTTPResponseAck.spec.ts b/src/receivers/HTTPResponseAck.spec.ts index c58389a3c..b3e7e06b1 100644 --- a/src/receivers/HTTPResponseAck.spec.ts +++ b/src/receivers/HTTPResponseAck.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; +import { IncomingMessage, ServerResponse } from 'http'; import sinon from 'sinon'; import { assert } from 'chai'; -import { IncomingMessage, ServerResponse } from 'http'; import { HTTPResponseAck } from './HTTPResponseAck'; import { HTTPModuleFunctions } from './HTTPModuleFunctions'; import { ReceiverMultipleAckError } from '../errors'; diff --git a/src/receivers/HTTPResponseAck.ts b/src/receivers/HTTPResponseAck.ts index 24eb69785..afb8b5aca 100644 --- a/src/receivers/HTTPResponseAck.ts +++ b/src/receivers/HTTPResponseAck.ts @@ -1,5 +1,5 @@ -import { Logger } from '@slack/logger'; import { IncomingMessage, ServerResponse } from 'http'; +import { Logger } from '@slack/logger'; import { AckFn } from '../types'; import { ReceiverMultipleAckError } from '../errors'; import { HTTPModuleFunctions as httpFunc, ReceiverUnhandledRequestHandlerArgs } from './HTTPModuleFunctions'; diff --git a/src/receivers/SocketModeReceiver.spec.ts b/src/receivers/SocketModeReceiver.spec.ts index 4633ecc4b..8b02d9a72 100644 --- a/src/receivers/SocketModeReceiver.spec.ts +++ b/src/receivers/SocketModeReceiver.spec.ts @@ -1,10 +1,10 @@ import 'mocha'; +import { EventEmitter } from 'events'; +import { IncomingMessage, ServerResponse } from 'http'; import sinon, { SinonSpy } from 'sinon'; import { assert } from 'chai'; import rewiremock from 'rewiremock'; import { Logger, LogLevel } from '@slack/logger'; -import { EventEmitter } from 'events'; -import { IncomingMessage, ServerResponse } from 'http'; import { match } from 'path-to-regexp'; import { ParamsDictionary } from 'express-serve-static-core'; import { InstallProvider } from '@slack/oauth'; diff --git a/src/receivers/SocketModeReceiver.ts b/src/receivers/SocketModeReceiver.ts index 0cb2e7cd6..c8fa1bf7a 100644 --- a/src/receivers/SocketModeReceiver.ts +++ b/src/receivers/SocketModeReceiver.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { URL } from 'url'; -import { SocketModeClient } from '@slack/socket-mode'; import { createServer, ServerResponse, Server } from 'http'; +import { SocketModeClient } from '@slack/socket-mode'; import { Logger, ConsoleLogger, LogLevel } from '@slack/logger'; import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOptions, InstallPathOptions } from '@slack/oauth'; import { AppsConnectionsOpenResponse } from '@slack/web-api'; diff --git a/src/receivers/http-utils.ts b/src/receivers/http-utils.ts index 865a2e9f5..240a78b5c 100644 --- a/src/receivers/http-utils.ts +++ b/src/receivers/http-utils.ts @@ -1,5 +1,5 @@ -import { ConsoleLogger } from '@slack/logger'; import { IncomingMessage } from 'http'; +import { ConsoleLogger } from '@slack/logger'; import { HTTPModuleFunctions } from './HTTPModuleFunctions'; const logger = new ConsoleLogger(); diff --git a/src/receivers/verify-request.spec.ts b/src/receivers/verify-request.spec.ts index c672c4dde..783359e8e 100644 --- a/src/receivers/verify-request.spec.ts +++ b/src/receivers/verify-request.spec.ts @@ -1,6 +1,6 @@ import 'mocha'; -import { assert } from 'chai'; import { createHmac } from 'crypto'; +import { assert } from 'chai'; import { isValidSlackRequest, verifySlackRequest } from './verify-request'; describe('Request verification', async () => { diff --git a/src/receivers/verify-request.ts b/src/receivers/verify-request.ts index 29277765a..5b28bfa81 100644 --- a/src/receivers/verify-request.ts +++ b/src/receivers/verify-request.ts @@ -1,8 +1,8 @@ // Deprecated: this function will be removed in the near future. Use HTTPModuleFunctions instead. -import { ConsoleLogger, Logger } from '@slack/logger'; import { createHmac } from 'crypto'; -import tsscmp from 'tsscmp'; import type { IncomingMessage, ServerResponse } from 'http'; +import { ConsoleLogger, Logger } from '@slack/logger'; +import tsscmp from 'tsscmp'; import { BufferedIncomingMessage } from './BufferedIncomingMessage'; import { HTTPModuleFunctions, RequestVerificationOptions } from './HTTPModuleFunctions'; diff --git a/src/types/actions/block-action.spec.ts b/src/types/actions/block-action.spec.ts index 4bbe210e2..9b05efbdc 100644 --- a/src/types/actions/block-action.spec.ts +++ b/src/types/actions/block-action.spec.ts @@ -14,7 +14,7 @@ describe('Interactivity payload types', () => { type: 'block_actions', user: { id: 'W111', - name: 'seratch', + username: 'seratch', team_id: 'T111', }, api_app_id: 'A02', diff --git a/src/types/actions/block-action.ts b/src/types/actions/block-action.ts index 86580c055..fc12aeca4 100644 --- a/src/types/actions/block-action.ts +++ b/src/types/actions/block-action.ts @@ -218,9 +218,12 @@ export interface BlockAction