@wordpress/e2e-test-utils-playwright
Version:
End-To-End (E2E) test utils for WordPress.
8 lines (7 loc) • 2.42 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/request-utils/posts.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\nexport interface Post {\n\tid: number;\n\tcontent: string;\n\tstatus: 'publish' | 'future' | 'draft' | 'pending' | 'private';\n\tlink: string;\n}\n\nexport interface CreatePostPayload {\n\ttitle?: string;\n\tcontent?: string;\n\tstatus: 'publish' | 'future' | 'draft' | 'pending' | 'private';\n\tdate?: string;\n\tdate_gmt: string;\n}\n\n/**\n * Delete all posts using REST API.\n *\n * @param this\n * @param postType The type of post to delete. Defaults to 'posts'.\n */\nexport async function deleteAllPosts(\n\tthis: RequestUtils,\n\tpostType: string = 'posts'\n) {\n\t// List all posts.\n\t// https://developer.wordpress.org/rest-api/reference/posts/#list-posts\n\tconst posts = await this.rest< Post[] >( {\n\t\tpath: `/wp/v2/${ postType }`,\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 all posts one by one.\n\t// https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post\n\t// \"/wp/v2/posts\" not yet supports batch requests.\n\tawait Promise.all(\n\t\tposts.map( ( post ) =>\n\t\t\tthis.rest( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\tpath: `/wp/v2/${ postType }/${ post.id }`,\n\t\t\t\tparams: {\n\t\t\t\t\tforce: true,\n\t\t\t\t},\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Creates a new post using the REST API.\n *\n * @param this\n * @param payload Post attributes.\n */\nexport async function createPost(\n\tthis: RequestUtils,\n\tpayload: CreatePostPayload\n) {\n\tconst post = await this.rest< Post >( {\n\t\tmethod: 'POST',\n\t\tpath: `/wp/v2/posts`,\n\t\tdata: { ...payload },\n\t} );\n\n\treturn post;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,eAAsB,eAErB,WAAmB,SAClB;AAGD,QAAM,QAAQ,MAAM,KAAK,KAAgB;AAAA,IACxC,MAAM,UAAW,QAAS;AAAA,IAC1B,QAAQ;AAAA,MACP,UAAU;AAAA;AAAA,MAEV,QAAQ;AAAA,IACT;AAAA,EACD,CAAE;AAKF,QAAM,QAAQ;AAAA,IACb,MAAM;AAAA,MAAK,CAAE,SACZ,KAAK,KAAM;AAAA,QACV,QAAQ;AAAA,QACR,MAAM,UAAW,QAAS,IAAK,KAAK,EAAG;AAAA,QACvC,QAAQ;AAAA,UACP,OAAO;AAAA,QACR;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AACD;AAQA,eAAsB,WAErB,SACC;AACD,QAAM,OAAO,MAAM,KAAK,KAAc;AAAA,IACrC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM,EAAE,GAAG,QAAQ;AAAA,EACpB,CAAE;AAEF,SAAO;AACR;",
"names": []
}