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

[BE] Images e2e 테스트 작성 #386

Merged
merged 5 commits into from
Feb 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@
"@typescript-eslint/parser": "^6.0.0",
"jest": "^29.5.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"supertest": "^6.3.4",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
66 changes: 66 additions & 0 deletions backend/test/images/images.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as request from 'supertest';
import { ExecutionContext, INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { AppModule } from 'src/app.module';
import { JwtAuthGuard } from 'src/auth/guards/jwtAuth.guard';
import { ImagesRepository } from 'src/images/images.repository';

describe('ImagesController (e2e)', () => {
let app: INestApplication;
let imagesRepository: ImagesRepository;
const user = { id: 1, nickname: 'testUser' };

beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
})
.overrideGuard(JwtAuthGuard)
.useValue({
canActivate: (context: ExecutionContext) => {
const req = context.switchToHttp().getRequest();
req.user = user;

return true;
},
})
.compile();

imagesRepository = module.get<ImagesRepository>(ImagesRepository);
app = module.createNestApplication();
await app.init();
});

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

describe('/images/diaries (POST)', () => {
const url = '/images/diaries';

it('이미지 정상 업로드', async () => {
// given
const imageFilePath = './test/testImage.png';
const uploadedLocation = `https://dandi-object-storage.kr.object.ncloudstorage.com/${user.id}/2024/01/testImage.png`;
imagesRepository.uploadImage = jest.fn();
(imagesRepository.uploadImage as jest.Mock).mockReturnValue({ Location: uploadedLocation });

// when
const response = await request(app.getHttpServer()).post(url).attach('image', imageFilePath);

// then
expect(response.status).toEqual(201);
expect(response.body.imageURL).toEqual(uploadedLocation);
});

it('파일의 MIME type이 맞지 않는 경우 예외 발생', async () => {
// given
const imageFilePath = './test/images/testFile.txt';

// when
const response = await request(app.getHttpServer()).post(url).attach('image', imageFilePath);

// then
expect(response.status).toEqual(400);
});
});
});
1 change: 1 addition & 0 deletions backend/test/images/testFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"postcss": "^8.4.31",
"prettier-plugin-tailwindcss": "^0.5.7",
"tailwindcss": "^3.3.5",
"vite": "^4.5.1",
"vite": "4.5.2",
"vite-plugin-pwa": "^0.17.4"
}
}
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -8401,7 +8401,7 @@ sucrase@^3.32.0:
pirates "^4.0.1"
ts-interface-checker "^0.1.9"

superagent@^8.0.5:
superagent@^8.1.2:
version "8.1.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-8.1.2.tgz#03cb7da3ec8b32472c9d20f6c2a57c7f3765f30b"
integrity sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==
@@ -8417,13 +8417,13 @@ superagent@^8.0.5:
qs "^6.11.0"
semver "^7.3.8"

supertest@^6.3.3:
version "6.3.3"
resolved "https://registry.yarnpkg.com/supertest/-/supertest-6.3.3.tgz#42f4da199fee656106fd422c094cf6c9578141db"
integrity sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==
supertest@^6.3.4:
version "6.3.4"
resolved "https://registry.yarnpkg.com/supertest/-/supertest-6.3.4.tgz#2145c250570c2ea5d337db3552dbfb78a2286218"
integrity sha512-erY3HFDG0dPnhw4U+udPfrzXa4xhSG+n4rxfRuZWCUvjFWwKl+OxWf/7zk50s84/fAAs7vf5QAb9uRa0cCykxw==
dependencies:
methods "^1.1.2"
superagent "^8.0.5"
superagent "^8.1.2"

supports-color@^5.3.0:
version "5.5.0"
@@ -9063,10 +9063,10 @@ vite-plugin-pwa@^0.17.4:
workbox-build "^7.0.0"
workbox-window "^7.0.0"

vite@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.0.tgz#ec406295b4167ac3bc23e26f9c8ff559287cff26"
integrity sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==
vite@4.5.2:
version "4.5.2"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.2.tgz#d6ea8610e099851dad8c7371599969e0f8b97e82"
integrity sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==
dependencies:
esbuild "^0.18.10"
postcss "^8.4.27"