@wordpress/e2e-test-utils-playwright
Version:
End-To-End (E2E) test utils for WordPress.
8 lines (7 loc) • 2.24 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/request-utils/blocks.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\ntype CreateBlockPayload = {\n\tdate?: string;\n\tdate_gmt?: string;\n\tslug?: string;\n\ttitle: string;\n\tstatus: 'publish' | 'future' | 'draft' | 'pending' | 'private';\n\tcontent?: string;\n\tmeta?: unknown;\n\twp_pattern_category?: number[];\n};\n\n/**\n * Delete all blocks using REST API.\n *\n * @see https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks\n * @param this\n */\nexport async function deleteAllBlocks( this: RequestUtils ) {\n\t// List all blocks.\n\t// https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks\n\tconst blocks = await this.rest( {\n\t\tpath: '/wp/v2/blocks',\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t\t// All possible statuses.\n\t\t\tstatus: 'publish,future,draft,pending,private,trash',\n\t\t},\n\t} );\n\n\t// Delete blocks.\n\t// https://developer.wordpress.org/rest-api/reference/blocks/#delete-a-editor-block\n\t// \"/wp/v2/posts\" not yet supports batch requests.\n\tawait this.batchRest(\n\t\tblocks.map( ( block: { id: number } ) => ( {\n\t\t\tmethod: 'DELETE',\n\t\t\tpath: `/wp/v2/blocks/${ block.id }?force=true`,\n\t\t} ) )\n\t);\n}\n\n/**\n * Creates a new block using the REST API.\n *\n * @see https://developer.wordpress.org/rest-api/reference/blocks/#create-a-editor-block.\n * @param this\n * @param payload Block payload.\n */\nexport async function createBlock(\n\tthis: RequestUtils,\n\tpayload: CreateBlockPayload\n) {\n\tconst block = await this.rest( {\n\t\tpath: '/wp/v2/blocks',\n\t\tmethod: 'POST',\n\t\tdata: { ...payload },\n\t} );\n\n\treturn block;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,eAAsB,kBAAsC;AAG3D,QAAM,SAAS,MAAM,KAAK,KAAM;AAAA,IAC/B,MAAM;AAAA,IACN,QAAQ;AAAA,MACP,UAAU;AAAA;AAAA,MAEV,QAAQ;AAAA,IACT;AAAA,EACD,CAAE;AAKF,QAAM,KAAK;AAAA,IACV,OAAO,IAAK,CAAE,WAA6B;AAAA,MAC1C,QAAQ;AAAA,MACR,MAAM,iBAAkB,MAAM,EAAG;AAAA,IAClC,EAAI;AAAA,EACL;AACD;AASA,eAAsB,YAErB,SACC;AACD,QAAM,QAAQ,MAAM,KAAK,KAAM;AAAA,IAC9B,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM,EAAE,GAAG,QAAQ;AAAA,EACpB,CAAE;AAEF,SAAO;AACR;",
"names": []
}