@gasket/plugin-fastify 7.0.0-next.69 → 7.0.0-next.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generator/app/routes/index.js +28 -0
- package/generator/app/routes/index.ts +29 -0
- package/generator/jest/jest.config.js +4 -0
- package/generator/jest/jest.config.ts +17 -0
- package/generator/jest/test/index.test.js +20 -0
- package/generator/jest/test/index.test.ts +26 -0
- package/generator/jest/tsconfig.test.json +7 -0
- package/generator/mocha/test/index.test.js +23 -0
- package/generator/mocha/test/index.test.ts +23 -0
- package/package.json +4 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import gasket from '../gasket.js';
|
|
2
|
+
|
|
3
|
+
const app = gasket.actions.getFastifyApp();
|
|
4
|
+
|
|
5
|
+
export const defaultHandler = async (req, res) => {
|
|
6
|
+
if (res.statusCode === 200) {
|
|
7
|
+
res.send({ message: 'Welcome to your default route...' });
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
{{#if useSwagger}}
|
|
12
|
+
/**
|
|
13
|
+
* @swagger
|
|
14
|
+
*
|
|
15
|
+
* /default:
|
|
16
|
+
* get:
|
|
17
|
+
* summary: "Get default route"
|
|
18
|
+
* produces:
|
|
19
|
+
* - "application/json"
|
|
20
|
+
* responses:
|
|
21
|
+
* "200":
|
|
22
|
+
* description: "Returns welcome message."
|
|
23
|
+
* content:
|
|
24
|
+
* application/json
|
|
25
|
+
*/
|
|
26
|
+
{{/if}}
|
|
27
|
+
app.get('/default', defaultHandler);
|
|
28
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
import gasket from '../gasket.js';
|
|
3
|
+
|
|
4
|
+
const app = gasket.actions.getFastifyApp();
|
|
5
|
+
|
|
6
|
+
export const defaultHandler = async (req: FastifyRequest, res: FastifyReply) => {
|
|
7
|
+
if (res.statusCode === 200) {
|
|
8
|
+
res.send({ message: 'Welcome to your default route...' });
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
{{#if useSwagger}}
|
|
13
|
+
/**
|
|
14
|
+
* @swagger
|
|
15
|
+
*
|
|
16
|
+
* /default:
|
|
17
|
+
* get:
|
|
18
|
+
* summary: "Get default route"
|
|
19
|
+
* produces:
|
|
20
|
+
* - "application/json"
|
|
21
|
+
* responses:
|
|
22
|
+
* "200":
|
|
23
|
+
* description: "Returns welcome message."
|
|
24
|
+
* content:
|
|
25
|
+
* application/json
|
|
26
|
+
*/
|
|
27
|
+
{{/if}}
|
|
28
|
+
app.get('/default', defaultHandler);
|
|
29
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JestConfigWithTsJest } from 'ts-jest';
|
|
2
|
+
|
|
3
|
+
const config: JestConfigWithTsJest = {
|
|
4
|
+
preset: 'ts-jest/presets/default-esm',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
injectGlobals: true,
|
|
7
|
+
moduleDirectories: ['node_modules', '<rootDir>'],
|
|
8
|
+
moduleNameMapper: {
|
|
9
|
+
'^(\\.{1,2}/.*)\\.js$': '$1'
|
|
10
|
+
},
|
|
11
|
+
transform: {
|
|
12
|
+
'^.+.ts$': ['ts-jest', { useESM: true }]
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default config;
|
|
17
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
import { defaultHandler } from '../routes';
|
|
3
|
+
|
|
4
|
+
describe('Routes', () => {
|
|
5
|
+
let mockRequest, mockResponse;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
mockRequest = {};
|
|
8
|
+
mockResponse = {
|
|
9
|
+
statusCode: 200,
|
|
10
|
+
send: jest.fn()
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('defaultHandler should use expeced message', async () => {
|
|
15
|
+
await defaultHandler(mockRequest, mockResponse);
|
|
16
|
+
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
17
|
+
message: 'Welcome to your default route...'
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
jest,
|
|
3
|
+
describe,
|
|
4
|
+
beforeEach,
|
|
5
|
+
it,
|
|
6
|
+
expect
|
|
7
|
+
} from '@jest/globals';
|
|
8
|
+
import { defaultHandler } from '../routes';
|
|
9
|
+
|
|
10
|
+
describe('Routes', () => {
|
|
11
|
+
let mockRequest, mockResponse;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockRequest = {};
|
|
14
|
+
mockResponse = {
|
|
15
|
+
statusCode: 200,
|
|
16
|
+
send: jest.fn()
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('defaultHandler should use expeced message', async () => {
|
|
21
|
+
await defaultHandler(mockRequest, mockResponse);
|
|
22
|
+
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
23
|
+
message: 'Welcome to your default route...'
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import { defaultHandler } from '../routes/index.js';
|
|
4
|
+
|
|
5
|
+
describe('Routes', () => {
|
|
6
|
+
let mockRequest, mockResponse, sendSpy;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockRequest = {};
|
|
10
|
+
sendSpy = sinon.spy();
|
|
11
|
+
mockResponse = {
|
|
12
|
+
statusCode: 200,
|
|
13
|
+
send: sendSpy
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('defaultHandler should use expected message', async () => {
|
|
18
|
+
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
+
expect(sendSpy.calledWith({
|
|
20
|
+
message: 'Welcome to your default route...'
|
|
21
|
+
})).to.be.true;
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import { defaultHandler } from '../routes/index.js';
|
|
4
|
+
|
|
5
|
+
describe('Routes', () => {
|
|
6
|
+
let mockRequest, mockResponse, sendSpy;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockRequest = {};
|
|
10
|
+
sendSpy = sinon.spy();
|
|
11
|
+
mockResponse = {
|
|
12
|
+
statusCode: 200,
|
|
13
|
+
send: sendSpy
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('defaultHandler should use expected message', async () => {
|
|
18
|
+
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
+
expect(sendSpy.calledWith({
|
|
20
|
+
message: 'Welcome to your default route...'
|
|
21
|
+
})).to.be.true;
|
|
22
|
+
});
|
|
23
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.70",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
+
"generator",
|
|
8
9
|
"lib"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
},
|
|
37
38
|
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-fastify",
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@gasket/core": "7.0.0-next.
|
|
40
|
+
"@gasket/core": "7.0.0-next.70",
|
|
40
41
|
"cross-env": "^7.0.3",
|
|
41
42
|
"eslint": "^8.56.0",
|
|
42
43
|
"eslint-config-godaddy": "^7.1.1",
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
"jest": {
|
|
72
73
|
"rootDir": "test"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "f261bf98ca587e646dc61fa49dd50859a0f43a47"
|
|
75
76
|
}
|