mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 04:09:12 +00:00
[rpc/http]: properly accomplish tests, fix http sender returning trash
This commit is contained in:
parent
36819e33af
commit
75473ad4f7
3 changed files with 27 additions and 21 deletions
|
@ -58,7 +58,7 @@ export default class HTTPTransport extends Transport {
|
|||
req.on('end', async () => {
|
||||
const o = await this.receiver({ buffer: txtEnc.encode(buf), ctx: this.getContext(req, res) })
|
||||
res.statusCode = 200
|
||||
res.end(o)
|
||||
res.end(txtDec.decode(o))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -143,6 +143,7 @@ export default class HTTPTransport extends Transport {
|
|||
.set('User-Agent', 'roleypoly/2.0 bento http client (+https://roleypoly.com)')
|
||||
.withCredentials()
|
||||
.set(this.injectHeaders)
|
||||
.ok(() => true)
|
||||
|
||||
if (c.length > 0) {
|
||||
r.set('Cookie', c)
|
||||
|
@ -150,6 +151,6 @@ export default class HTTPTransport extends Transport {
|
|||
|
||||
const res = await r
|
||||
|
||||
return Buffer.from(res.body)
|
||||
return txtEnc.encode(res.text)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,32 +3,34 @@ import Bento, { JSONSerializer } from '@kayteh/bento'
|
|||
import { MockBackendClient } from './mock.bento'
|
||||
import MockBackendServer from './mock-server'
|
||||
import * as http from 'http'
|
||||
import * as sinon from 'sinon'
|
||||
import sinon from 'sinon'
|
||||
|
||||
describe('HTTPTransport', () => {
|
||||
const getCC = () => {
|
||||
const NOW = Date.now()
|
||||
const PORT = 20000 + (+(('' + NOW).slice(-4)))
|
||||
const bento = new Bento()
|
||||
const tt = new HTTPTransport(
|
||||
bento,
|
||||
new JSONSerializer(),
|
||||
`https://localhost:${PORT}/api/_rpc`,
|
||||
{}
|
||||
)
|
||||
const bento2 = new Bento()
|
||||
const tt = new HTTPTransport(bento, new JSONSerializer({ verbose: true }), `http://localhost:${PORT}/api/_rpc`, {})
|
||||
const h = tt.handler()
|
||||
const spy = sinon.spy(h)
|
||||
const s = http.createServer(spy)
|
||||
s.listen(PORT)
|
||||
|
||||
bento.transport = tt
|
||||
bento2.transport = tt
|
||||
|
||||
bento.service(MockBackendClient.__SERVICE__, MockBackendServer)
|
||||
const cc = bento.client(MockBackendClient)
|
||||
const cc = bento2.client(MockBackendClient)
|
||||
|
||||
return { cc, spy }
|
||||
}
|
||||
|
||||
describe('HTTPTransport', async () => {
|
||||
|
||||
it('handles full flow properly', async () => {
|
||||
const { cc, spy } = getCC()
|
||||
const out = await cc.helloBackend({ hello: 'yes!' })
|
||||
expect(out.message).toBe(`hello, yes!! i'm bot!!`)
|
||||
expect(spy.called).toBe(true) // oof
|
||||
})
|
||||
|
||||
s.close()
|
||||
})
|
||||
|
|
|
@ -3,23 +3,26 @@ import Bento, { JSONSerializer } from '@kayteh/bento'
|
|||
import { MockBackendClient } from './mock.bento'
|
||||
import MockBackendServer from './mock-server'
|
||||
|
||||
describe('NATSTransport', () => {
|
||||
const getCC = () => {
|
||||
const NOW = Date.now()
|
||||
const bento = new Bento()
|
||||
const bento2 = new Bento()
|
||||
|
||||
const tt = new NATSTransport(
|
||||
bento,
|
||||
new JSONSerializer(),
|
||||
'nats://localhost:4222/',
|
||||
'' + NOW
|
||||
)
|
||||
const tt = new NATSTransport(bento, new JSONSerializer({ verbose: true }), 'nats://localhost:4222/', '' + NOW)
|
||||
|
||||
bento.transport = tt
|
||||
bento2.transport = tt
|
||||
|
||||
bento.service(MockBackendClient.__SERVICE__, MockBackendServer)
|
||||
const cc = bento.client(MockBackendClient)
|
||||
const cc = bento2.client(MockBackendClient)
|
||||
|
||||
return cc
|
||||
}
|
||||
|
||||
describe('NATSTransport', () => {
|
||||
|
||||
it('handles full flow properly', async () => {
|
||||
const cc = getCC()
|
||||
const out = await cc.helloBackend({ hello: 'yes!' })
|
||||
expect(out.message).toBe(`hello, yes!! i'm bot!!`)
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue