게시글이 추가된 GET /api/posts API
Response에 데이터가 존재하지 않은 빈 객체를 검증하였다면,
이번에는 게시글 생성 API와 동일하게 전달받은 Response에 데이터 형식을 검증하는 성공 케이스 하나만 테스트를 진행!
=> 왜냐 이미 생성은 되어있으니까!
test("GET /api/posts API (getPosts) Integration Test Success Case, is Exist Posts Data", async () => {
const createPostBodyParams = {
nickname: "Nickname_Success",
password: "Password_Success",
title: "Title_Success",
content: "Content_Success",
};
const response = await supertest(app).get(`/api/posts`); // API의 HTTP Method & URL
// 1. API의 status가 200
expect(response.status).toEqual(200);
// 2. API의 res 데이터는 { data: [ { postId, nickname, title, createdAt, updatedAt }] }
expect(response.body).toMatchObject({
data: [
{
postId: 1,
nickname: createPostBodyParams.nickname,
title: createPostBodyParams.title,
createdAt: expect.anything(),
updatedAt: expect.anything(),
},
],
});
});