This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): beta.11 - fastify adapter (#191)
- Loading branch information
Showing
33 changed files
with
1,352 additions
and
65 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
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,34 @@ | ||
import { Application, HttpStatus, Module } from '@server'; | ||
import { FastifyAdapter } from '@server/fastify'; | ||
import { HttpModule } from '@server/http'; | ||
import * as request from 'supertest'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(FastifyAdapter), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Fastify :: App Version', () => { | ||
let app: Application; | ||
let module: HttpModule; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
module = await app.inject<HttpModule>(HttpModule); | ||
|
||
await module.listen(); | ||
}); | ||
|
||
afterEach(() => module.close()); | ||
|
||
it('registers `get` request with app version prefix', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/app-version/get') | ||
.expect(HttpStatus.OK); | ||
}); | ||
}); |
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
44 changes: 44 additions & 0 deletions
44
server/integration/core/custom-decorators/test/fastify.spec.ts
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,44 @@ | ||
import { Application, Module, Reflector } from '@server'; | ||
import { FastifyAdapter } from '@server/fastify'; | ||
import { HttpModule } from '@server/http'; | ||
import * as request from 'supertest'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(FastifyAdapter), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Fastify :: Custom Decorators', () => { | ||
let app: Application; | ||
let module: HttpModule; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
module = await app.inject<HttpModule>(HttpModule); | ||
|
||
await module.listen(); | ||
}); | ||
|
||
afterEach(() => module.close()); | ||
|
||
it('checks availability of reflector', async () => { | ||
expect(await app.inject(Reflector)).toBeDefined(); | ||
}); | ||
|
||
it('decorates `get` request and its params', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/?param=decorated') | ||
.expect('decorated'); | ||
}); | ||
|
||
it('throws error during `get` request', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/?param=failure') | ||
.expect(({ body }) => expect(body.message).toEqual('decorated-error')); | ||
}); | ||
}); |
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,71 @@ | ||
import { Application, Module } from '@server'; | ||
import { FastifyAdapter } from '@server/fastify'; | ||
import { HttpModule } from '@server/http'; | ||
import * as request from 'supertest'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
import { Sequence } from '../src/sequence'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(FastifyAdapter), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Fastify :: Pipes', () => { | ||
let app: Application; | ||
let module: HttpModule; | ||
let seq: Sequence; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
module = await app.inject<HttpModule>(HttpModule); | ||
seq = await app.inject<Sequence>(Sequence); | ||
|
||
jest.spyOn(seq, 'push'); | ||
|
||
await module.listen(); | ||
}); | ||
|
||
afterEach(() => module.close()); | ||
|
||
it('executes pipes', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/') | ||
.expect(() => { | ||
expect(seq.push).toBeCalledWith('server'); | ||
expect(seq.push).toBeCalledWith('controller'); | ||
expect(seq.push).toBeCalledWith('method'); | ||
expect(seq.push).toBeCalledWith('method'); | ||
expect(seq.push).toBeCalledWith('controller'); | ||
expect(seq.push).toBeCalledWith('server'); | ||
}); | ||
}); | ||
|
||
it('executes pipes with method error', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/with-method-error') | ||
.expect((res) => { | ||
expect(res.body.message).toBe('method-error'); | ||
expect(seq.push).toBeCalledWith('server'); | ||
expect(seq.push).toBeCalledWith('controller'); | ||
expect(seq.push).toBeCalledWith('method'); | ||
expect(seq.push).toBeCalledWith('method'); | ||
expect(seq.push).toBeCalledWith('controller'); | ||
expect(seq.push).toBeCalledWith('server'); | ||
}); | ||
}); | ||
|
||
it('executes pipes with pipe error', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/with-pipe-error') | ||
.expect((res) => { | ||
expect(res.body.message).toBe('pipe-error'); | ||
expect(seq.push).toBeCalledWith('server'); | ||
expect(seq.push).toBeCalledWith('controller'); | ||
expect(seq.push).toBeCalledWith('server'); | ||
}); | ||
}); | ||
}); |
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,25 @@ | ||
import { Application, Module } from '@server'; | ||
import { FastifyAdapter } from '@server/fastify'; | ||
import { HttpModule } from '@server/http'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(FastifyAdapter), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Fastify :: Scopes', () => { | ||
let app: Application; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
}); | ||
|
||
it('creates app without errors', () => { | ||
expect(app).toBeDefined(); | ||
}); | ||
}); |
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
39 changes: 39 additions & 0 deletions
39
server/integration/http/metadata-scanner/test/fastify.spec.ts
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,39 @@ | ||
import { Application, Module } from '@server'; | ||
import { FastifyAdapter } from '@server/fastify'; | ||
import { HttpModule } from '@server/http'; | ||
import { MetadataScanner } from '@server/http'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(FastifyAdapter), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Fastify :: Metadata Scanner', () => { | ||
let app: Application; | ||
let scanner: MetadataScanner; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
scanner = await app.inject<MetadataScanner>(MetadataScanner); | ||
}); | ||
|
||
it('provides access to the metadata', () => { | ||
const routesMetadata = scanner.scan(); | ||
|
||
expect(routesMetadata).toEqual(expect.arrayContaining([expect.objectContaining({ | ||
methodName: 'post', | ||
params: expect.arrayContaining([expect.objectContaining({ | ||
argName: 'body', | ||
index: 0, | ||
methodName: 'post', | ||
})]), | ||
type: 'post', | ||
url: '/', | ||
})])); | ||
}); | ||
}); |
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
Oops, something went wrong.