Skip to content

Commit

Permalink
fix(express): send not detected on decorated application
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyben committed Nov 2, 2021
1 parent 555c3d3 commit f8656d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 20 additions & 7 deletions express/__tests__/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { log } from '../../testing/tools'
test('simple app', async () => {
@Send()
@Router('/')
class Bar {
@Get('/bar')
class Simple {
@Get('/simple')
getOne() {
return 'bar'
return 'simple'
}
}

const app = new Application().register([Bar])
const app = new Application().register([Simple])
const rq = supertest(app)

const res = await rq.get('/bar')
expect(res.text).toBe('bar')
const res = await rq.get('/simple')
expect(res.text).toBe('simple')
expect(res.type).toBe('text/html')
})

Expand All @@ -36,6 +36,14 @@ describe('inherit application class', () => {
}
}

@Router('/bar')
class Bar {
@Get('/')
getBar() {
return true
}
}

class Service {
user = 'Jeremy'
}
Expand Down Expand Up @@ -73,7 +81,7 @@ describe('inherit application class', () => {
private successText = 'success'
}

const app = new App(new Service()).register([Foo])
const app = new App(new Service()).register([Foo, Bar])
const rq = supertest(app)

test('inheritance', () => {
Expand All @@ -84,6 +92,11 @@ describe('inherit application class', () => {
expect(app.service.user).toBe('Jeremy')
})

test('send inheritance', async () => {
const res = await rq.get('/bar')
expect(res.text).toEqual('true')
})

test('middlewares and route', async () => {
const res = await rq.get('/healthcheck')

Expand Down
4 changes: 3 additions & 1 deletion express/src/send-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ export function extractSend(
key: string | symbol,
appClass?: ClassType
): Send.Options | null | undefined {
const appSend: Send.Options | undefined = appClass ? Reflect.getOwnMetadata(META, appClass) : undefined
const appSend: Send.Options | undefined = appClass
? Reflect.getOwnMetadata(META, (appClass as Function).prototype)
: undefined

const routerSend: Send.Options | null | undefined = Reflect.getOwnMetadata(META, (target as Function).prototype)

Expand Down

0 comments on commit f8656d6

Please sign in to comment.