Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

테스트 개선 #351

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions nestjs-BE/server/src/spaces/spaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,24 @@ export class SpacesControllerV2 {
@UseInterceptors(FileInterceptor('icon'))
@ApiOperation({ summary: 'Update space by space_uuid' })
@ApiResponse({
status: 200,
status: HttpStatus.OK,
description: 'Space has been successfully updated.',
})
@ApiResponse({
status: 400,
description: 'Bad Request. Invalid input data.',
status: HttpStatus.BAD_REQUEST,
description: 'Profile uuid needed. ',
})
@ApiResponse({
status: 404,
description: 'Space not found.',
status: HttpStatus.UNAUTHORIZED,
description: 'User not logged in.',
})
@ApiResponse({
status: HttpStatus.FORBIDDEN,
description: "Profile user doesn't have. Profile not joined space.",
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Profile not found.',
})
async update(
@UploadedFile() icon: Express.Multer.File,
Expand Down
39 changes: 21 additions & 18 deletions nestjs-BE/server/test/spaces.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { PrismaService } from '../src/prisma/prisma.service';
import { sign } from 'jsonwebtoken';
import { Profile, Space } from '@prisma/client';
import { v4 as uuid } from 'uuid';
import { readFile } from 'fs/promises';
import { resolve } from 'path';

describe('SpacesController (e2e)', () => {
let app: INestApplication;
Expand All @@ -16,6 +18,7 @@ describe('SpacesController (e2e)', () => {
let testProfile: Profile;
let configService: ConfigService;
let prisma: PrismaService;
const testImagePath = resolve(__dirname, './base_image.png');

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand Down Expand Up @@ -73,7 +76,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces (POST)', () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand Down Expand Up @@ -126,7 +129,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces (POST) without profile uuid', () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand All @@ -141,7 +144,7 @@ describe('SpacesController (e2e)', () => {

it('/v2/spaces (POST) without space name', () => {
const newSpace = {
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand All @@ -164,7 +167,7 @@ describe('SpacesController (e2e)', () => {
it("/v2/spaces (POST) profile user doesn't have", async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};
const newUser = await prisma.user.create({ data: { uuid: uuid() } });
Expand All @@ -190,7 +193,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces (POST) profilie not found', () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand Down Expand Up @@ -287,7 +290,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) update success', async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};
await prisma.profileSpace.create({
Expand Down Expand Up @@ -317,7 +320,7 @@ describe('SpacesController (e2e)', () => {

it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) request without name', async () => {
const newSpace = {
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};
const imageUrlPattern = `^https\\:\\/\\/${configService.get<string>(
Expand Down Expand Up @@ -369,7 +372,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) profile uuid needed', async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand All @@ -383,24 +386,24 @@ describe('SpacesController (e2e)', () => {
});

it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) unauthorized', async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
iconContentType: 'image/png',
};
const icon = await readFile(resolve(__dirname, './base_image.png'));
const newSpace = { name: 'new test space', icon };

return request(app.getHttpServer())
.patch(`/v2/spaces/${testSpace.uuid}?profile_uuid=${testProfile.uuid}`)
.field('name', newSpace.name)
.attach('icon', newSpace.icon, { contentType: newSpace.iconContentType })
.attach('icon', newSpace.icon)
.expect(HttpStatus.UNAUTHORIZED)
.expect({ message: 'Unauthorized', statusCode: HttpStatus.UNAUTHORIZED });
.expect({
message: 'Unauthorized',
statusCode: HttpStatus.UNAUTHORIZED,
});
});

it("/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) profile user doesn't have", async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};
const newUser = await prisma.user.create({ data: { uuid: uuid() } });
Expand Down Expand Up @@ -428,7 +431,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) profile not joined space', async () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};
const newUser = await prisma.user.create({ data: { uuid: uuid() } });
Expand All @@ -453,7 +456,7 @@ describe('SpacesController (e2e)', () => {
it('/v2/spaces/:space_uuid?profile_uuid={profile_uuid} (PATCH) profile not found', () => {
const newSpace = {
name: 'new test space',
icon: './test/base_image.png',
icon: testImagePath,
iconContentType: 'image/png',
};

Expand Down
Loading