Add test for _-prefixed methods

This commit is contained in:
Jerko Steiner 2019-09-05 09:31:32 +07:00
parent c4ae271604
commit 0a1eabadd9

View File

@ -57,7 +57,9 @@ describe('jsonrpc', () => {
addWithContext = (ctx: IContext, a: number, b: number) => {
return a + b + ctx.userId
}
_private = () => {
return 1
}
@ensureLoggedIn
addWithContext2(ctx: IContext, a: number, b: number) {
return Promise.resolve(a + b + ctx!.userId)
@ -214,6 +216,19 @@ describe('jsonrpc', () => {
})
})
it('cannot call private _-prefixed methods', async () => {
await request(createApp())
.post('/myService')
.send({
id: 123,
jsonrpc: '2.0',
method: '_private',
params: [],
})
.expect(404)
.expect(/Method not found/)
})
it('cannot call any other methods in objects prototype', async () => {
await request(createApp())
.post('/myService')