/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/e2e-test-utils-playwright/src/request-utils/comments.ts
77 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { RequestUtils } from './index'; export interface Comment { id: number; author: number; content: string; post: number; } export interface CreateCommentPayload { content: string; post: number; } export interface User { id: number; } /** * Create new comment using the REST API. * * @param this * @param payload */ export async function createComment( this: RequestUtils, payload: CreateCommentPayload ) { const currentUser = await this.rest< User >( { path: '/wp/v2/users/me', method: 'GET', } ); const author = currentUser.id; const comment = await this.rest< Comment >( { method: 'POST', path: '/wp/v2/comments', data: { ...payload, author }, } ); return comment; } /** * Delete all comments using the REST API. * * @param this * @param type - Optional comment type to delete. */ export async function deleteAllComments( this: RequestUtils, type?: string ) { // List all comments. // https://developer.wordpress.org/rest-api/reference/comments/#list-comments const comments = await this.rest( { path: '/wp/v2/comments', params: { per_page: 100, status: 'all', type: type || 'comment', }, } ); // Delete all comments one by one. // https://developer.wordpress.org/rest-api/reference/comments/#delete-a-comment // "/wp/v2/comments" doesn't support batch requests yet. await Promise.all( comments.map( ( comment: Comment ) => this.rest( { method: 'DELETE', path: `/wp/v2/comments/${ comment.id }`, params: { force: true, }, } ) ) ); }