/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/e2e-test-utils-playwright/src/request-utils/posts.ts
66 строк
1 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 Post { id: number; content: string; status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; link: string; } export interface CreatePostPayload { title?: string; content?: string; status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; date?: string; date_gmt: string; } /** * Delete all posts using REST API. * * @param this * @param postType The type of post to delete. Defaults to 'posts'. */ export async function deleteAllPosts( this: RequestUtils, postType: string = 'posts' ) { // List all posts. // https://developer.wordpress.org/rest-api/reference/posts/#list-posts const posts = await this.rest< Post[] >( { path: `/wp/v2/${ postType }`, params: { per_page: 100, // All possible statuses. status: 'publish,future,draft,pending,private,trash', }, } ); // Delete all posts one by one. // https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post // "/wp/v2/posts" not yet supports batch requests. await Promise.all( posts.map( ( post ) => this.rest( { method: 'DELETE', path: `/wp/v2/${ postType }/${ post.id }`, params: { force: true, }, } ) ) ); } /** * Creates a new post using the REST API. * * @param this * @param payload Post attributes. */ export async function createPost( this: RequestUtils, payload: CreatePostPayload ) { return this.createRecord< Post >( 'posts', { ...payload } ); }