Skip to content

Commit

Permalink
Merge pull request #442 from inversify/chore/add-decorator-tests
Browse files Browse the repository at this point in the history
Add http decorator tests
  • Loading branch information
notaphplover authored Feb 25, 2025
2 parents 8f3dbc7 + 1970de9 commit f004ab9
Show file tree
Hide file tree
Showing 20 changed files with 978 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/All.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestMethod');

import { RequestMethodType } from '../models/RequestMethodType';
import { ALL } from './All';
import { requestMethod } from './RequestMethod';

describe(ALL.name, () => {
describe('when called', () => {
let pathFixture: string | undefined;
let methodDecoratorFixture: MethodDecorator;
let result: unknown;

beforeAll(() => {
pathFixture = undefined;
methodDecoratorFixture = {} as MethodDecorator;

(requestMethod as jest.Mocked<typeof requestMethod>).mockReturnValueOnce(
methodDecoratorFixture,
);

result = ALL(pathFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestMethod', () => {
expect(requestMethod).toHaveBeenCalledTimes(1);
expect(requestMethod).toHaveBeenCalledWith(
RequestMethodType.ALL,
pathFixture,
);
});

it('should return a MethodDecorator', () => {
expect(result).toBe(methodDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Body.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestParam');

import { RequestMethodParameterType } from '../models/RequestMethodParameterType';
import { body } from './Body';
import { requestParam } from './RequestParam';

describe(body.name, () => {
describe('when called', () => {
let parameterNameFixture: string | undefined;
let parameterDecoratorFixture: ParameterDecorator;
let result: unknown;

beforeAll(() => {
parameterNameFixture = undefined;
parameterDecoratorFixture = {} as ParameterDecorator;

(requestParam as jest.Mocked<typeof requestParam>).mockReturnValueOnce(
parameterDecoratorFixture,
);

result = body(parameterNameFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestParam', () => {
expect(requestParam).toHaveBeenCalledTimes(1);
expect(requestParam).toHaveBeenCalledWith(
RequestMethodParameterType.BODY,
parameterNameFixture,
);
});

it('should return a ParameterDecorator', () => {
expect(result).toBe(parameterDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Cookies.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestParam');

import { RequestMethodParameterType } from '../models/RequestMethodParameterType';
import { cookies } from './Cookies';
import { requestParam } from './RequestParam';

describe(cookies.name, () => {
describe('when called', () => {
let parameterNameFixture: string | undefined;
let parameterDecoratorFixture: ParameterDecorator;
let result: unknown;

beforeAll(() => {
parameterNameFixture = undefined;
parameterDecoratorFixture = {} as ParameterDecorator;

(requestParam as jest.Mocked<typeof requestParam>).mockReturnValueOnce(
parameterDecoratorFixture,
);

result = cookies(parameterNameFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestParam', () => {
expect(requestParam).toHaveBeenCalledTimes(1);
expect(requestParam).toHaveBeenCalledWith(
RequestMethodParameterType.COOKIES,
parameterNameFixture,
);
});

it('should return a ParameterDecorator', () => {
expect(result).toBe(parameterDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Delete.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestMethod');

import { RequestMethodType } from '../models/RequestMethodType';
import { DELETE } from './Delete';
import { requestMethod } from './RequestMethod';

describe(DELETE.name, () => {
describe('when called', () => {
let pathFixture: string | undefined;
let methodDecoratorFixture: MethodDecorator;
let result: unknown;

beforeAll(() => {
pathFixture = undefined;
methodDecoratorFixture = {} as MethodDecorator;

(requestMethod as jest.Mocked<typeof requestMethod>).mockReturnValueOnce(
methodDecoratorFixture,
);

result = DELETE(pathFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestMethod', () => {
expect(requestMethod).toHaveBeenCalledTimes(1);
expect(requestMethod).toHaveBeenCalledWith(
RequestMethodType.DELETE,
pathFixture,
);
});

it('should return a MethodDecorator', () => {
expect(result).toBe(methodDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Get.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestMethod');

import { RequestMethodType } from '../models/RequestMethodType';
import { GET } from './Get';
import { requestMethod } from './RequestMethod';

describe(GET.name, () => {
describe('when called', () => {
let pathFixture: string | undefined;
let methodDecoratorFixture: MethodDecorator;
let result: unknown;

beforeAll(() => {
pathFixture = undefined;
methodDecoratorFixture = {} as MethodDecorator;

(requestMethod as jest.Mocked<typeof requestMethod>).mockReturnValueOnce(
methodDecoratorFixture,
);

result = GET(pathFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestMethod', () => {
expect(requestMethod).toHaveBeenCalledTimes(1);
expect(requestMethod).toHaveBeenCalledWith(
RequestMethodType.GET,
pathFixture,
);
});

it('should return a MethodDecorator', () => {
expect(result).toBe(methodDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Head.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestMethod');

import { RequestMethodType } from '../models/RequestMethodType';
import { HEAD } from './Head';
import { requestMethod } from './RequestMethod';

describe(HEAD.name, () => {
describe('when called', () => {
let pathFixture: string | undefined;
let methodDecoratorFixture: MethodDecorator;
let result: unknown;

beforeAll(() => {
pathFixture = undefined;
methodDecoratorFixture = {} as MethodDecorator;

(requestMethod as jest.Mocked<typeof requestMethod>).mockReturnValueOnce(
methodDecoratorFixture,
);

result = HEAD(pathFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestMethod', () => {
expect(requestMethod).toHaveBeenCalledTimes(1);
expect(requestMethod).toHaveBeenCalledWith(
RequestMethodType.HEAD,
pathFixture,
);
});

it('should return a MethodDecorator', () => {
expect(result).toBe(methodDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Headers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestParam');

import { RequestMethodParameterType } from '../models/RequestMethodParameterType';
import { headers } from './Headers';
import { requestParam } from './RequestParam';

describe(headers.name, () => {
describe('when called', () => {
let parameterNameFixture: string | undefined;
let parameterDecoratorFixture: ParameterDecorator;
let result: unknown;

beforeAll(() => {
parameterNameFixture = undefined;
parameterDecoratorFixture = {} as ParameterDecorator;

(requestParam as jest.Mocked<typeof requestParam>).mockReturnValueOnce(
parameterDecoratorFixture,
);

result = headers(parameterNameFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestParam', () => {
expect(requestParam).toHaveBeenCalledTimes(1);
expect(requestParam).toHaveBeenCalledWith(
RequestMethodParameterType.HEADERS,
parameterNameFixture,
);
});

it('should return a ParameterDecorator', () => {
expect(result).toBe(parameterDecoratorFixture);
});
});
});
39 changes: 39 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Next.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestParam');

import { RequestMethodParameterType } from '../models/RequestMethodParameterType';
import { next } from './Next';
import { requestParam } from './RequestParam';

describe(next.name, () => {
describe('when called', () => {
let parameterDecoratorFixture: ParameterDecorator;
let result: unknown;

beforeAll(() => {
parameterDecoratorFixture = {} as ParameterDecorator;

(requestParam as jest.Mocked<typeof requestParam>).mockReturnValueOnce(
parameterDecoratorFixture,
);

result = next();
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestParam', () => {
expect(requestParam).toHaveBeenCalledTimes(1);
expect(requestParam).toHaveBeenCalledWith(
RequestMethodParameterType.NEXT,
);
});

it('should return a ParameterDecorator', () => {
expect(result).toBe(parameterDecoratorFixture);
});
});
});
42 changes: 42 additions & 0 deletions packages/http/libraries/core/src/http/decorators/Options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

jest.mock('./RequestMethod');

import { RequestMethodType } from '../models/RequestMethodType';
import { OPTIONS } from './Options';
import { requestMethod } from './RequestMethod';

describe(OPTIONS.name, () => {
describe('when called', () => {
let pathFixture: string | undefined;
let methodDecoratorFixture: MethodDecorator;
let result: unknown;

beforeAll(() => {
pathFixture = undefined;
methodDecoratorFixture = {} as MethodDecorator;

(requestMethod as jest.Mocked<typeof requestMethod>).mockReturnValueOnce(
methodDecoratorFixture,
);

result = OPTIONS(pathFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call requestMethod', () => {
expect(requestMethod).toHaveBeenCalledTimes(1);
expect(requestMethod).toHaveBeenCalledWith(
RequestMethodType.OPTIONS,
pathFixture,
);
});

it('should return a MethodDecorator', () => {
expect(result).toBe(methodDecoratorFixture);
});
});
});
Loading

0 comments on commit f004ab9

Please sign in to comment.