Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6124ae0
feat(http-e2e-tests): add SuccessfulMiddleware and UnsuccessfulMiddle…
adrianmjim Apr 26, 2025
cb3556f
feat(http-e2e-tests): add controllers for warrior CRUD operations wit…
adrianmjim Apr 26, 2025
e068742
feat(http-e2e-tests): implement givenDefinitions for middleware contr…
adrianmjim Apr 26, 2025
efa5332
feat(http-e2e-tests): add middleware feature for successful and unsuc…
adrianmjim Apr 26, 2025
422f0f1
Merge branch 'main' of https://github.com/inversify/monorepo into fea…
adrianmjim Apr 26, 2025
2ccb733
fix(http-core): change TResult type from void to any for better flexi…
adrianmjim Apr 26, 2025
b6cea3b
fix(http-e2e-tests): return response.text() in UnsuccessfulMiddleware…
adrianmjim Apr 26, 2025
67a59cf
Merge branch 'feat/add-middleware-e2e-tests' of https://github.com/in…
adrianmjim Apr 26, 2025
8b484d9
refactor(http-e2e-tests): remove WarriorsGetSuccessfulGuardController…
adrianmjim Apr 26, 2025
1c68606
Merge branch 'main' into feat/add-middleware-e2e-tests
adrianmjim Apr 27, 2025
fad7908
Merge branch 'main' of https://github.com/inversify/monorepo into fea…
adrianmjim May 1, 2025
c0f03d3
Merge branch 'main' of https://github.com/inversify/monorepo into fea…
adrianmjim May 1, 2025
b7f02a2
feat(http-e2e-tests): add new middleware implementations for Express,…
adrianmjim May 1, 2025
732e07d
feat(http-e2e-tests): add new middleware controller implementations f…
adrianmjim May 1, 2025
0af807e
feat(http-e2e-tests): implement successful and unsuccessful middlewar…
adrianmjim May 1, 2025
0831d5f
fix(http-e2e-tests): include <server_kind> in successful and unsucces…
adrianmjim May 1, 2025
7b4701f
Merge branch 'main' into feat/add-middleware-e2e-tests
adrianmjim May 1, 2025
1fd5030
Merge branch 'main' of https://github.com/inversify/monorepo into fea…
adrianmjim May 2, 2025
499380e
refactor(http-e2e-tests): set test header at SuccessfulMiddleware
adrianmjim May 3, 2025
5421ac1
refactor(http-e2e-tests): apply SuccessfulExpressMiddleware to all Un…
adrianmjim May 3, 2025
22846f0
refactor(http-e2e-tests): bind SuccessfulExpressMiddleware to all Uns…
adrianmjim May 3, 2025
a5c5d21
refactor(http-e2e-tests): add header check to middleware feature
adrianmjim May 3, 2025
c90a6eb
Merge branch 'main' into feat/add-middleware-e2e-tests
notaphplover May 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface Middleware<
TRequest = any,
TResponse = any,
TNextFunction = any,
TResult = void,
TResult = any,
> {
execute(
request: TRequest,
Expand Down
77 changes: 77 additions & 0 deletions packages/http/tools/e2e-tests/features/middleware.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Feature: middleware
The m allows to continue or stop the request processing

Background: Having a container
Given a container

Rule: middleware allows to continue or stop the request processing

Scenario: middleware allows to continue request processing
Given a warrior controller with SuccessfulMiddleware for <method> method and <server_kind> server
And a <server_kind> server from container
And a <method> warriors HTTP request
When the request is send
Then the response status code is Ok-ish
Then the response contains the correct header

Examples:
| server_kind | method |
| "express" | "DELETE" |
| "express" | "GET" |
| "express" | "OPTIONS" |
| "express" | "PATCH" |
| "express" | "POST" |
| "express" | "PUT" |
| "express4" | "DELETE" |
| "express4" | "GET" |
| "express4" | "OPTIONS" |
| "express4" | "PATCH" |
| "express4" | "POST" |
| "express4" | "PUT" |
| "fastify" | "DELETE" |
| "fastify" | "GET" |
| "fastify" | "OPTIONS" |
| "fastify" | "PATCH" |
| "fastify" | "POST" |
| "fastify" | "PUT" |
| "hono" | "DELETE" |
| "hono" | "GET" |
| "hono" | "OPTIONS" |
| "hono" | "PATCH" |
| "hono" | "POST" |
| "hono" | "PUT" |

Scenario: middleware allows to stop request processing
Given a warrior controller with UnsuccessfulMiddleware for <method> method and <server_kind> server
And a <server_kind> server from container
And a <method> warriors HTTP request
When the request is send
Then the response status code is FORBIDDEN
Then the response contains the correct header

Examples:
| server_kind | method |
| "express" | "DELETE" |
| "express" | "GET" |
| "express" | "OPTIONS" |
| "express" | "PATCH" |
| "express" | "POST" |
| "express" | "PUT" |
| "express4" | "DELETE" |
| "express4" | "GET" |
| "express4" | "OPTIONS" |
| "express4" | "PATCH" |
| "express4" | "POST" |
| "express4" | "PUT" |
| "fastify" | "DELETE" |
| "fastify" | "GET" |
| "fastify" | "OPTIONS" |
| "fastify" | "PATCH" |
| "fastify" | "POST" |
| "fastify" | "PUT" |
| "hono" | "DELETE" |
| "hono" | "GET" |
| "hono" | "OPTIONS" |
| "hono" | "PATCH" |
| "hono" | "POST" |
| "hono" | "PUT" |
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, DELETE } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsDeleteSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@DELETE()
public async deleteWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, DELETE } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsDeleteUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@DELETE()
public async deleteWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, GET } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsGetSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@GET()
public async getWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, GET } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsGetUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@GET()
public async getWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, OPTIONS } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsOptionsSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@OPTIONS()
public async optionsWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, OPTIONS } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsOptionsUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@OPTIONS()
public async optionsWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, PATCH } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPatchSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@PATCH()
public async patchWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, PATCH } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPatchUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@PATCH()
public async patchWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, POST } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPostSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@POST()
public async postWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, POST } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPostUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@POST()
public async postWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, PUT } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPutSuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware)
@PUT()
public async putWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, controller, PUT } from '@inversifyjs/http-core';

