Skip to content

Commit

Permalink
Merge pull request #386 from shunny822/be/test/images-e2e
Browse files Browse the repository at this point in the history
[BE] Images e2e 테스트 작성
  • Loading branch information
shunny822 authored Feb 2, 2024
2 parents d310aba + 5fddbda commit bbe7887
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit bbe7887

Please sign in to comment.