Skip to content

Commit

Permalink
release: v3.7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Oct 2, 2021
1 parent 1ea8ab2 commit 9103863
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS ENV FILE EXAMPLE ONLY FOR DOCKER COMPOSE
# SEE https://docs.docker.com/compose/environment-variables/#the-env-file
JWT_SECRET=asffasgvxczfqreqw213
ALLOWED_ORIGINS=https://innei.ren,https://www.innei.ren
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [3.7.7](https://github.com/mx-space/server-next/compare/v3.7.6...v3.7.7) (2021-10-02)


### Bug Fixes

* app config shared ([b7db64e](https://github.com/mx-space/server-next/commit/b7db64e3ae3df1ecc945badece9e3e00533a11a1))
* **deps:** update dependency rxjs to v7.3.1 ([bd55864](https://github.com/mx-space/server-next/commit/bd558641abe5aabd84727a3d357be039699a7857))
* node patch ([1ea8ab2](https://github.com/mx-space/server-next/commit/1ea8ab211db1f00d69a2a9b81321e28e58f15a24))



## [3.7.6](https://github.com/mx-space/server-next/compare/v3.7.5...v3.7.6) (2021-10-01)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server-next",
"version": "3.7.6",
"version": "3.7.7",
"description": "",
"author": "Innei <https://innei.ren>",
"private": true,
Expand Down
71 changes: 71 additions & 0 deletions test/src/modules/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { JwtModule } from '@nestjs/jwt'
import { PassportModule } from '@nestjs/passport'
import { Test } from '@nestjs/testing'
import { getModelToken } from 'nestjs-typegoose'
import { SECURITY } from '~/app.config'
import { AuthService } from '~/modules/auth/auth.service'
import { JwtStrategy } from '~/modules/auth/jwt.strategy'
import { UserModel } from '~/modules/user/user.model'

describe('Test AuthService', () => {
let service: AuthService

const mockUser = {
_id: '1',
id: '1',
username: 'test-user',
email: '[email protected]',
authCode: 'authCode',
}
beforeAll(async () => {
const __secret: any = SECURITY.jwtSecret || 'asjhczxiucipoiopiqm2376'

const jwtModule = JwtModule.registerAsync({
useFactory() {
return {
secret: __secret,
signOptions: {
expiresIn: SECURITY.jwtExpire,
algorithm: 'HS256',
},
}
},
})

const moduleRef = Test.createTestingModule({
imports: [jwtModule, PassportModule],
providers: [
JwtStrategy,
AuthService,
{
provide: getModelToken(UserModel.name),
useValue: {
findById: jest.fn().mockReturnValue({
select: jest.fn().mockResolvedValue({
...mockUser,
}),
}),
},
},
],
})

const app = await moduleRef.compile()
await app.init()
service = app.get(AuthService)
})

it('should sign token', async () => {
const _token = await service.signToken('1')
expect(_token).toBeDefined()
})

it('should verifyied', async () => {
const user = await service.verifyPayload({
_id: '1',
authCode: 'authCode',
})
expect(user).toBeDefined()
expect(user).toEqual(mockUser)
})
})
74 changes: 74 additions & 0 deletions test/src/modules/users/users.controller.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { Test } from '@nestjs/testing'
import { hashSync } from 'bcrypt'
import { getModelToken } from 'nestjs-typegoose'
import { fastifyApp } from '~/common/adapt/fastify'
import { AuthService } from '~/modules/auth/auth.service'
import { UserController } from '~/modules/user/user.controller'
import { UserModel } from '~/modules/user/user.model'
import { UserService } from '~/modules/user/user.service'

describe('AppController (e2e)', () => {
let app: NestFastifyApplication

beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [UserController],
providers: [
{
provide: AuthService,
useValue: {
signToken() {
return ''
},
},
},
{
provide: UserService,
useValue: {
login() {
return {
username: 'test',
avatar: '',
email: '[email protected]',
}
},
recordFootstep() {
return {}
},
},
},
{
provide: getModelToken(UserModel.name),
useValue: {
findOne: jest.fn().mockImplementationOnce(() => ({
select: jest.fn().mockResolvedValueOnce({
username: 'test',
password: hashSync('pwd', 2),
}),
})),
},
},
],
}).compile()

app = moduleRef.createNestApplication<NestFastifyApplication>(fastifyApp)
await app.init()
await app.getHttpAdapter().getInstance().ready()
})

it('GET /master/login', () => {
return app
.inject({
method: 'POST',
url: '/master/login',
payload: {
username: 'test',
password: 'pwd',
},
})
.then((res) => {
expect(res.statusCode).toBe(200)
})
})
})

0 comments on commit 9103863

Please sign in to comment.