노드심화 5-10

·2022년 12월 29일
0

study

목록 보기
50/81
post-thumbnail

GET Method 통합 테스트 (Integration Test)

GET /api/posts API
=> PostsController의 getPosts Method

게시글 조회 API

게시글 조회는 빈 값을 요청(Request) 받고, 조회된 Post 데이터들을 응답(Response) 받음.

GET /api/posts API의 검증 로직

  1. API를 호출하였을 때, 성공적으로 실행할 경우 200 Http Status Code를 반환한다.
  2. API의 Response는 아무런 데이터를 삽입하지 않은 상태이므로 { data: [] }의 구조를 가진다.

게시글 조회 API 성공 케이스

test("GET /api/posts API (getPosts) Integration Test Success Case, Not Found Posts Data", async () => {
    const response = await supertest(app).get(`/api/posts`); // API의 HTTP Method & URL
    // .query({}) // Request Query String
    // .send({}); // Request Body

    // 1. API의 status가 200
    expect(response.status).toEqual(200);
    // 2. API의 res 데이터는 { data : []}
    expect(response.body).toEqual({ data: [] });
  });
profile
개발자 꿈나무

0개의 댓글