import { SuccessfulExpressMiddleware } from '../../middlewares/express/SuccessfulExpressMiddleware';
import { UnsuccessfulExpressMiddleware } from '../../middlewares/express/UnsuccessfulExpressMiddleware';

@controller('/warriors')
export class WarriorsPutUnsuccessfulExpressMiddlewareController {
@applyMiddleware(SuccessfulExpressMiddleware, UnsuccessfulExpressMiddleware)
@PUT()
public async putWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, DELETE } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsDeleteSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@DELETE()
public async deleteWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, DELETE } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsDeleteUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@DELETE()
public async deleteWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, GET } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsGetSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@GET()
public async getWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, GET } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsGetUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@GET()
public async getWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, OPTIONS } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsOptionsSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@OPTIONS()
public async optionsWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, OPTIONS } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsOptionsUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@OPTIONS()
public async optionsWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, PATCH } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPatchSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@PATCH()
public async patchWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, PATCH } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPatchUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@PATCH()
public async patchWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, POST } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPostSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@POST()
public async postWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, POST } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPostUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@POST()
public async postWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, PUT } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPutSuccessfulExpressV4MiddlewareController {
@applyMiddleware(SuccessfulExpressV4Middleware)
@PUT()
public async putWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { applyMiddleware, controller, PUT } from '@inversifyjs/http-core';

import { SuccessfulExpressV4Middleware } from '../../middlewares/express4/SuccessfulExpressV4Middleware';
import { UnsuccessfulExpressV4Middleware } from '../../middlewares/express4/UnsuccessfulExpressV4Middleware';

@controller('/warriors')
export class WarriorsPutUnsuccessfulExpressV4MiddlewareController {
@applyMiddleware(
SuccessfulExpressV4Middleware,
UnsuccessfulExpressV4Middleware,
)
@PUT()
public async putWarrior(): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { applyMiddleware, controller, DELETE } from '@inversifyjs/http-core';

import { SuccessfulFastifyMiddleware } from '../../middlewares/fastify/SuccessfulFastifyMiddleware';

@controller('/warriors')
export class WarriorsDeleteSuccessfulFastifyMiddlewareController {
@applyMiddleware(SuccessfulFastifyMiddleware)
@DELETE()
public async deleteWarrior(): Promise<void> {}
}
Loading