-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from Quickchive/test-#239/google-auth
test: create get googla auth e2e test
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { getBuilder } from '../common/application-builder'; | ||
import { HttpStatus, INestApplication } from '@nestjs/common'; | ||
import { StartedPostgreSqlContainer } from '@testcontainers/postgresql'; | ||
import * as request from 'supertest'; | ||
import { DataSource } from 'typeorm'; | ||
import { googleAuthGuardMock } from '../mock/google-auth-guard.mock'; | ||
|
||
const emailStub = 'test@email.com'; | ||
const nameStub = 'test'; | ||
const accessTokenStub = 'testToken'; | ||
|
||
jest.setTimeout(30_000); | ||
describe('[GET] /api/oauth/kakao-auth', () => { | ||
// Application | ||
let app: INestApplication; | ||
let container: StartedPostgreSqlContainer; // TODO 결합도 낮추기 | ||
let dataSource: DataSource; | ||
|
||
beforeAll(async () => { | ||
const { | ||
builder, | ||
container: _container, | ||
dataSource: _dataSource, | ||
} = await getBuilder(); | ||
container = _container; | ||
dataSource = _dataSource; | ||
|
||
const module = await builder | ||
.overrideProvider(DataSource) | ||
.useValue(dataSource) | ||
.overrideGuard(AuthGuard('google')) | ||
.useValue( | ||
googleAuthGuardMock({ | ||
email: emailStub, | ||
name: nameStub, | ||
accessToken: accessTokenStub, | ||
}), | ||
) | ||
.compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
await container.stop(); | ||
}); | ||
|
||
describe('구글 계정 로그인 요청에 성공한다.', () => { | ||
it('302를 반환한다.', async () => { | ||
const { status } = await request(app.getHttpServer()).get( | ||
'/oauth/google-auth', | ||
); | ||
|
||
expect(status).toBe(HttpStatus.FOUND); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { ExecutionContext } from '@nestjs/common'; | ||
import { googleUserInfo } from '../../src/auth/dtos/google.dto'; | ||
|
||
export const googleAuthGuardMock = (googleUserInfo: googleUserInfo) => ({ | ||
canActivate: (context: ExecutionContext) => { | ||
const request = context.switchToHttp().getRequest(); | ||
const response = context.switchToHttp().getResponse(); | ||
|
||
request.user = googleUserInfo; | ||
|
||
response.redirect(); | ||
|
||
return true; | ||
}, | ||
}); |