v1.12.22 관리자 멤버 댓글 목록 및 최근 댓글 확인 추가
This commit is contained in:
@@ -229,6 +229,47 @@ test('CSP 보고는 민감 URL을 제거해 같은 차원으로 집계한다', a
|
||||
expect(JSON.stringify(rows[0])).not.toContain('/private/one.js')
|
||||
})
|
||||
|
||||
test('관리자 댓글 조회는 인증·입력 검증과 멤버별 페이지·답글·댓글 수를 제공한다', async ({ request: anonymousApi }) => {
|
||||
expect((await anonymousApi.get('/admin/api/comments')).status()).toBe(401)
|
||||
for (const query of ['page=0', 'pageSize=101', 'memberId=invalid']) {
|
||||
expect((await adminApi.get(`/admin/api/comments?${query}`)).status()).toBe(400)
|
||||
}
|
||||
const [post] = await database`SELECT id, slug, title FROM posts LIMIT 1`
|
||||
const [other] = await database`
|
||||
INSERT INTO users (username, email, password_hash)
|
||||
VALUES ('댓글 테스트', 'comment-test@example.com', 'unused') RETURNING id
|
||||
`
|
||||
try {
|
||||
const [parent] = await database`
|
||||
INSERT INTO comments (post_id, user_id, body)
|
||||
VALUES (${post.id}, ${other.id}, '다른 회원 댓글') RETURNING id
|
||||
`
|
||||
await database`
|
||||
INSERT INTO comments (post_id, user_id, parent_id, body, created_at)
|
||||
VALUES (${post.id}, ${adminUser.userId}, ${parent.id}, '회원 답글', now() + interval '1 second'),
|
||||
(${post.id}, ${adminUser.userId}, NULL, '회원 댓글', now())
|
||||
`
|
||||
const first = await (await adminApi.get(`/admin/api/comments?memberId=${adminUser.userId}&pageSize=1`)).json()
|
||||
expect(first.pagination).toMatchObject({ page: 1, total: 2, pageCount: 2 })
|
||||
expect(first.items[0]).toMatchObject({ body: '회원 답글', parentId: parent.id, postId: post.id, postTitle: post.title, postSlug: post.slug })
|
||||
const second = await (await adminApi.get(`/admin/api/comments?memberId=${adminUser.userId}&pageSize=1&page=2`)).json()
|
||||
expect(second.items[0].body).toBe('회원 댓글')
|
||||
const last = await (await adminApi.get(`/admin/api/comments?memberId=${adminUser.userId}&pageSize=1&page=999`)).json()
|
||||
expect(last.pagination.page).toBe(2)
|
||||
const recent = await (await adminApi.get('/admin/api/comments?pageSize=5')).json()
|
||||
expect(recent.items[0].body).toBe('회원 답글')
|
||||
const posts = await (await adminApi.get('/admin/api/posts?paged=true')).json()
|
||||
expect(posts.items.find((item) => item.id === post.id).commentCount).toBe(3)
|
||||
await database`DELETE FROM comments WHERE post_id = ${post.id}`
|
||||
const empty = await (await adminApi.get(`/admin/api/comments?memberId=${adminUser.userId}`)).json()
|
||||
expect(empty.pagination.total).toBe(0)
|
||||
expect(empty.items).toEqual([])
|
||||
} finally {
|
||||
await database`DELETE FROM comments WHERE post_id = ${post.id}`
|
||||
await database`DELETE FROM users WHERE id = ${other.id}`
|
||||
}
|
||||
})
|
||||
|
||||
test('CSP 수집은 잘못된 형식과 32KB 초과 본문을 거부한다', async ({ request: anonymousApi }) => {
|
||||
const unsupportedResponse = await anonymousApi.post('/api/csp-report', {
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user