diff --git a/backend/package.json b/backend/package.json index 51611b3..ccd44e5 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/test/images/images.e2e-spec.ts b/backend/test/images/images.e2e-spec.ts new file mode 100644 index 0000000..8764341 --- /dev/null +++ b/backend/test/images/images.e2e-spec.ts @@ -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); + 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); + }); + }); +}); diff --git a/backend/test/images/testFile.txt b/backend/test/images/testFile.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/backend/test/images/testFile.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 806d4b0..612ab7f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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" } } diff --git a/yarn.lock b/yarn.lock index 61e7fdf..4b95495 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"