-
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 #386 from shunny822/be/test/images-e2e
[BE] Images e2e 테스트 작성
- Loading branch information
Showing
5 changed files
with
79 additions
and
12 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
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,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); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
test |
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
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 |
---|---|---|
|
@@ -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== | ||
[email protected].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" | ||
|