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

[feat] : 챗봇 기능에 대한 테스트 코드를 작성한다 #32

Merged
merged 5 commits into from
Oct 24, 2024

Conversation

bbbang105
Copy link
Contributor

@bbbang105 bbbang105 commented Oct 24, 2024

✅ PR 유형

어떤 변경 사항이 있었나요?

  • 새로운 기능 추가
  • 버그 수정
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

📝 작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

챗봇 기능 테스트 코드 작성 완료

...

// then
        resultActions
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.isSuccess").value(true))
                .andExpect(jsonPath("$.code").value("200"))
                .andExpect(jsonPath("$.message").value("가이드 챗봇 답변을 가져오는 데 성공했습니다."))
                .andExpect(jsonPath("$.payload.answers[0]").value("각 구장에 위치한 굿즈샵에서 원하는 응원 도구를 구매할 수 있어요!"))
                .andExpect(jsonPath("$.payload.imgUrl").isEmpty())

                // docs
                .andDo(MockMvcRestDocumentationWrapper.document("chatbot/guide",
                        preprocessRequest(prettyPrint()),
                        preprocessResponse(prettyPrint()),
                        resource(
                                ResourceSnippetParameters.builder()
                                        .tag("Chatbot")
                                        .description("가이드 챗봇 답변을 조회한다.")
                                        .queryParameters(
                                                parameterWithName("stadiumName").description("경기장 이름"),
                                                parameterWithName("categoryName").description("카테고리 이름"),
                                                parameterWithName("orderNumber").description("질문 번호")
                                        )
                                        .responseFields(
                                                fieldWithPath("isSuccess").type(JsonFieldType.BOOLEAN).description("성공 여부"),
                                                fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"),
                                                fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"),
                                                fieldWithPath("payload").type(JsonFieldType.OBJECT).description("응답 데이터"),
                                                fieldWithPath("payload.answers").type(JsonFieldType.ARRAY).description("답변 목록"),
                                                fieldWithPath("payload.imgUrl").type(JsonFieldType.STRING).description("이미지 URL").optional()
                                        )
                                        .responseSchema(Schema.schema("GetGuideChatbotAnswerResponse"))
                                        .build()
                        )
                ));

...
  • then에서 docs 부분을 주석으로 분리하여 가독성을 높이고자 하였습니다.
  • type(JsonFieldType.{type})로 타입을 명시하였습니다. (화면 상 차이는 없는 듯함)

배포 도메인 CORS 허용 설정

    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(Arrays.asList("http://localhost:5173", "https://git.hitzone.store"));
        configuration.setAllowedMethods(Collections.singletonList("*"));
        configuration.setAllowCredentials(true);
        configuration.setAllowedHeaders(Collections.singletonList("*"));
        configuration.setMaxAge(3600L);
        configuration.setExposedHeaders(Arrays.asList("Set-Cookie", "Authorization"));

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }
  • 배포 도메인에 대한 CORS 설정을 허용했습니다.
  • 사용되지 않는 CorsMvcConfig를 제거하였습니다.

SwaggerConfig에 배포 도메인 추가

...

@Bean
    public OpenAPI customOpenAPI() {
        OpenAPI openAPI = new OpenAPI()
                .info(new Info().title("히트존 API 문서").version("0.0.1").description("Spring REST Docs with Swagger UI."))
                .servers(List.of(
                        new Server().url("http://localhost:8080").description("로컬 서버"),
                        new Server().url("https://git.hitzone.store").description("배포 서버")
                ));


...
  • 서버를 분리하여 프론트 측에서도 사용할 수 있도록 하였습니다.
image
  • 위는 배포 서버에서도 사용 가능한 모습입니다.

✏️ 관련 이슈

본인이 작업한 내용이 어떤 Issue Number와 관련이 있는지만 작성해주세요


🎸 기타 사항 or 추가 코멘트

image

배포된 도메인으로 접속하면 위처럼 Rest Docs는 적용되지 않는 것 같습니다..
이 부분은 도커로 따로 띄워야 하는 건지 좀 더 찾아보고 해결해보겠습니다!

@bbbang105 bbbang105 added 🚀 feat 새로운 기능 추가 / 일부 코드 추가 / 일부 코드 수정 (리팩토링과 구분) / 디자인 요소 수정 🎫 rename 패키지 혹은 폴더명, 클래스명 수정 🌱 style 코드 의미에 영향을 주지 않는 변경사항 (코드 포맷팅, 오타 수정, 변수명 변경, 에셋 추가) 🤯 SANGHO 상호 Issue or PR labels Oct 24, 2024
@bbbang105 bbbang105 self-assigned this Oct 24, 2024
Copy link
Contributor

@juuuunny juuuunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고 하셨습니다!!
잘 작성된 거 같아요

.servers(List.of(
new Server().url("http://localhost:8080").description("로컬 서버"),
new Server().url("https://git.hitzone.store").description("배포 서버")
));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이렇게 서버 작성해주는 건 몰랐네요! 새롭게 알아감니다

@bbbang105 bbbang105 merged commit 942b590 into develop Oct 24, 2024
1 check passed
@bbbang105 bbbang105 deleted the feature/#31/chatbot-test-code branch October 24, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 feat 새로운 기능 추가 / 일부 코드 추가 / 일부 코드 수정 (리팩토링과 구분) / 디자인 요소 수정 🎫 rename 패키지 혹은 폴더명, 클래스명 수정 🤯 SANGHO 상호 Issue or PR 🌱 style 코드 의미에 영향을 주지 않는 변경사항 (코드 포맷팅, 오타 수정, 변수명 변경, 에셋 추가)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] : 챗봇 기능에 대한 테스트 코드를 작성한다
2 participants