-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix BaseController.ok on non string content (#423)
* refactor: update JsonResult with no generic * fix: update OkNegotiatedContentResult update OkNegotiatedContentResult to rely on JsonContent when non string content is provided
- Loading branch information
1 parent
800f041
commit f0eb0de
Showing
11 changed files
with
84 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { beforeEach, describe, expect, it } from '@jest/globals'; | ||
import * as bodyParser from 'body-parser'; | ||
import { Application, Request } from 'express'; | ||
import { Container } from 'inversify'; | ||
import supertest from 'supertest'; | ||
import TestAgent from 'supertest/lib/agent'; | ||
|
||
import { BaseHttpController } from '../../base_http_controller'; | ||
import { controller, httpPut, request } from '../../decorators'; | ||
import { InversifyExpressServer } from '../../server'; | ||
import { cleanUpMetadata } from '../../utils'; | ||
|
||
describe('Issue 420', () => { | ||
beforeEach(() => { | ||
cleanUpMetadata(); | ||
}); | ||
|
||
it('should work with no url params', async () => { | ||
@controller('/controller') | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
class TestController extends BaseHttpController { | ||
@httpPut('/test') | ||
public async updateTest( | ||
@request() | ||
req: Request<unknown, unknown, { test: string }, void>, | ||
) { | ||
return this.ok({ message: req.body.test }); | ||
} | ||
} | ||
|
||
const container: Container = new Container(); | ||
|
||
const server: InversifyExpressServer = new InversifyExpressServer( | ||
container, | ||
); | ||
|
||
server.setConfig((app: Application) => { | ||
app.use( | ||
bodyParser.urlencoded({ | ||
extended: true, | ||
}), | ||
); | ||
app.use(bodyParser.json()); | ||
}); | ||
|
||
const agent: TestAgent<supertest.Test> = supertest(server.build()); | ||
|
||
const response: supertest.Response = await agent | ||
.put('/controller/test') | ||
.send({ test: 'test' }) | ||
.set('Content-Type', 'application/json') | ||
.set('Accept', 'application/json'); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body).toStrictEqual({ message: 'test' }); | ||
}); | ||
}); |