Skip to content

Commit

Permalink
test: create get google login e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
stae1102 committed Jan 28, 2024
1 parent d9419e2 commit 99c9605
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/auth/get-google-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const nameStub = 'test';
const accessTokenStub = 'testToken';

jest.setTimeout(30_000);
describe('[GET] /api/oauth/kakao-auth', () => {
describe('[GET] /api/oauth/google-auth', () => {
// Application
let app: INestApplication;
let container: StartedPostgreSqlContainer; // TODO 결합도 낮추기
Expand Down
67 changes: 67 additions & 0 deletions test/auth/get-google-login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { AuthGuard } from '@nestjs/passport';
import { getBuilder } from '../common/application-builder';
import { CACHE_MANAGER, 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';
import { cacheManagerMock } from '../mock/cache-manager.mock';

const emailStub = 'test@email.com';
const nameStub = 'test';
const accessTokenStub = 'testToken';

jest.setTimeout(30_000);
describe('[GET] /api/oauth/google-login', () => {
// 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,
}),
)
.overrideProvider(CACHE_MANAGER)
.useValue(cacheManagerMock)
.compile();

app = module.createNestApplication();
await app.init();
});

afterAll(async () => {
await app.close();
await container.stop();
});

describe('구글 로그인에 성공한다', () => {
it('토큰과 함께 200을 반환한다.', async () => {
const { status, body } = await request(app.getHttpServer()).get(
'/oauth/google-login',
);

console.log(body);

expect(status).toBe(HttpStatus.OK);
expect(typeof body.access_token).toBe('string');
expect(typeof body.refresh_token).toBe('string');
});
});
});

0 comments on commit 99c9605

Please sign in to comment.