Skip to content

Commit

Permalink
test(all): cleaning tests and fixing ts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Feb 29, 2024
1 parent 79f3383 commit c3dcfff
Show file tree
Hide file tree
Showing 40 changed files with 136 additions and 107 deletions.
6 changes: 3 additions & 3 deletions test/adapters/aws/alb.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ALBEvent, ALBResult } from 'aws-lambda';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
getMultiValueHeadersMap,
Expand Down
6 changes: 3 additions & 3 deletions test/adapters/aws/api-gateway-v1.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { APIGatewayProxyResult } from 'aws-lambda';
import type { APIGatewayProxyEvent } from 'aws-lambda/trigger/api-gateway-proxy';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
ServerlessResponse,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
Expand Down
6 changes: 3 additions & 3 deletions test/adapters/aws/api-gateway-v2.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { APIGatewayProxyEventV2 } from 'aws-lambda';
import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
ServerlessResponse,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/aws/aws-simple-adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
type DelegatedResolver,
EmptyResponse,
ILogger,
type ILogger,
createDefaultLogger,
getEventBodyAsBuffer,
} from '../../../src';
Expand Down
10 changes: 5 additions & 5 deletions test/adapters/aws/lambda-edge.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type {
} from 'aws-lambda/trigger/cloudfront-request';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
BothValueHeaders,
DelegatedResolver,
ILogger,
MultiValueHeaders,
SingleValueHeaders,
type BothValueHeaders,
type DelegatedResolver,
type ILogger,
type MultiValueHeaders,
type SingleValueHeaders,
} from '../../../src';
import {
DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,
Expand Down
10 changes: 5 additions & 5 deletions test/adapters/aws/request-lambda-edge.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type {
} from 'aws-lambda/trigger/cloudfront-request';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
BothValueHeaders,
DelegatedResolver,
ILogger,
MultiValueHeaders,
SingleValueHeaders,
type BothValueHeaders,
type DelegatedResolver,
type ILogger,
type MultiValueHeaders,
type SingleValueHeaders,
} from '../../../src';
import {
DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS,
Expand Down
8 changes: 4 additions & 4 deletions test/adapters/azure/http-trigger.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Cookie, HttpRequest, HttpResponseSimple } from '@azure/functions';
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
getPathWithQueryStringParams,
Expand Down Expand Up @@ -303,7 +303,7 @@ describe(HttpTriggerV4Adapter.name, () => {

const log = {} as ILogger;

const resolver: DelegatedResolver<HttpRequest> = {
const resolver: DelegatedResolver<HttpResponseSimple> = {
fail: vitest.fn(),
succeed: vitest.fn(),
};
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/azure/utils/http-trigger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { URL } from 'url';
import type { Context, Form, HttpRequest } from '@azure/functions';
import { vitest } from 'vitest';
import { BothValueHeaders } from '../../../../src';
import { type BothValueHeaders } from '../../../../src';

export function createHttpTriggerEvent(
method: HttpRequest['method'],
Expand Down
12 changes: 7 additions & 5 deletions test/adapters/digital-ocean/http-function.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
getEventBodyAsBuffer,
getPathWithQueryStringParams,
} from '../../../src';
import { DigitalOceanHttpEvent } from '../../../src/@types/digital-ocean';
import { DigitalOceanHttpResponse } from '../../../src/@types/digital-ocean/digital-ocean-http-response';
import {
type DigitalOceanHttpEvent,
type DigitalOceanHttpResponse,
} from '../../../src/@types/digital-ocean';
import { HttpFunctionAdapter } from '../../../src/adapters/digital-ocean';
import { createCanHandleTestsForAdapter } from '../utils/can-handle';
import { createHttpFunctionEvent } from './utils/http-function';
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/digital-ocean/utils/http-function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DigitalOceanHttpEvent } from '../../../../src/@types/digital-ocean';
import { type DigitalOceanHttpEvent } from '../../../../src/@types/digital-ocean';

export function createHttpFunctionEvent(
method: string,
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/dummy/dummy.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
type DelegatedResolver,
EmptyResponse,
createDefaultLogger,
} from '../../../src';
Expand Down
8 changes: 4 additions & 4 deletions test/adapters/huawei/huawei-api-gateway.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import {
DelegatedResolver,
GetResponseAdapterProps,
ILogger,
type DelegatedResolver,
type GetResponseAdapterProps,
type ILogger,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
getPathWithQueryStringParams,
} from '../../../src';
import {
import type {
HuaweiApiGatewayEvent,
HuaweiApiGatewayResponse,
} from '../../../src/@types/huawei';
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/huawei/utils/huawei-api-gateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BothValueHeaders } from '../../../../src';
import {
import type { BothValueHeaders } from '../../../../src';
import type {
HuaweiApiGatewayEvent,
HuaweiRequestQueryStringParameters,
} from '../../../../src/@types/huawei';
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/utils/can-handle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { AdapterContract, ILogger } from '../../../src';
import type { AdapterContract, ILogger } from '../../../src';
import { allEvents } from './events';

export function createCanHandleTestsForAdapter<
Expand Down
36 changes: 22 additions & 14 deletions test/core/base-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { describe, expect, it, vitest } from 'vitest';
import {
AdapterContract,
AdapterRequest,
type AdapterContract,
type AdapterRequest,
BaseHandler,
ILogger,
type ILogger,
ServerlessRequest,
ServerlessResponse,
createDefaultLogger,
} from '../../src';
import { AlbAdapter, SQSAdapter } from '../../src/adapters/aws';
import { createSQSEvent } from '../adapters/aws/utils/sqs';

class TestHandler<
class TestHandler<TApp, TContext, TCallback, TReturn> extends BaseHandler<
TApp,
TEvent,
unknown,
TContext,
TCallback,
TResponse,
TReturn,
> extends BaseHandler<TApp, TEvent, TContext, TCallback, TResponse, TReturn> {
unknown,
TReturn
> {
getHandler = vitest.fn();

/**
* {@inheritDoc}
*/
public getAdapterByEventAndContext(
public override getAdapterByEventAndContext(
event: any,
context: any,
adapters: AdapterContract<TEvent, TContext, TResponse>[],
adapters: AdapterContract<unknown, TContext, unknown>[],
log: ILogger,
): AdapterContract<TEvent, TContext, TResponse> {
): AdapterContract<unknown, TContext, unknown> {
return super.getAdapterByEventAndContext(event, context, adapters, log);
}

/**
* {@inheritDoc}
*/
public getServerlessRequestResponseFromAdapterRequest(
public override getServerlessRequestResponseFromAdapterRequest(
requestValues: AdapterRequest,
): [request: ServerlessRequest, response: ServerlessResponse] {
return super.getServerlessRequestResponseFromAdapterRequest(requestValues);
Expand All @@ -48,7 +48,11 @@ describe(BaseHandler.name, () => {
const handler = new TestHandler();
const testEvent = createSQSEvent();
const eventAdapter = new SQSAdapter();
const adapters = [eventAdapter, new AlbAdapter()];
const adapters = [eventAdapter, new AlbAdapter()] as AdapterContract<
any,
any,
any
>[];
const context = {};
const logger = createDefaultLogger();

Expand Down Expand Up @@ -89,7 +93,11 @@ describe(BaseHandler.name, () => {
it('should throw error when resolve more than one adapter', () => {
const handler = new TestHandler();
const testEvent = createSQSEvent();
const adapters = [new SQSAdapter(), new SQSAdapter()];
const adapters = [new SQSAdapter(), new SQSAdapter()] as AdapterContract<
any,
any,
any
>[];
const adapterNames = adapters
.map(adapter => adapter.getAdapterName())
.join(', ');
Expand Down
2 changes: 1 addition & 1 deletion test/core/headers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
BothValueHeaders,
type BothValueHeaders,
getFlattenedHeadersMap,
getFlattenedHeadersMapAndCookies,
getMultiValueHeadersMap,
Expand Down
2 changes: 1 addition & 1 deletion test/core/is-binary.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
BothValueHeaders,
type BothValueHeaders,
DEFAULT_BINARY_CONTENT_TYPES,
DEFAULT_BINARY_ENCODINGS,
getContentType,
Expand Down
6 changes: 3 additions & 3 deletions test/core/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/unbound-method */

import {
SpyInstance,
type MockInstance,
afterEach,
beforeEach,
describe,
Expand All @@ -10,14 +10,14 @@ import {
vitest,
} from 'vitest';
import {
LogLevels,
type LogLevels,
NO_OP,
createDefaultLogger,
isInternalLogger,
} from '../../src';

describe('createDefaultLogger', () => {
const mocks: SpyInstance[] = [];
const mocks: MockInstance[] = [];

beforeEach(() => {
const mockMethods: (keyof Console)[] = [
Expand Down
6 changes: 3 additions & 3 deletions test/core/utils/stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// credits to: https://github.com/b4nst/stream-mock/pull/64/files#diff-52aee274967f2fcfa3ffa78ebba2f510dd23d176aa92ccf8c0ad4843373f5ce7

import { Readable, ReadableOptions } from 'node:stream';
import { IReadableMock } from 'stream-mock';
import { Readable, type ReadableOptions } from 'node:stream';
import type { IReadableMock } from 'stream-mock';

/**
* ErrorReadableMock is a readable stream that mocks error.
Expand Down Expand Up @@ -34,7 +34,7 @@ export default class ErrorReadableMock
private expectedError: Error;

// tslint:disable-next-line:function-name Not responsible of this function name
public _read() {
public override _read() {
this.destroy(this.expectedError);
}
}
6 changes: 3 additions & 3 deletions test/frameworks/apollo-server.framework.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
waitForStreamComplete,
} from '../../src';
import {
ApolloServerContextArguments,
type ApolloServerContextArguments,
ApolloServerFramework,
DefaultServerlessApolloServerContext,
type DefaultServerlessApolloServerContext,
} from '../../src/frameworks/apollo-server';
import { JsonBodyParserFramework } from '../../src/frameworks/body-parser';
import { TestRouteBuilderMethods } from './utils';
import { type TestRouteBuilderMethods } from './utils';

export const frameworkTestOptions: [
method: TestRouteBuilderMethods,
Expand Down
4 changes: 2 additions & 2 deletions test/frameworks/express.framework.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Express } from 'express';
import express, { type Express } from 'express';
import { describe } from 'vitest';
import { ExpressFramework } from '../../src/frameworks/express';
import { TestRouteBuilderHandler, createTestSuiteFor } from './utils';
import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils';

function createHandler(
method: 'get' | 'post' | 'delete' | 'put',
Expand Down
4 changes: 2 additions & 2 deletions test/frameworks/fastify.framework.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastify, { FastifyInstance } from 'fastify';
import fastify, { type FastifyInstance } from 'fastify';
import { describe } from 'vitest';
import { FastifyFramework } from '../../src/frameworks/fastify';
import { TestRouteBuilderHandler, createTestSuiteFor } from './utils';
import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils';

function createHandler(
method: 'get' | 'post' | 'delete' | 'put',
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/hapi.framework.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Server } from '@hapi/hapi';
import { describe } from 'vitest';
import { HapiFramework } from '../../src/frameworks/hapi';
import { TestRouteBuilderHandler, createTestSuiteFor } from './utils';
import { type TestRouteBuilderHandler, createTestSuiteFor } from './utils';

function createHandler(
method: 'GET' | 'POST' | 'DELETE' | 'PUT',
Expand Down
4 changes: 2 additions & 2 deletions test/frameworks/http-deepkit.framework.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App } from '@deepkit/app';
import {
HttpBody,
type HttpBody,
HttpKernel,
HttpModule,
HttpRequest,
Expand All @@ -14,7 +14,7 @@ import {
waitForStreamComplete,
} from '../../src';
import { HttpDeepkitFramework } from '../../src/frameworks/deepkit';
import { TestRouteBuilderHandler } from './utils';
import { type TestRouteBuilderHandler } from './utils';

export function createDeepkitHandler(
method: 'get' | 'post' | 'delete' | 'put',
Expand Down
Loading

0 comments on commit c3dcfff

Please sign in to comment.