Skip to content

Commit 9103863

Browse files
committed
release: v3.7.7
1 parent 1ea8ab2 commit 9103863

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS ENV FILE EXAMPLE ONLY FOR DOCKER COMPOSE
2+
# SEE https://docs.docker.com/compose/environment-variables/#the-env-file
3+
JWT_SECRET=asffasgvxczfqreqw213
4+
ALLOWED_ORIGINS=https://innei.ren,https://www.innei.ren

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## [3.7.7](https://github.com/mx-space/server-next/compare/v3.7.6...v3.7.7) (2021-10-02)
2+
3+
4+
### Bug Fixes
5+
6+
* app config shared ([b7db64e](https://github.com/mx-space/server-next/commit/b7db64e3ae3df1ecc945badece9e3e00533a11a1))
7+
* **deps:** update dependency rxjs to v7.3.1 ([bd55864](https://github.com/mx-space/server-next/commit/bd558641abe5aabd84727a3d357be039699a7857))
8+
* node patch ([1ea8ab2](https://github.com/mx-space/server-next/commit/1ea8ab211db1f00d69a2a9b81321e28e58f15a24))
9+
10+
11+
112
## [3.7.6](https://github.com/mx-space/server-next/compare/v3.7.5...v3.7.6) (2021-10-01)
213

314

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "server-next",
3-
"version": "3.7.6",
3+
"version": "3.7.7",
44
"description": "",
55
"author": "Innei <https://innei.ren>",
66
"private": true,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { JwtModule } from '@nestjs/jwt'
2+
import { PassportModule } from '@nestjs/passport'
3+
import { Test } from '@nestjs/testing'
4+
import { getModelToken } from 'nestjs-typegoose'
5+
import { SECURITY } from '~/app.config'
6+
import { AuthService } from '~/modules/auth/auth.service'
7+
import { JwtStrategy } from '~/modules/auth/jwt.strategy'
8+
import { UserModel } from '~/modules/user/user.model'
9+
10+
describe('Test AuthService', () => {
11+
let service: AuthService
12+
13+
const mockUser = {
14+
_id: '1',
15+
id: '1',
16+
username: 'test-user',
17+
email: 'tukon@gmail.com',
18+
authCode: 'authCode',
19+
}
20+
beforeAll(async () => {
21+
const __secret: any = SECURITY.jwtSecret || 'asjhczxiucipoiopiqm2376'
22+
23+
const jwtModule = JwtModule.registerAsync({
24+
useFactory() {
25+
return {
26+
secret: __secret,
27+
signOptions: {
28+
expiresIn: SECURITY.jwtExpire,
29+
algorithm: 'HS256',
30+
},
31+
}
32+
},
33+
})
34+
35+
const moduleRef = Test.createTestingModule({
36+
imports: [jwtModule, PassportModule],
37+
providers: [
38+
JwtStrategy,
39+
AuthService,
40+
{
41+
provide: getModelToken(UserModel.name),
42+
useValue: {
43+
findById: jest.fn().mockReturnValue({
44+
select: jest.fn().mockResolvedValue({
45+
...mockUser,
46+
}),
47+
}),
48+
},
49+
},
50+
],
51+
})
52+
53+
const app = await moduleRef.compile()
54+
await app.init()
55+
service = app.get(AuthService)
56+
})
57+
58+
it('should sign token', async () => {
59+
const _token = await service.signToken('1')
60+
expect(_token).toBeDefined()
61+
})
62+
63+
it('should verifyied', async () => {
64+
const user = await service.verifyPayload({
65+
_id: '1',
66+
authCode: 'authCode',
67+
})
68+
expect(user).toBeDefined()
69+
expect(user).toEqual(mockUser)
70+
})
71+
})
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { NestFastifyApplication } from '@nestjs/platform-fastify'
2+
import { Test } from '@nestjs/testing'
3+
import { hashSync } from 'bcrypt'
4+
import { getModelToken } from 'nestjs-typegoose'
5+
import { fastifyApp } from '~/common/adapt/fastify'
6+
import { AuthService } from '~/modules/auth/auth.service'
7+
import { UserController } from '~/modules/user/user.controller'
8+
import { UserModel } from '~/modules/user/user.model'
9+
import { UserService } from '~/modules/user/user.service'
10+
11+
describe('AppController (e2e)', () => {
12+
let app: NestFastifyApplication
13+
14+
beforeAll(async () => {
15+
const moduleRef = await Test.createTestingModule({
16+
controllers: [UserController],
17+
providers: [
18+
{
19+
provide: AuthService,
20+
useValue: {
21+
signToken() {
22+
return ''
23+
},
24+
},
25+
},
26+
{
27+
provide: UserService,
28+
useValue: {
29+
login() {
30+
return {
31+
username: 'test',
32+
avatar: '',
33+
email: 'tukon@gmail.com',
34+
}
35+
},
36+
recordFootstep() {
37+
return {}
38+
},
39+
},
40+
},
41+
{
42+
provide: getModelToken(UserModel.name),
43+
useValue: {
44+
findOne: jest.fn().mockImplementationOnce(() => ({
45+
select: jest.fn().mockResolvedValueOnce({
46+
username: 'test',
47+
password: hashSync('pwd', 2),
48+
}),
49+
})),
50+
},
51+
},
52+
],
53+
}).compile()
54+
55+
app = moduleRef.createNestApplication<NestFastifyApplication>(fastifyApp)
56+
await app.init()
57+
await app.getHttpAdapter().getInstance().ready()
58+
})
59+
60+
it('GET /master/login', () => {
61+
return app
62+
.inject({
63+
method: 'POST',
64+
url: '/master/login',
65+
payload: {
66+
username: 'test',
67+
password: 'pwd',
68+
},
69+
})
70+
.then((res) => {
71+
expect(res.statusCode).toBe(200)
72+
})
73+
})
74+
})

0 commit comments

Comments
 (0)