Mock Content
", 42 | "rendered": "Mock Content
43 | ", 44 | }, 45 | "id": 2, 46 | "link": "http://localhost:8080/hello-world/#comment-2", 47 | "meta": Array [], 48 | "parent": 0, 49 | "post": 1, 50 | "status": "approved", 51 | "type": "comment", 52 | } 53 | `; 54 | -------------------------------------------------------------------------------- /__snapshots__/comment/e2e-delete.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .comment .delete 1`] = ` 4 | Array [ 5 | Object { 6 | "deleted": true, 7 | "previous": Object { 8 | "author": 1, 9 | "author_avatar_urls": Object { 10 | "24": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=24&d=mm&r=g", 11 | "48": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=48&d=mm&r=g", 12 | "96": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=96&d=mm&r=g", 13 | }, 14 | "author_email": "admin@localhost.net", 15 | "author_name": "admin", 16 | "author_url": "http://localhost:8080", 17 | "author_user_agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", 18 | "content": Object { 19 | "raw": "Mock Content
", 20 | "rendered": "Mock Content
21 | ", 22 | }, 23 | "id": 3, 24 | "link": "http://localhost:8080/hello-world/#comment-3", 25 | "meta": Array [], 26 | "parent": 0, 27 | "post": 1, 28 | "status": "approved", 29 | "type": "comment", 30 | }, 31 | }, 32 | ] 33 | `; 34 | -------------------------------------------------------------------------------- /__snapshots__/comment/e2e-update.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .comment .update 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "author": Array [ 7 | Object { 8 | "embeddable": true, 9 | "href": "http://localhost:8080/wp-json/wp/v2/users/1", 10 | }, 11 | ], 12 | "collection": Array [ 13 | Object { 14 | "href": "http://localhost:8080/wp-json/wp/v2/comments", 15 | }, 16 | ], 17 | "self": Array [ 18 | Object { 19 | "href": "http://localhost:8080/wp-json/wp/v2/comments/6", 20 | }, 21 | ], 22 | "up": Array [ 23 | Object { 24 | "embeddable": true, 25 | "href": "http://localhost:8080/wp-json/wp/v2/posts/1", 26 | "post_type": "post", 27 | }, 28 | ], 29 | }, 30 | "author": 1, 31 | "author_avatar_urls": Object { 32 | "24": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=24&d=mm&r=g", 33 | "48": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=48&d=mm&r=g", 34 | "96": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=96&d=mm&r=g", 35 | }, 36 | "author_email": "admin@localhost.net", 37 | "author_name": "admin", 38 | "author_url": "http://localhost:8080", 39 | "author_user_agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", 40 | "content": Object { 41 | "raw": "Updated Content
", 42 | "rendered": "Updated Content
43 | ", 44 | }, 45 | "id": 6, 46 | "link": "http://localhost:8080/hello-world/#comment-6", 47 | "meta": Array [], 48 | "parent": 0, 49 | "post": 1, 50 | "status": "approved", 51 | "type": "comment", 52 | } 53 | `; 54 | -------------------------------------------------------------------------------- /__snapshots__/e2e-search.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .search 1`] = `Array []`; 4 | -------------------------------------------------------------------------------- /__snapshots__/e2e-siteSettings-find.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .siteSettings .find 1`] = ` 4 | Object { 5 | "date_format": "F j, Y", 6 | "default_category": 1, 7 | "default_comment_status": "open", 8 | "default_ping_status": "open", 9 | "default_post_format": "0", 10 | "description": "Just another WordPress site", 11 | "email": "admin@localhost.net", 12 | "language": "en_US", 13 | "page_for_posts": 0, 14 | "page_on_front": 0, 15 | "posts_per_page": 10, 16 | "show_on_front": "posts", 17 | "site_icon": 0, 18 | "site_logo": null, 19 | "start_of_week": 1, 20 | "time_format": "g:i a", 21 | "timezone": "", 22 | "title": "E2E Test - Wordpress API Client", 23 | "url": "http://localhost:8080", 24 | "use_smilies": true, 25 | } 26 | `; 27 | -------------------------------------------------------------------------------- /__snapshots__/e2e-siteSettings-update.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .siteSettings .update 1`] = ` 4 | Object { 5 | "date_format": "F j, Y", 6 | "default_category": 1, 7 | "default_comment_status": "open", 8 | "default_ping_status": "open", 9 | "default_post_format": "0", 10 | "description": "Just another WordPress site", 11 | "email": "admin@localhost.org", 12 | "language": "en_US", 13 | "page_for_posts": 0, 14 | "page_on_front": 0, 15 | "posts_per_page": 10, 16 | "show_on_front": "posts", 17 | "site_icon": 0, 18 | "site_logo": null, 19 | "start_of_week": 1, 20 | "time_format": "g:i a", 21 | "timezone": "", 22 | "title": "E2E Test - Wordpress API Client", 23 | "url": "http://localhost:8080", 24 | "use_smilies": true, 25 | } 26 | `; 27 | -------------------------------------------------------------------------------- /__snapshots__/e2e-status-authenticated.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .status authenticated 1`] = ` 4 | Object { 5 | "draft": Object { 6 | "_links": Object { 7 | "archives": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/posts?status=draft", 10 | }, 11 | ], 12 | }, 13 | "date_floating": true, 14 | "name": "Draft", 15 | "public": false, 16 | "queryable": false, 17 | "slug": "draft", 18 | }, 19 | "future": Object { 20 | "_links": Object { 21 | "archives": Array [ 22 | Object { 23 | "href": "http://localhost:8080/wp-json/wp/v2/posts?status=future", 24 | }, 25 | ], 26 | }, 27 | "date_floating": false, 28 | "name": "Scheduled", 29 | "public": false, 30 | "queryable": false, 31 | "slug": "future", 32 | }, 33 | "pending": Object { 34 | "_links": Object { 35 | "archives": Array [ 36 | Object { 37 | "href": "http://localhost:8080/wp-json/wp/v2/posts?status=pending", 38 | }, 39 | ], 40 | }, 41 | "date_floating": true, 42 | "name": "Pending", 43 | "public": false, 44 | "queryable": false, 45 | "slug": "pending", 46 | }, 47 | "private": Object { 48 | "_links": Object { 49 | "archives": Array [ 50 | Object { 51 | "href": "http://localhost:8080/wp-json/wp/v2/posts?status=private", 52 | }, 53 | ], 54 | }, 55 | "date_floating": false, 56 | "name": "Private", 57 | "public": false, 58 | "queryable": false, 59 | "slug": "private", 60 | }, 61 | "publish": Object { 62 | "_links": Object { 63 | "archives": Array [ 64 | Object { 65 | "href": "http://localhost:8080/wp-json/wp/v2/posts", 66 | }, 67 | ], 68 | }, 69 | "date_floating": false, 70 | "name": "Published", 71 | "public": true, 72 | "queryable": true, 73 | "slug": "publish", 74 | }, 75 | "trash": Object { 76 | "_links": Object { 77 | "archives": Array [ 78 | Object { 79 | "href": "http://localhost:8080/wp-json/wp/v2/posts?status=trash", 80 | }, 81 | ], 82 | }, 83 | "date_floating": false, 84 | "name": "Trash", 85 | "public": false, 86 | "queryable": false, 87 | "slug": "trash", 88 | }, 89 | } 90 | `; 91 | -------------------------------------------------------------------------------- /__snapshots__/e2e-status.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .status unauthenticated 1`] = ` 4 | Object { 5 | "publish": Object { 6 | "_links": Object { 7 | "archives": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/posts", 10 | }, 11 | ], 12 | }, 13 | "date_floating": false, 14 | "name": "Published", 15 | "public": true, 16 | "queryable": true, 17 | "slug": "publish", 18 | }, 19 | } 20 | `; 21 | -------------------------------------------------------------------------------- /__snapshots__/plugin/e2e-create.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .plugin .create 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "self": Array [ 7 | Object { 8 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/advanced-custom-fields/acf", 9 | }, 10 | ], 11 | }, 12 | "author": "WP Engine", 13 | "author_uri": "https://wpengine.com/?utm_source=wordpress.org&utm_medium=referral&utm_campaign=plugin_directory&utm_content=advanced_custom_fields", 14 | "description": Object { 15 | "raw": "Customize WordPress with powerful, professional and intuitive fields.", 16 | "rendered": "Customize WordPress with powerful, professional and intuitive fields. By WP Engine.", 17 | }, 18 | "name": "Advanced Custom Fields", 19 | "network_only": false, 20 | "plugin": "advanced-custom-fields/acf", 21 | "plugin_uri": "https://www.advancedcustomfields.com", 22 | "requires_php": "", 23 | "requires_wp": "", 24 | "status": "active", 25 | "textdomain": "acf", 26 | "version": "6.0.7", 27 | } 28 | `; 29 | -------------------------------------------------------------------------------- /__snapshots__/plugin/e2e-delete.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .plugin .delete 1`] = ` 4 | Object { 5 | "deleted": true, 6 | "previous": Object { 7 | "author": "Automattic", 8 | "author_uri": "https://automattic.com/wordpress-plugins/", 9 | "description": Object { 10 | "raw": "Used by millions, Akismet is quite possibly the best way in the world to protect your blog from spam. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.", 11 | "rendered": "Used by millions, Akismet is quite possibly the best way in the world to protect your blog from spam. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key. By Automattic.", 12 | }, 13 | "name": "Akismet Anti-Spam", 14 | "network_only": false, 15 | "plugin": "akismet/akismet", 16 | "plugin_uri": "https://akismet.com/", 17 | "requires_php": "5.2", 18 | "requires_wp": "5.0", 19 | "status": "inactive", 20 | "textdomain": "akismet", 21 | "version": "5.0.1", 22 | }, 23 | } 24 | `; 25 | -------------------------------------------------------------------------------- /__snapshots__/plugin/e2e-find_all.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .plugin .find (all) 1`] = ` 4 | Array [ 5 | Object { 6 | "_links": Object { 7 | "self": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/advanced-custom-fields/acf", 10 | }, 11 | ], 12 | }, 13 | "author": "WP Engine", 14 | "author_uri": "https://wpengine.com/?utm_source=wordpress.org&utm_medium=referral&utm_campaign=plugin_directory&utm_content=advanced_custom_fields", 15 | "description": Object { 16 | "raw": "Customize WordPress with powerful, professional and intuitive fields.", 17 | "rendered": "Customize WordPress with powerful, professional and intuitive fields. By WP Engine.", 18 | }, 19 | "name": "Advanced Custom Fields", 20 | "network_only": false, 21 | "plugin": "advanced-custom-fields/acf", 22 | "plugin_uri": "https://www.advancedcustomfields.com", 23 | "requires_php": "", 24 | "requires_wp": "", 25 | "status": "inactive", 26 | "textdomain": "acf", 27 | "version": "6.0.7", 28 | }, 29 | Object { 30 | "_links": Object { 31 | "self": Array [ 32 | Object { 33 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/hello", 34 | }, 35 | ], 36 | }, 37 | "author": "Matt Mullenweg", 38 | "author_uri": "http://ma.tt/", 39 | "description": Object { 40 | "raw": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.", 41 | "rendered": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page. By Matt Mullenweg.", 42 | }, 43 | "name": "Hello Dolly", 44 | "network_only": false, 45 | "plugin": "hello", 46 | "plugin_uri": "http://wordpress.org/plugins/hello-dolly/", 47 | "requires_php": "", 48 | "requires_wp": "", 49 | "status": "inactive", 50 | "textdomain": "", 51 | "version": "1.7.2", 52 | }, 53 | Object { 54 | "_links": Object { 55 | "self": Array [ 56 | Object { 57 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/basic-auth/basic-auth", 58 | }, 59 | ], 60 | }, 61 | "author": "WordPress API Team", 62 | "author_uri": "https://github.com/WP-API", 63 | "description": Object { 64 | "raw": "Basic Authentication handler for the JSON API, used for development and debugging purposes", 65 | "rendered": "Basic Authentication handler for the JSON API, used for development and debugging purposes By WordPress API Team.", 66 | }, 67 | "name": "JSON Basic Authentication", 68 | "network_only": false, 69 | "plugin": "basic-auth/basic-auth", 70 | "plugin_uri": "https://github.com/WP-API/Basic-Auth", 71 | "requires_php": "", 72 | "requires_wp": "", 73 | "status": "active", 74 | "textdomain": "basic-auth", 75 | "version": "0.1", 76 | }, 77 | Object { 78 | "_links": Object { 79 | "self": Array [ 80 | Object { 81 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/wp-plugin", 82 | }, 83 | ], 84 | }, 85 | "author": "Damian Kress", 86 | "author_uri": "https://www.damiankress.de/", 87 | "description": Object { 88 | "raw": "Hide date- and network-related fields from the WordPress REST API", 89 | "rendered": "Hide date- and network-related fields from the WordPress REST API By Damian Kress.", 90 | }, 91 | "name": "REST for Jest", 92 | "network_only": false, 93 | "plugin": "wp-plugin", 94 | "plugin_uri": "", 95 | "requires_php": "8.0", 96 | "requires_wp": "5.8.2", 97 | "status": "active", 98 | "textdomain": "", 99 | "version": "0.0.1", 100 | }, 101 | ] 102 | `; 103 | -------------------------------------------------------------------------------- /__snapshots__/plugin/e2e-find_one.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .plugin .find (one) 1`] = ` 4 | Array [ 5 | Object { 6 | "_links": Object { 7 | "self": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/hello", 10 | }, 11 | ], 12 | }, 13 | "author": "Matt Mullenweg", 14 | "author_uri": "http://ma.tt/", 15 | "description": Object { 16 | "raw": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.", 17 | "rendered": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page. By Matt Mullenweg.", 18 | }, 19 | "name": "Hello Dolly", 20 | "network_only": false, 21 | "plugin": "hello", 22 | "plugin_uri": "http://wordpress.org/plugins/hello-dolly/", 23 | "requires_php": "", 24 | "requires_wp": "", 25 | "status": "inactive", 26 | "textdomain": "", 27 | "version": "1.7.2", 28 | }, 29 | ] 30 | `; 31 | -------------------------------------------------------------------------------- /__snapshots__/plugin/e2e-update.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .plugin .update 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "self": Array [ 7 | Object { 8 | "href": "http://localhost:8080/wp-json/wp/v2/plugins/hello", 9 | }, 10 | ], 11 | }, 12 | "author": "Matt Mullenweg", 13 | "author_uri": "http://ma.tt/", 14 | "description": Object { 15 | "raw": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.", 16 | "rendered": "This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page. By Matt Mullenweg.", 17 | }, 18 | "name": "Hello Dolly", 19 | "network_only": false, 20 | "plugin": "hello", 21 | "plugin_uri": "http://wordpress.org/plugins/hello-dolly/", 22 | "requires_php": "", 23 | "requires_wp": "", 24 | "status": "active", 25 | "textdomain": "", 26 | "version": "1.7.2", 27 | } 28 | `; 29 | -------------------------------------------------------------------------------- /__snapshots__/taxonomy/e2e-find_all.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .taxonomy .find (all) 1`] = ` 4 | Object { 5 | "category": Object { 6 | "_links": Object { 7 | "collection": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/taxonomies", 10 | }, 11 | ], 12 | "curies": Array [ 13 | Object { 14 | "href": "https://api.w.org/{rel}", 15 | "name": "wp", 16 | "templated": true, 17 | }, 18 | ], 19 | "wp:items": Array [ 20 | Object { 21 | "href": "http://localhost:8080/wp-json/wp/v2/categories", 22 | }, 23 | ], 24 | }, 25 | "description": "", 26 | "hierarchical": true, 27 | "name": "Categories", 28 | "rest_base": "categories", 29 | "rest_namespace": "wp/v2", 30 | "slug": "category", 31 | "types": Array [ 32 | "post", 33 | ], 34 | }, 35 | "nav_menu": Object { 36 | "_links": Object { 37 | "collection": Array [ 38 | Object { 39 | "href": "http://localhost:8080/wp-json/wp/v2/taxonomies", 40 | }, 41 | ], 42 | "curies": Array [ 43 | Object { 44 | "href": "https://api.w.org/{rel}", 45 | "name": "wp", 46 | "templated": true, 47 | }, 48 | ], 49 | "wp:items": Array [ 50 | Object { 51 | "href": "http://localhost:8080/wp-json/wp/v2/menus", 52 | }, 53 | ], 54 | }, 55 | "description": "", 56 | "hierarchical": false, 57 | "name": "Navigation Menus", 58 | "rest_base": "menus", 59 | "rest_namespace": "wp/v2", 60 | "slug": "nav_menu", 61 | "types": Array [ 62 | "nav_menu_item", 63 | ], 64 | }, 65 | "post_tag": Object { 66 | "_links": Object { 67 | "collection": Array [ 68 | Object { 69 | "href": "http://localhost:8080/wp-json/wp/v2/taxonomies", 70 | }, 71 | ], 72 | "curies": Array [ 73 | Object { 74 | "href": "https://api.w.org/{rel}", 75 | "name": "wp", 76 | "templated": true, 77 | }, 78 | ], 79 | "wp:items": Array [ 80 | Object { 81 | "href": "http://localhost:8080/wp-json/wp/v2/tags", 82 | }, 83 | ], 84 | }, 85 | "description": "", 86 | "hierarchical": false, 87 | "name": "Tags", 88 | "rest_base": "tags", 89 | "rest_namespace": "wp/v2", 90 | "slug": "post_tag", 91 | "types": Array [ 92 | "post", 93 | ], 94 | }, 95 | } 96 | `; 97 | -------------------------------------------------------------------------------- /__snapshots__/taxonomy/e2e-find_one.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .taxonomy .find (one) 1`] = ` 4 | Array [ 5 | Object { 6 | "_links": Object { 7 | "collection": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/taxonomies", 10 | }, 11 | ], 12 | "curies": Array [ 13 | Object { 14 | "href": "https://api.w.org/{rel}", 15 | "name": "wp", 16 | "templated": true, 17 | }, 18 | ], 19 | "wp:items": Array [ 20 | Object { 21 | "href": "http://localhost:8080/wp-json/wp/v2/categories", 22 | }, 23 | ], 24 | }, 25 | "description": "", 26 | "hierarchical": true, 27 | "name": "Categories", 28 | "rest_base": "categories", 29 | "rest_namespace": "wp/v2", 30 | "slug": "category", 31 | "types": Array [ 32 | "post", 33 | ], 34 | }, 35 | ] 36 | `; 37 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-create.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .create 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "collection": Array [ 7 | Object { 8 | "href": "http://localhost:8080/wp-json/wp/v2/users", 9 | }, 10 | ], 11 | "self": Array [ 12 | Object { 13 | "href": "http://localhost:8080/wp-json/wp/v2/users/2", 14 | }, 15 | ], 16 | }, 17 | "avatar_urls": Object { 18 | "24": "http://2.gravatar.com/avatar/5065aac0330a46af9b5308cc9e2a4796?s=24&d=mm&r=g", 19 | "48": "http://2.gravatar.com/avatar/5065aac0330a46af9b5308cc9e2a4796?s=48&d=mm&r=g", 20 | "96": "http://2.gravatar.com/avatar/5065aac0330a46af9b5308cc9e2a4796?s=96&d=mm&r=g", 21 | }, 22 | "capabilities": Object { 23 | "level_0": true, 24 | "read": true, 25 | "subscriber": true, 26 | }, 27 | "description": "", 28 | "email": "0mock@email.com", 29 | "extra_capabilities": Object { 30 | "subscriber": true, 31 | }, 32 | "first_name": "", 33 | "id": 2, 34 | "last_name": "", 35 | "link": "http://localhost:8080/author/mockuser0/", 36 | "locale": "en_US", 37 | "meta": Object { 38 | "persisted_preferences": Array [], 39 | }, 40 | "name": "Mock Title", 41 | "nickname": "mockuser0", 42 | "roles": Array [ 43 | "subscriber", 44 | ], 45 | "slug": "mockuser0", 46 | "url": "", 47 | "username": "mockuser0", 48 | } 49 | `; 50 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-delete.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .delete 1`] = ` 4 | Array [ 5 | Object { 6 | "deleted": true, 7 | "previous": Object { 8 | "avatar_urls": Object { 9 | "24": "http://1.gravatar.com/avatar/7c981bca7cd49f8032cda228c9ec3dcc?s=24&d=mm&r=g", 10 | "48": "http://1.gravatar.com/avatar/7c981bca7cd49f8032cda228c9ec3dcc?s=48&d=mm&r=g", 11 | "96": "http://1.gravatar.com/avatar/7c981bca7cd49f8032cda228c9ec3dcc?s=96&d=mm&r=g", 12 | }, 13 | "capabilities": Object { 14 | "level_0": true, 15 | "read": true, 16 | "subscriber": true, 17 | }, 18 | "description": "", 19 | "email": "1mock@email.com", 20 | "extra_capabilities": Object { 21 | "subscriber": true, 22 | }, 23 | "first_name": "", 24 | "id": 3, 25 | "last_name": "", 26 | "link": "http://localhost:8080/author/mockuser1/", 27 | "locale": "en_US", 28 | "meta": Object { 29 | "persisted_preferences": Array [], 30 | }, 31 | "name": "Mock Title", 32 | "nickname": "mockuser1", 33 | "roles": Array [ 34 | "subscriber", 35 | ], 36 | "slug": "mockuser1", 37 | "url": "", 38 | "username": "mockuser1", 39 | }, 40 | }, 41 | ] 42 | `; 43 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-deleteMe.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .deleteMe 1`] = ` 4 | Object { 5 | "deleted": true, 6 | "previous": Object { 7 | "avatar_urls": Object { 8 | "24": "http://1.gravatar.com/avatar/738c1748074481b9c1a5fcf8de604745?s=24&d=mm&r=g", 9 | "48": "http://1.gravatar.com/avatar/738c1748074481b9c1a5fcf8de604745?s=48&d=mm&r=g", 10 | "96": "http://1.gravatar.com/avatar/738c1748074481b9c1a5fcf8de604745?s=96&d=mm&r=g", 11 | }, 12 | "capabilities": Object { 13 | "activate_plugins": true, 14 | "administrator": true, 15 | "create_users": true, 16 | "delete_others_pages": true, 17 | "delete_others_posts": true, 18 | "delete_pages": true, 19 | "delete_plugins": true, 20 | "delete_posts": true, 21 | "delete_private_pages": true, 22 | "delete_private_posts": true, 23 | "delete_published_pages": true, 24 | "delete_published_posts": true, 25 | "delete_themes": true, 26 | "delete_users": true, 27 | "edit_dashboard": true, 28 | "edit_files": true, 29 | "edit_others_pages": true, 30 | "edit_others_posts": true, 31 | "edit_pages": true, 32 | "edit_plugins": true, 33 | "edit_posts": true, 34 | "edit_private_pages": true, 35 | "edit_private_posts": true, 36 | "edit_published_pages": true, 37 | "edit_published_posts": true, 38 | "edit_theme_options": true, 39 | "edit_themes": true, 40 | "edit_users": true, 41 | "export": true, 42 | "import": true, 43 | "install_plugins": true, 44 | "install_themes": true, 45 | "level_0": true, 46 | "level_1": true, 47 | "level_10": true, 48 | "level_2": true, 49 | "level_3": true, 50 | "level_4": true, 51 | "level_5": true, 52 | "level_6": true, 53 | "level_7": true, 54 | "level_8": true, 55 | "level_9": true, 56 | "list_users": true, 57 | "manage_categories": true, 58 | "manage_links": true, 59 | "manage_options": true, 60 | "moderate_comments": true, 61 | "promote_users": true, 62 | "publish_pages": true, 63 | "publish_posts": true, 64 | "read": true, 65 | "read_private_pages": true, 66 | "read_private_posts": true, 67 | "remove_users": true, 68 | "switch_themes": true, 69 | "unfiltered_html": true, 70 | "unfiltered_upload": true, 71 | "update_core": true, 72 | "update_plugins": true, 73 | "update_themes": true, 74 | "upload_files": true, 75 | }, 76 | "description": "", 77 | "email": "2mock@email.com", 78 | "extra_capabilities": Object { 79 | "administrator": true, 80 | }, 81 | "first_name": "", 82 | "id": 4, 83 | "last_name": "", 84 | "link": "http://localhost:8080/author/mockuser2/", 85 | "locale": "en_US", 86 | "meta": Object { 87 | "persisted_preferences": Array [], 88 | }, 89 | "name": "Mock Title", 90 | "nickname": "mockuser2", 91 | "roles": Array [ 92 | "administrator", 93 | ], 94 | "slug": "mockuser2", 95 | "url": "", 96 | "username": "mockuser2", 97 | }, 98 | } 99 | `; 100 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-find_all.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .find (all) 1`] = ` 4 | Array [ 5 | Object { 6 | "_links": Object { 7 | "collection": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/users", 10 | }, 11 | ], 12 | "self": Array [ 13 | Object { 14 | "href": "http://localhost:8080/wp-json/wp/v2/users/1", 15 | }, 16 | ], 17 | }, 18 | "avatar_urls": Object { 19 | "24": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=24&d=mm&r=g", 20 | "48": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=48&d=mm&r=g", 21 | "96": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=96&d=mm&r=g", 22 | }, 23 | "description": "", 24 | "id": 1, 25 | "link": "http://localhost:8080/author/admin/", 26 | "meta": Array [], 27 | "name": "admin", 28 | "slug": "admin", 29 | "url": "http://localhost:8080", 30 | }, 31 | Object { 32 | "_links": Object { 33 | "collection": Array [ 34 | Object { 35 | "href": "http://localhost:8080/wp-json/wp/v2/users", 36 | }, 37 | ], 38 | "self": Array [ 39 | Object { 40 | "href": "http://localhost:8080/wp-json/wp/v2/users/5", 41 | }, 42 | ], 43 | }, 44 | "avatar_urls": Object { 45 | "24": "http://0.gravatar.com/avatar/9ea74214e4fda24b4e34fd7eb525c455?s=24&d=mm&r=g", 46 | "48": "http://0.gravatar.com/avatar/9ea74214e4fda24b4e34fd7eb525c455?s=48&d=mm&r=g", 47 | "96": "http://0.gravatar.com/avatar/9ea74214e4fda24b4e34fd7eb525c455?s=96&d=mm&r=g", 48 | }, 49 | "description": "", 50 | "id": 5, 51 | "link": "http://localhost:8080/author/mockuser3/", 52 | "meta": Array [], 53 | "name": "Mock Title", 54 | "slug": "mockuser3", 55 | "url": "", 56 | }, 57 | ] 58 | `; 59 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-find_me.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .find (me) 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "collection": Array [ 7 | Object { 8 | "href": "http://localhost:8080/wp-json/wp/v2/users", 9 | }, 10 | ], 11 | "self": Array [ 12 | Object { 13 | "href": "http://localhost:8080/wp-json/wp/v2/users/1", 14 | }, 15 | ], 16 | }, 17 | "avatar_urls": Object { 18 | "24": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=24&d=mm&r=g", 19 | "48": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=48&d=mm&r=g", 20 | "96": "http://2.gravatar.com/avatar/5c0689e79c6f7fc399bb1459c5709046?s=96&d=mm&r=g", 21 | }, 22 | "description": "", 23 | "id": 1, 24 | "link": "http://localhost:8080/author/admin/", 25 | "meta": Array [], 26 | "name": "admin", 27 | "slug": "admin", 28 | "url": "http://localhost:8080", 29 | } 30 | `; 31 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-find_one.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .find (one) 1`] = ` 4 | Array [ 5 | Object { 6 | "_links": Object { 7 | "collection": Array [ 8 | Object { 9 | "href": "http://localhost:8080/wp-json/wp/v2/users", 10 | }, 11 | ], 12 | "self": Array [ 13 | Object { 14 | "href": "http://localhost:8080/wp-json/wp/v2/users/6", 15 | }, 16 | ], 17 | }, 18 | "avatar_urls": Object { 19 | "24": "http://2.gravatar.com/avatar/bcf2cb8656d6aa221cb96ece43a73ccd?s=24&d=mm&r=g", 20 | "48": "http://2.gravatar.com/avatar/bcf2cb8656d6aa221cb96ece43a73ccd?s=48&d=mm&r=g", 21 | "96": "http://2.gravatar.com/avatar/bcf2cb8656d6aa221cb96ece43a73ccd?s=96&d=mm&r=g", 22 | }, 23 | "description": "", 24 | "id": 6, 25 | "link": "http://localhost:8080/author/mockuser4/", 26 | "meta": Array [], 27 | "name": "Mock Title", 28 | "slug": "mockuser4", 29 | "url": "", 30 | }, 31 | ] 32 | `; 33 | -------------------------------------------------------------------------------- /__snapshots__/user/e2e-update.snapshot: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`End-to-end test .user .update 1`] = ` 4 | Object { 5 | "_links": Object { 6 | "collection": Array [ 7 | Object { 8 | "href": "http://localhost:8080/wp-json/wp/v2/users", 9 | }, 10 | ], 11 | "self": Array [ 12 | Object { 13 | "href": "http://localhost:8080/wp-json/wp/v2/users/7", 14 | }, 15 | ], 16 | }, 17 | "avatar_urls": Object { 18 | "24": "http://2.gravatar.com/avatar/bffe87956a454372ee471b87b609a19b?s=24&d=mm&r=g", 19 | "48": "http://2.gravatar.com/avatar/bffe87956a454372ee471b87b609a19b?s=48&d=mm&r=g", 20 | "96": "http://2.gravatar.com/avatar/bffe87956a454372ee471b87b609a19b?s=96&d=mm&r=g", 21 | }, 22 | "capabilities": Object { 23 | "level_0": true, 24 | "read": true, 25 | "subscriber": true, 26 | }, 27 | "description": "", 28 | "email": "6mock@email.com", 29 | "extra_capabilities": Object { 30 | "subscriber": true, 31 | }, 32 | "first_name": "", 33 | "id": 7, 34 | "last_name": "", 35 | "link": "http://localhost:8080/author/mockuser6/", 36 | "locale": "en_US", 37 | "meta": Object { 38 | "persisted_preferences": Array [], 39 | }, 40 | "name": "Updated Title", 41 | "nickname": "mockuser6", 42 | "roles": Array [ 43 | "subscriber", 44 | ], 45 | "slug": "mockuser6", 46 | "url": "", 47 | "username": "mockuser6", 48 | } 49 | `; 50 | -------------------------------------------------------------------------------- /__tests__/e2e/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM wordpress:php8.0 2 | 3 | RUN apt-get -y update \ 4 | && apt-get -y upgrade \ 5 | && apt-get -y install default-mysql-client unzip wget \ 6 | && wget -O composer-setup.php https://getcomposer.org/installer \ 7 | && php composer-setup.php --install-dir=/usr/local/bin --filename=composer 8 | RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \ 9 | && chmod +x wp-cli.phar \ 10 | && mv ./wp-cli.phar /usr/local/bin/wp 11 | 12 | WORKDIR /usr/src/wordpress 13 | 14 | RUN composer init \ 15 | --stability 'dev' \ 16 | --name 'wordpress-api-client/e2e-test' 17 | RUN composer require "wp-api/basic-auth" \ 18 | && mv vendor/wp-api/basic-auth wp-content/plugins 19 | COPY wp-plugin.php wp-content/plugins 20 | 21 | WORKDIR /var/www/html -------------------------------------------------------------------------------- /__tests__/e2e/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | 5 | db: 6 | container_name: e2e-db 7 | image: mysql:8 8 | cap_add: 9 | - SYS_NICE # CAP_SYS_NICE 10 | platform: linux/amd64 # Apple M1 fix 11 | volumes: 12 | - ./db.sql:/docker-entrypoint-initdb.d/db.sql 13 | environment: 14 | MYSQL_DATABASE: wordpress 15 | MYSQL_PASSWORD: wordpress_db_password 16 | MYSQL_ROOT_PASSWORD: password 17 | MYSQL_USER: wordpress_db_user 18 | networks: 19 | - wpsite 20 | 21 | wordpress: 22 | container_name: e2e-wp 23 | depends_on: 24 | - db 25 | build: 26 | context: . 27 | dockerfile: Dockerfile 28 | environment: 29 | WORDPRESS_DB_HOST: db 30 | WORDPRESS_DB_NAME: wordpress 31 | WORDPRESS_DB_PASSWORD: wordpress_db_password 32 | WORDPRESS_DB_USER: wordpress_db_user 33 | WORDPRESS_DEBUG: 1 34 | WORDPRESS_CONFIG_EXTRA: | 35 | define('FORCE_SSL_ADMIN', 0); 36 | define('WP_SITEURL', 'http://localhost:8080'); 37 | ports: 38 | - "8080:80" 39 | networks: 40 | - wpsite 41 | 42 | 43 | networks: 44 | wpsite: -------------------------------------------------------------------------------- /__tests__/e2e/jpg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkress59/wordpress-api-client/640f6c73cb5da9490f69813ee010a0c24f74ab09/__tests__/e2e/jpg.jpg -------------------------------------------------------------------------------- /__tests__/e2e/png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dkress59/wordpress-api-client/640f6c73cb5da9490f69813ee010a0c24f74ab09/__tests__/e2e/png.png -------------------------------------------------------------------------------- /__tests__/e2e/spec/application-password.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import { randomUUID } from 'crypto' 4 | import fs from 'fs' 5 | import path from 'path' 6 | 7 | import WpApiClient from '../../../src' 8 | 9 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 10 | 11 | describe('End-to-end test', () => { 12 | const client = new WpApiClient('http://localhost:8080', { 13 | auth: { 14 | type: 'basic', 15 | password: 'password', 16 | username: 'admin', 17 | }, 18 | }) 19 | 20 | beforeAll(() => () => { 21 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 22 | }) 23 | 24 | describe('.applicationPassword', () => { 25 | it('.create', async () => { 26 | const appId = randomUUID() 27 | const mockAppName = 'mock-app-name' 28 | const userId = (await client.user().findMe()).id 29 | const response = await client 30 | .applicationPassword() 31 | .create(userId, appId, mockAppName) 32 | expect(response._links.self).toHaveLength(1) 33 | expect(response.name).toEqual(mockAppName) 34 | expect(response.last_used).toBeNull() 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/block-directory.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | 10 | describe('End-to-end test', () => { 11 | const client = new WpApiClient('http://localhost:8080', { 12 | auth: { 13 | type: 'basic', 14 | password: 'password', 15 | username: 'admin', 16 | }, 17 | }) 18 | 19 | beforeAll(() => () => { 20 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 21 | }) 22 | 23 | it('.blockDirectory', async () => { 24 | const response = await client.blockDirectory(' ') 25 | expect(response.some(Boolean)).toBe(true) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/block-type.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | it('.blockType', async () => { 29 | expect(await client.blockType()).toMatchSpecificSnapshot( 30 | fileName('blockType'), 31 | ) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/comment.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const mockContent = { 9 | rendered: 'Mock Content
', 10 | protected: false, 11 | } 12 | const mockUpdatedContent = { 13 | rendered: 'Updated Content
', 14 | } 15 | 16 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 17 | function fileName(name: string, dir?: string) { 18 | const pathName = path.join(snapshotPath, dir ?? '') 19 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 20 | return path.join(pathName, `e2e-${name}.snapshot`) 21 | } 22 | 23 | describe('End-to-end test', () => { 24 | const client = new WpApiClient('http://localhost:8080', { 25 | auth: { 26 | type: 'basic', 27 | password: 'password', 28 | username: 'admin', 29 | }, 30 | }) 31 | 32 | beforeAll(() => () => { 33 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 34 | }) 35 | 36 | describe('.comment', () => { 37 | let newCommentId: number | undefined 38 | 39 | afterEach(async () => { 40 | if (newCommentId) await client.comment().delete(newCommentId) 41 | newCommentId = 0 42 | }) 43 | 44 | it('.create', async () => { 45 | const response = await client.comment().create({ 46 | content: mockContent, 47 | post: 1, 48 | }) 49 | newCommentId = response?.id 50 | expect(response).toMatchSpecificSnapshot( 51 | fileName('create', 'comment'), 52 | ) 53 | }) 54 | it('.delete', async () => { 55 | const response = await client.comment().create({ 56 | content: mockContent, 57 | post: 1, 58 | }) 59 | expect( 60 | await client.comment().delete(response!.id), 61 | ).toMatchSpecificSnapshot(fileName('delete', 'comment')) 62 | }) 63 | it('.find (all)', async () => { 64 | const response = await client.comment().create({ 65 | content: mockContent, 66 | post: 1, 67 | }) 68 | newCommentId = response?.id 69 | expect(await client.comment().find()).toMatchSpecificSnapshot( 70 | fileName('find_all', 'comment'), 71 | ) 72 | }) 73 | it('.find (one)', async () => { 74 | const response = await client.comment().create({ 75 | content: mockContent, 76 | post: 1, 77 | }) 78 | newCommentId = response?.id 79 | expect( 80 | await client.comment().find(response!.id), 81 | ).toMatchSpecificSnapshot(fileName('find_one', 'comment')) 82 | }) 83 | it('.update', async () => { 84 | const response = await client.comment().create({ 85 | content: mockContent, 86 | post: 1, 87 | }) 88 | newCommentId = response?.id 89 | expect( 90 | await client.comment().update( 91 | { 92 | content: mockUpdatedContent, 93 | }, 94 | response!.id, 95 | ), 96 | ).toMatchSpecificSnapshot(fileName('update', 'comment')) 97 | }) 98 | }) 99 | }) 100 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/media.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const mockTitle = { 9 | rendered: 'Mock Title', 10 | } 11 | const mockPng = fs.readFileSync(path.resolve(__dirname, '../png.png')) 12 | const mockJpg = fs.readFileSync(path.resolve(__dirname, '../jpg.jpg')) 13 | 14 | describe('End-to-end test', () => { 15 | const client = new WpApiClient('http://localhost:8080', { 16 | auth: { 17 | type: 'basic', 18 | password: 'password', 19 | username: 'admin', 20 | }, 21 | }) 22 | 23 | describe('.media', () => { 24 | let newMediaId: number | undefined 25 | const mockFilename = 'filename.png' 26 | const mockMimeType = 'image/png' 27 | 28 | afterEach(async () => { 29 | if (newMediaId) await client.media().delete(newMediaId) 30 | newMediaId = 0 31 | }) 32 | 33 | describe('.create', () => { 34 | it('default', async () => { 35 | const response = await client 36 | .media() 37 | .create(mockFilename, mockJpg) 38 | newMediaId = response.id 39 | expect(response.title.rendered).toEqual( 40 | mockFilename.split('.')[0], 41 | ) 42 | }) 43 | it('custom mime-type', async () => { 44 | const response = await client 45 | .media() 46 | .create(mockFilename, mockPng, mockMimeType) 47 | newMediaId = response.id 48 | expect(response.media_type).toEqual(mockMimeType.split('/')[0]) 49 | }) 50 | it('with update', async () => { 51 | const mockAlText = 'mock alt-text' 52 | const response = await client 53 | .media() 54 | .create(mockFilename, mockJpg, undefined, { 55 | alt_text: mockAlText, 56 | title: mockTitle, 57 | slug: 'mock_slug', 58 | }) 59 | newMediaId = response.id 60 | expect(response.alt_text).toEqual(mockAlText) 61 | }) 62 | }) 63 | it('.delete', async () => { 64 | const response = await client.media().create(mockFilename, mockJpg) 65 | const deleted = await client.media().delete(response.id) 66 | expect(deleted[0]!.deleted).toBe(true) 67 | }) 68 | it('.find (all)', async () => { 69 | const response = await client.media().create(mockFilename, mockJpg) 70 | const response2 = await client 71 | .media() 72 | .create('2' + mockFilename, mockJpg) 73 | newMediaId = response.id 74 | expect((await client.media().find()).length > 1).toBe(true) 75 | 76 | await client.media().delete(response2.id) 77 | }) 78 | it('.find (one)', async () => { 79 | const response = await client.media().create(mockFilename, mockJpg) 80 | newMediaId = response.id 81 | expect((await client.media().find(response.id))[0]!.id).toEqual( 82 | response.id, 83 | ) 84 | }) 85 | it('.update', async () => { 86 | const created = await client.media().create(mockFilename, mockJpg) 87 | newMediaId = created.id 88 | const mockCaption = 'Mock Caption' 89 | const updated = await client 90 | .media() 91 | .update({ caption: mockCaption }, created.id) 92 | expect(updated!.caption.raw).toEqual(mockCaption) 93 | }) 94 | }) 95 | }) 96 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/page.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | const mockTitle = { 6 | rendered: 'Mock Title', 7 | } 8 | const mockContent = { 9 | rendered: 'Mock Content
', 10 | protected: false, 11 | } 12 | const mockUpdatedTitle = { rendered: 'Updated Title' } 13 | 14 | describe('End-to-end test', () => { 15 | const client = new WpApiClient('http://localhost:8080', { 16 | auth: { 17 | type: 'basic', 18 | password: 'password', 19 | username: 'admin', 20 | }, 21 | }) 22 | 23 | describe('.page', () => { 24 | let newPostId: number | undefined 25 | 26 | beforeEach(async () => { 27 | if (newPostId) await client.page().delete(newPostId) 28 | newPostId = 0 29 | }) 30 | 31 | it('.find (all)', async () => { 32 | const response = await client.page().create({ 33 | content: mockContent, 34 | title: mockTitle, 35 | status: 'publish', 36 | }) 37 | newPostId = response!.id 38 | const currentLength = (await client.page().find()).length 39 | expect(currentLength > 1).toBe(true) 40 | }) 41 | it('.find (one)', async () => { 42 | const allPages = await client.page().find() 43 | expect(await client.page().find(allPages[0]!.id)).toEqual([ 44 | allPages[0], 45 | ]) 46 | }) 47 | it('.create', async () => { 48 | const response = await client.page().create({ 49 | content: mockContent, 50 | title: mockTitle, 51 | }) 52 | newPostId = response?.id 53 | expect(response!.title).toEqual({ 54 | ...mockTitle, 55 | raw: mockTitle.rendered, 56 | }) 57 | }) 58 | it('.update', async () => { 59 | const response = await client.page().create({ 60 | content: mockContent, 61 | title: mockTitle, 62 | }) 63 | newPostId = response?.id 64 | expect( 65 | ( 66 | await client 67 | .page() 68 | .update({ title: mockUpdatedTitle }, response!.id) 69 | )?.title.raw, 70 | ).toEqual(mockUpdatedTitle.rendered) 71 | }) 72 | it('.delete', async () => { 73 | const response = await client.page().create({ 74 | content: mockContent, 75 | title: mockTitle, 76 | }) 77 | await client.page().delete(response!.id) 78 | expect(response?.title).toEqual({ 79 | ...mockTitle, 80 | raw: mockTitle.rendered, 81 | }) 82 | }) 83 | }) 84 | }) 85 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/plugin.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | describe('.plugin', () => { 29 | jest.setTimeout(30 * 1000) 30 | it('.create', async () => { 31 | const response = await client 32 | .plugin() 33 | .create('advanced-custom-fields', 'active') 34 | expect(response).toMatchSpecificSnapshot( 35 | fileName('create', 'plugin'), 36 | ) 37 | 38 | await client 39 | .plugin() 40 | .update('advanced-custom-fields/acf', 'inactive') 41 | }) 42 | it('.delete', async () => { 43 | expect( 44 | await client.plugin().delete('akismet/akismet'), 45 | ).toMatchSpecificSnapshot(fileName('delete', 'plugin')) 46 | }) 47 | it('.find (all)', async () => { 48 | expect(await client.plugin().find()).toMatchSpecificSnapshot( 49 | fileName('find_all', 'plugin'), 50 | ) 51 | }) 52 | it('.find (one)', async () => { 53 | expect(await client.plugin().find('hello')).toMatchSpecificSnapshot( 54 | fileName('find_one', 'plugin'), 55 | ) 56 | }) 57 | it('.update', async () => { 58 | expect( 59 | await client.plugin().update('hello', 'active'), 60 | ).toMatchSpecificSnapshot(fileName('update', 'plugin')) 61 | }) 62 | }) 63 | }) 64 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/post-category.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | const mockTitle = { 6 | rendered: 'Mock Title', 7 | } 8 | 9 | describe('End-to-end test', () => { 10 | const client = new WpApiClient('http://localhost:8080', { 11 | auth: { 12 | type: 'basic', 13 | password: 'password', 14 | username: 'admin', 15 | }, 16 | }) 17 | 18 | describe('.postCategory', () => { 19 | let newCategoryId: number | undefined 20 | 21 | afterEach(async () => { 22 | if (newCategoryId) await client.postCategory().delete(newCategoryId) 23 | newCategoryId = 0 24 | }) 25 | 26 | it('.create', async () => { 27 | const currentLength = (await client.postCategory().find()).length 28 | const response = await client 29 | .postCategory() 30 | .create({ name: mockTitle.rendered }) 31 | newCategoryId = response?.id 32 | expect((await client.postCategory().find()).length).toBe( 33 | currentLength + 1, 34 | ) 35 | }) 36 | it('.delete', async () => { 37 | const response = await client 38 | .postCategory() 39 | .create({ name: mockTitle.rendered }) 40 | const currentLength = (await client.postCategory().find()).length 41 | await client.postCategory().delete(response!.id) 42 | expect((await client.postCategory().find()).length).toBe( 43 | currentLength - 1, 44 | ) 45 | }) 46 | it('.find (all)', async () => { 47 | await client.postCategory().create({ name: mockTitle.rendered }) 48 | expect((await client.postCategory().find()).length > 1).toBe(true) 49 | }) 50 | it('.find (one)', async () => { 51 | const allCategories = await client.postCategory().find() 52 | expect( 53 | await client.postCategory().find(allCategories[0]!.id), 54 | ).toEqual([allCategories[0]]) 55 | }) 56 | it('.update', async () => { 57 | const mockTitle2 = 'mock-title' 58 | const mockUpdatedTitle2 = 'mock-title-2' 59 | const response = await client.postCategory().create({ 60 | name: mockTitle2, 61 | }) 62 | newCategoryId = response?.id 63 | expect( 64 | (await client.postCategory().update( 65 | { 66 | name: mockUpdatedTitle2, 67 | }, 68 | response!.id, 69 | ))!.name, 70 | ).toEqual(mockUpdatedTitle2) 71 | }) 72 | }) 73 | }) 74 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/post-tag.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | const mockTitle = { 6 | rendered: 'Mock Title', 7 | } 8 | const mockUpdatedTitle = { rendered: 'Updated Title' } 9 | 10 | describe('End-to-end test', () => { 11 | const client = new WpApiClient('http://localhost:8080', { 12 | auth: { 13 | type: 'basic', 14 | password: 'password', 15 | username: 'admin', 16 | }, 17 | }) 18 | 19 | describe('.postTag', () => { 20 | let newTagId: number | undefined 21 | 22 | beforeAll(async () => { 23 | await client.postTag().create({ 24 | name: 'Initial Tag', 25 | }) 26 | }) 27 | 28 | afterEach(async () => { 29 | if (newTagId) await client.postTag().delete(newTagId) 30 | newTagId = 0 31 | }) 32 | 33 | it('.create', async () => { 34 | const currentLength = (await client.postTag().find()).length 35 | const response = await client.postTag().create({ 36 | name: mockTitle.rendered, 37 | }) 38 | newTagId = response!.id 39 | expect((await client.postTag().find()).length).toBe( 40 | currentLength + 1, 41 | ) 42 | }) 43 | it('.delete', async () => { 44 | const response = await client.postTag().create({ 45 | name: mockTitle.rendered, 46 | }) 47 | const currentLength = (await client.postTag().find()).length 48 | await client.postTag().delete(response!.id) 49 | expect((await client.postTag().find()).length).toBe( 50 | currentLength - 1, 51 | ) 52 | }) 53 | it('.find (all)', async () => { 54 | //await client.postTag().create({ name: mockTitle.rendered }) 55 | await client.postTag().create({ name: mockTitle.rendered }) 56 | expect((await client.postTag().find()).length > 1).toBe(true) 57 | }) 58 | it('.find (one)', async () => { 59 | const allTags = await client.postTag().find() 60 | expect(await client.postTag().find(allTags[0]!.id)).toEqual([ 61 | allTags[0], 62 | ]) 63 | }) 64 | it('.update', async () => { 65 | const mockName = 'mock-name-new' 66 | const mockUpdatedName = 'mock-updated-name-new' 67 | const response = await client.postTag().create({ 68 | name: mockName, 69 | }) 70 | newTagId = response?.id 71 | expect( 72 | (await client.postTag().update( 73 | { 74 | name: mockUpdatedName, 75 | }, 76 | response!.id, 77 | ))!.name, 78 | ).toEqual(mockUpdatedName) 79 | }) 80 | }) 81 | }) 82 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/post-type.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | it('.postType', async () => { 29 | expect(await client.postType()).toMatchSpecificSnapshot( 30 | fileName('postType'), 31 | ) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/post.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | const mockTitle = { 6 | rendered: 'Mock Title', 7 | } 8 | const mockContent = { 9 | rendered: 'Mock Content
', 10 | protected: false, 11 | } 12 | const mockUpdatedTitle = { rendered: 'Updated Title' } 13 | 14 | describe('End-to-end test', () => { 15 | const client = new WpApiClient('http://localhost:8080', { 16 | auth: { 17 | type: 'basic', 18 | password: 'password', 19 | username: 'admin', 20 | }, 21 | }) 22 | 23 | describe('.post', () => { 24 | let newPostId: number | undefined 25 | 26 | beforeEach(async () => { 27 | if (newPostId) await client.post().delete(newPostId) 28 | newPostId = 0 29 | }) 30 | 31 | it('.find (all)', async () => { 32 | const response = await client.post().create({ 33 | content: mockContent, 34 | title: mockTitle, 35 | status: 'publish', 36 | }) 37 | newPostId = response!.id 38 | const currentLength = (await client.post().find()).length 39 | expect(currentLength > 1).toBe(true) 40 | }) 41 | it('.find (one)', async () => { 42 | const allPosts = await client.post().find() 43 | expect(await client.post().find(allPosts[0]!.id)).toEqual([ 44 | allPosts[0], 45 | ]) 46 | }) 47 | it('.create', async () => { 48 | const response = await client.post().create({ 49 | content: mockContent, 50 | title: mockTitle, 51 | }) 52 | newPostId = response!.id 53 | expect(response?.title).toEqual({ 54 | ...mockTitle, 55 | raw: mockTitle.rendered, 56 | }) 57 | }) 58 | it('.update', async () => { 59 | const response = await client.post().create({ 60 | content: mockContent, 61 | title: mockTitle, 62 | }) 63 | newPostId = response?.id 64 | expect( 65 | ( 66 | await client 67 | .post() 68 | .update({ title: mockUpdatedTitle }, response!.id) 69 | )?.title.raw, 70 | ).toEqual(mockUpdatedTitle.rendered) 71 | }) 72 | it('.delete', async () => { 73 | const response = await client.post().create({ 74 | content: mockContent, 75 | title: mockTitle, 76 | }) 77 | await client.post().delete(response!.id) 78 | expect(response?.title).toEqual({ 79 | ...mockTitle, 80 | raw: mockTitle.rendered, 81 | }) 82 | }) 83 | }) 84 | }) 85 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/rendered-block.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | // eslint-disable-next-line jest/no-disabled-tests 29 | it.skip('.renderedBlock', async () => { 30 | // ToDo: Find out what .renderedBlock actually is supposed to do 31 | expect( 32 | await client.renderedBlock({ 33 | name: 'mock-rendered-block', 34 | postId: 1, 35 | }), 36 | ).toMatchSpecificSnapshot(fileName('renderedBlock')) 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/reusable-block.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | const mockTitle = { 6 | rendered: 'Mock Title', 7 | } 8 | const mockContent = { 9 | rendered: 'Mock Content
', 10 | protected: false, 11 | } 12 | const mockUpdatedTitle = { rendered: 'Updated Title' } 13 | const mockRawContent = { raw: mockContent.rendered, protected: false } 14 | const mockRawTitle = { raw: mockTitle.rendered, protected: false } 15 | 16 | describe('End-to-end test', () => { 17 | const client = new WpApiClient('http://localhost:8080', { 18 | auth: { 19 | type: 'basic', 20 | password: 'password', 21 | username: 'admin', 22 | }, 23 | }) 24 | 25 | describe('.reusableBlock', () => { 26 | let newBlockId = 0 27 | 28 | beforeEach(async () => { 29 | const response = await client.reusableBlock().create({ 30 | content: mockRawContent, 31 | title: mockRawTitle, 32 | status: 'publish', 33 | }) 34 | newBlockId = response!.id 35 | }) 36 | 37 | afterEach(async () => { 38 | if (newBlockId) await client.reusableBlock().delete(newBlockId) 39 | newBlockId = 0 40 | }) 41 | 42 | it('.find (all)', async () => { 43 | const response = await client.reusableBlock().create({ 44 | content: mockRawContent, 45 | title: mockRawTitle, 46 | status: 'publish', 47 | }) 48 | const response2 = await client.reusableBlock().create({ 49 | content: mockRawContent, 50 | title: mockRawTitle, 51 | status: 'publish', 52 | }) 53 | expect((await client.reusableBlock().find()).length > 1).toBe(true) 54 | 55 | await client.reusableBlock().delete(response!.id) 56 | await client.reusableBlock().delete(response2!.id) 57 | }) 58 | it('.find (one)', async () => { 59 | const response = await client.reusableBlock().create({ 60 | content: mockRawContent, 61 | title: mockRawTitle, 62 | status: 'publish', 63 | }) 64 | newBlockId = response!.id 65 | expect( 66 | (await client.reusableBlock().find(newBlockId))[0]!.slug, 67 | ).toEqual(response!.slug) 68 | }) 69 | it('.create', async () => { 70 | const response = await client.reusableBlock().create({ 71 | content: mockRawContent, 72 | title: mockRawTitle, 73 | status: 'publish', 74 | }) 75 | newBlockId = response!.id 76 | expect(response?.title.raw).toEqual(mockRawTitle.raw) 77 | }) 78 | it('.update', async () => { 79 | const response = await client.reusableBlock().create({ 80 | content: mockRawContent, 81 | title: mockRawTitle, 82 | status: 'publish', 83 | }) 84 | newBlockId = response!.id 85 | expect( 86 | (await client 87 | .reusableBlock() 88 | .update( 89 | { title: { raw: mockUpdatedTitle.rendered } }, 90 | newBlockId, 91 | ))!.title, 92 | ).toEqual({ 93 | raw: mockUpdatedTitle.rendered, 94 | }) 95 | }) 96 | it('.delete', async () => { 97 | const response = await client.reusableBlock().create({ 98 | content: mockRawContent, 99 | title: mockRawTitle, 100 | status: 'publish', 101 | }) 102 | expect( 103 | (await client.reusableBlock().delete(response!.id))[0]!.id, 104 | ).toEqual(response!.id) 105 | }) 106 | }) 107 | }) 108 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/search.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | it('.search', async () => { 29 | expect( 30 | await client.search('mock', { per_page: '2' }), 31 | ).toMatchSpecificSnapshot(fileName('search')) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/site-settings.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | describe('.siteSettings', () => { 29 | it('.find', async () => { 30 | expect(await client.siteSettings().find()).toMatchSpecificSnapshot( 31 | fileName('siteSettings-find'), 32 | ) 33 | }) 34 | it('.update', async () => { 35 | expect( 36 | await client 37 | .siteSettings() 38 | .update({ email: 'admin@localhost.org' }), 39 | ).toMatchSpecificSnapshot(fileName('siteSettings-update')) 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/status.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | const noAuthClient = new WpApiClient('http://localhost:8080') 24 | 25 | beforeAll(() => () => { 26 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 27 | }) 28 | 29 | describe('.status', () => { 30 | it('unauthenticated', async () => { 31 | expect(await noAuthClient.status()).toMatchSpecificSnapshot( 32 | fileName('status'), 33 | ) 34 | }) 35 | it('authenticated', async () => { 36 | expect(await client.status()).toMatchSpecificSnapshot( 37 | fileName('status-authenticated'), 38 | ) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/taxonomy.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 9 | function fileName(name: string, dir?: string) { 10 | const pathName = path.join(snapshotPath, dir ?? '') 11 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 12 | return path.join(pathName, `e2e-${name}.snapshot`) 13 | } 14 | 15 | describe('End-to-end test', () => { 16 | const client = new WpApiClient('http://localhost:8080', { 17 | auth: { 18 | type: 'basic', 19 | password: 'password', 20 | username: 'admin', 21 | }, 22 | }) 23 | 24 | beforeAll(() => () => { 25 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 26 | }) 27 | 28 | describe('.taxonomy', () => { 29 | it('.find (all)', async () => { 30 | expect(await client.taxonomy()).toMatchSpecificSnapshot( 31 | fileName('find_all', 'taxonomy'), 32 | ) 33 | }) 34 | it('.find (one)', async () => { 35 | expect(await client.taxonomy('category')).toMatchSpecificSnapshot( 36 | fileName('find_one', 'taxonomy'), 37 | ) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/theme.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import WpApiClient from '../../../src' 4 | 5 | describe('End-to-end test', () => { 6 | const client = new WpApiClient('http://localhost:8080', { 7 | auth: { 8 | type: 'basic', 9 | password: 'password', 10 | username: 'admin', 11 | }, 12 | }) 13 | 14 | it('.theme', async () => { 15 | expect( 16 | (await client.theme()).filter( 17 | theme => theme.textdomain === 'twentytwentyone', 18 | ), 19 | ).toHaveLength(1) 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /__tests__/e2e/spec/user.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import 'jest-specific-snapshot' 2 | 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | import WpApiClient from '../../../src' 7 | 8 | const mockTitle = { 9 | rendered: 'Mock Title', 10 | } 11 | const mockUpdatedTitle = { rendered: 'Updated Title' } 12 | 13 | const snapshotPath = path.resolve(process.cwd(), './__snapshots__') 14 | function fileName(name: string, dir?: string) { 15 | const pathName = path.join(snapshotPath, dir ?? '') 16 | if (dir && !fs.existsSync(pathName)) fs.mkdirSync(pathName) 17 | return path.join(pathName, `e2e-${name}.snapshot`) 18 | } 19 | 20 | describe('End-to-end test', () => { 21 | const client = new WpApiClient('http://localhost:8080', { 22 | auth: { 23 | type: 'basic', 24 | password: 'password', 25 | username: 'admin', 26 | }, 27 | }) 28 | 29 | beforeAll(() => () => { 30 | if (!fs.existsSync(snapshotPath)) fs.mkdirSync(snapshotPath) 31 | }) 32 | 33 | describe('.user', () => { 34 | let i = 0 35 | let newUserId = 0 36 | const mockUsername = 'mockuser' 37 | const mockEmail = 'mock@email.com' 38 | const mockPassword = 'Mock_Password1' 39 | 40 | afterEach(async () => { 41 | i++ 42 | if (newUserId) await client.user().delete(1, newUserId) 43 | newUserId = 0 44 | }) 45 | 46 | it('.create', async () => { 47 | const response = await client.user().create({ 48 | email: String(i) + mockEmail, 49 | name: mockTitle.rendered, 50 | password: mockPassword, 51 | username: mockUsername + String(i), 52 | }) 53 | newUserId = response!.id 54 | expect(response).toMatchSpecificSnapshot(fileName('create', 'user')) 55 | }) 56 | it('.delete', async () => { 57 | const response = await client.user().create({ 58 | email: String(i) + mockEmail, 59 | name: mockTitle.rendered, 60 | password: mockPassword, 61 | username: mockUsername + String(i), 62 | }) 63 | expect( 64 | await client.user().delete(1, response!.id), 65 | ).toMatchSpecificSnapshot(fileName('delete', 'user')) 66 | }) 67 | it('.deleteMe', async () => { 68 | const password = mockPassword 69 | const username = mockUsername + String(i) 70 | await client.user().create({ 71 | name: mockTitle.rendered, 72 | email: String(i) + mockEmail, 73 | password, 74 | username, 75 | roles: ['administrator'], 76 | }) 77 | const newClient = new WpApiClient('http://localhost:8080', { 78 | auth: { type: 'basic', username, password }, 79 | }) 80 | expect(await newClient.user().deleteMe(1)).toMatchSpecificSnapshot( 81 | fileName('deleteMe', 'user'), 82 | ) 83 | }) 84 | it('.find (all)', async () => { 85 | const response = await client.user().create({ 86 | email: String(i) + mockEmail, 87 | name: mockTitle.rendered, 88 | password: mockPassword, 89 | username: mockUsername + String(i), 90 | }) 91 | newUserId = response!.id 92 | expect(await client.user().find()).toMatchSpecificSnapshot( 93 | fileName('find_all', 'user'), 94 | ) 95 | }) 96 | it('.find (one)', async () => { 97 | const response = await client.user().create({ 98 | email: String(i) + mockEmail, 99 | name: mockTitle.rendered, 100 | password: mockPassword, 101 | username: mockUsername + String(i), 102 | }) 103 | newUserId = response!.id 104 | expect(await client.user().find(newUserId)).toMatchSpecificSnapshot( 105 | fileName('find_one', 'user'), 106 | ) 107 | }) 108 | it('.find (me)', async () => { 109 | expect(await client.user().findMe()).toMatchSpecificSnapshot( 110 | fileName('find_me', 'user'), 111 | ) 112 | }) 113 | it('.update', async () => { 114 | const response = await client.user().create({ 115 | name: mockTitle.rendered, 116 | email: String(i) + mockEmail, 117 | password: mockPassword, 118 | username: mockUsername + String(i), 119 | }) 120 | newUserId = response!.id 121 | expect( 122 | await client.user().update( 123 | { 124 | name: mockUpdatedTitle.rendered, 125 | password: mockPassword, 126 | }, 127 | newUserId, 128 | ), 129 | ).toMatchSpecificSnapshot(fileName('update', 'user')) 130 | }) 131 | }) 132 | }) 133 | -------------------------------------------------------------------------------- /__tests__/e2e/wait-for-db-import.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CONTAINER="e2e-db" 4 | DB="wordpress" 5 | 6 | sleep 3 7 | while ! docker exec $CONTAINER /bin/sh -c "mysqladmin --protocol=tcp ping -ppassword >/dev/null 2>&1"; do 8 | echo "testing connection..." 9 | sleep 1 10 | done 11 | 12 | #docker cp __tests__/e2e/db.sql $CONTAINER:/ 13 | #docker exec $CONTAINER /bin/sh -c "mysql --protocol=tcp -uroot -ppassword $DB < /db.sql" -------------------------------------------------------------------------------- /__tests__/e2e/wp-plugin.php: -------------------------------------------------------------------------------- 1 | data; 31 | 32 | if (isset($_data['author_ip'])) { 33 | unset($_data['author_ip']); 34 | } 35 | if (isset($_data['date'])) { 36 | unset($_data['date']); 37 | unset($_data['date_gmt']); 38 | unset($_data['modified']); 39 | unset($_data['modified_gmt']); 40 | } 41 | if (isset($_data['registered_date'])) { 42 | unset($_data['registered_date']); 43 | } 44 | $data->data = $_data; 45 | 46 | return $data; 47 | } -------------------------------------------------------------------------------- /__tests__/factories/category.factory.ts: -------------------------------------------------------------------------------- 1 | import { FixtureFactory } from 'interface-forge' 2 | import path from 'path' 3 | import { WP_Taxonomy_Name } from 'wp-types' 4 | 5 | import { WPCategory } from '../../src/types' 6 | import { fakeNumber, fakeTaxonomy } from '../util' 7 | 8 | const fixtureDir = path.resolve(__dirname, '..', '..') 9 | 10 | export const WPCategoryFactory = new FixtureFactory${faker.lorem.paragraph()}
` } 31 | export const fakeObjectLink = () => ({ 32 | href: fakeUrl(), 33 | id: fakeNumber(), 34 | }) 35 | export const fakeBase = () => ({ 36 | _links: WPObjectLinksFactory, 37 | acf: undefined, 38 | id: fakeNumber(), 39 | link: fakeUrl(), 40 | meta: [], 41 | slug: randomWords().replace(' ', '-').toLowerCase(), 42 | }) 43 | export const fakeTaxonomy = () => ({ 44 | ...fakeBase(), 45 | count: fakeNumber(12), 46 | description: fakeSentence(), 47 | name: randomWords(), 48 | }) 49 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | import { ForegroundColor } from 'chalk' 2 | // eslint-disable-next-line jest/no-jest-import 3 | import jest from 'jest' 4 | 5 | const coveragePathIgnorePatterns = [ 6 | '__tests__', 7 | '.yarn', 8 | '.factory.ts', 9 | '.spec.ts', 10 | ] 11 | 12 | function createProject( 13 | name: string, 14 | color: ForegroundColor, 15 | testMatch: string[], 16 | ): jest.Config { 17 | return { 18 | cacheDirectory: '.jest/cache', 19 | clearMocks: true, 20 | coveragePathIgnorePatterns, 21 | displayName: { 22 | color, 23 | name, 24 | }, 25 | preset: 'ts-jest', 26 | testMatch, 27 | } 28 | } 29 | 30 | const jestConfig: jest.Config = { 31 | collectCoverage: true, 32 | coverageProvider: 'v8', 33 | preset: 'ts-jest', 34 | projects: [ 35 | createProject('core', 'gray', ['**/__tests__/**/*.spec.[jt]s']), 36 | createProject('e2e', 'green', ['**/__tests__/**/*.e2e-spec.[jt]s']), 37 | ], 38 | testMatch: ['**/__tests__/**/*.(e2e-spec|spec).[jt]s'], 39 | verbose: true, 40 | } 41 | 42 | export default jestConfig 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wordpress-api-client", 3 | "description": "WordPress-API Client for JS/TS", 4 | "version": "0.4.9", 5 | "author": "dkress59", 6 | "bugs": "https://github.com/dkress59/wordpress-api-client/issues", 7 | "license": "MIT", 8 | "main": "./dist/index.js", 9 | "repository": "https://github.com/dkress59/wordpress-api-client", 10 | "scripts": { 11 | "build": "tsc -p tsconfig.build.json", 12 | "check:script": "eslint src --ext .ts --fix-dry-run --report-unused-disable-directives", 13 | "lint:script": "eslint src --ext .ts --fix", 14 | "test": "jest --selectProjects core", 15 | "test:e2e": "jest --selectProjects e2e --runInBand", 16 | "test:watch": "jest --selectProjects core --watchAll", 17 | "doctor": "yarn dlx @yarnpkg/doctor", 18 | "docker": "docker compose -f __tests__/e2e/docker-compose.yml up -d", 19 | "docker:build": "docker compose -f __tests__/e2e/docker-compose.yml build --no-cache --pull", 20 | "docker:down": "docker compose -f __tests__/e2e/docker-compose.yml down --volumes", 21 | "postinstall": "husky install", 22 | "prepack": "yarn pinst --disable", 23 | "postpack": "yarn pinst --enable" 24 | }, 25 | "types": "./dist/index.d.ts", 26 | "contributors": [ 27 | { 28 | "name": "Damian Kress", 29 | "email": "wordpress@damiankress.de" 30 | } 31 | ], 32 | "dependencies": { 33 | "@tool-belt/type-predicates": "1.2.2", 34 | "cross-fetch": "3.1.5", 35 | "wp-types": "3.61.0" 36 | }, 37 | "devDependencies": { 38 | "@tool-belt/eslint-config": "1.5.1", 39 | "@types/eslint": "8.21.0", 40 | "@types/faker": "5.5.9", 41 | "@types/jest": "28.1.8", 42 | "@types/jest-specific-snapshot": "0.5.6", 43 | "@types/node": "16.18.12", 44 | "@types/source-map-support": "0.5.6", 45 | "@typescript-eslint/eslint-plugin": "5.51.0", 46 | "@typescript-eslint/parser": "5.51.0", 47 | "chalk": "5.2.0", 48 | "eslint": "8.33.0", 49 | "eslint-config-prettier": "8.6.0", 50 | "eslint-import-resolver-typescript": "2.7.1", 51 | "eslint-plugin-eslint-comments": "3.2.0", 52 | "eslint-plugin-import": "2.27.5", 53 | "eslint-plugin-jest": "26.9.0", 54 | "eslint-plugin-prettier": "4.2.1", 55 | "eslint-plugin-simple-import-sort": "7.0.0", 56 | "eslint-plugin-sonarjs": "0.14.0", 57 | "eslint-plugin-unused-imports": "2.0.0", 58 | "faker": "5.5.3", 59 | "husky": "8.0.3", 60 | "interface-forge": "1.5.1", 61 | "jest": "28.1.3", 62 | "jest-specific-snapshot": "5.0.0", 63 | "pinst": "3.0.0", 64 | "prettier": "2.8.4", 65 | "source-map-support": "0.5.21", 66 | "ts-jest": "28.0.8", 67 | "ts-node": "10.9.1", 68 | "typescript": "4.9.5" 69 | }, 70 | "engines": { 71 | "node": "14.17.0 || >=16.0.0" 72 | }, 73 | "keywords": [ 74 | "typescript", 75 | "wordpress", 76 | "headless", 77 | "nodejs", 78 | "REST", 79 | "api client", 80 | "wpapi", 81 | "wp-api", 82 | "wp-json", 83 | "json", 84 | "js", 85 | "ts", 86 | "wp" 87 | ], 88 | "packageManager": "yarn@3.4.1" 89 | } 90 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=dkress59_wordpress-api-client 2 | sonar.organization=dkress59 3 | 4 | # This is the name and version displayed in the SonarCloud UI. 5 | #sonar.projectName=wordpress-api-client 6 | #sonar.projectVersion=1.0 7 | 8 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 9 | sonar.sources=src 10 | sonar.test.inclusions=__tests__/*.spec.* 11 | 12 | sonar.javascript.lcov.reportPaths=coverage/lcov.info 13 | 14 | # Encoding of the source code. Default is default system encoding 15 | sonar.sourceEncoding=UTF-8 -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | import { WP_Post_Status_Name, WP_Post_Type_Name } from 'wp-types' 2 | 3 | export const END_POINT = { 4 | BLOCK_DIRECTORY: 'wp/v2/block-directory/search', 5 | BLOCK_RENDERER: 'wp/v2/block-renderer', 6 | BLOCK_TYPES: 'wp/v2/block-types', 7 | CATEGORIES: 'wp/v2/categories', 8 | COMMENTS: 'wp/v2/comments', 9 | EDITOR_BLOCKS: 'wp/v2/blocks', 10 | MEDIA: 'wp/v2/media', 11 | PAGES: 'wp/v2/pages', 12 | PLUGINS: 'wp/v2/plugins', 13 | POSTS: 'wp/v2/posts', 14 | SEARCH: 'wp/v2/search', 15 | SETTINGS: 'wp/v2/settings', 16 | STATUSES: 'wp/v2/statuses', 17 | TAGS: 'wp/v2/tags', 18 | TAXONOMIES: 'wp/v2/taxonomies', 19 | THEMES: 'wp/v2/themes', 20 | TYPES: 'wp/v2/types', 21 | USER_APPLICATION_PASSWORDS: 'application-passwords', 22 | USERS_ME: 'wp/v2/users/me', 23 | USERS: 'wp/v2/users', 24 | } 25 | 26 | export const ERROR_MESSAGE = { 27 | DETAILED: '[WpApiClient Error] %error%', 28 | ERROR_RESPONSE: 29 | '[WpApiClient Error] There was an error when calling the end point %url%: %error% (%status%)', 30 | GENERIC: '[WpApiClient Error] Misconfiguration?', 31 | ID_REQUIRED: 32 | '[WpApiClient Error] At least one ID must be provided to .delete()', 33 | INVALID_BASEURL: '[WpApiClient Error] Invalid baseUrl: %url%', 34 | INVALID_FILENAME: 35 | '[WpApiClient Error] The fileName must include the file extension (e.g.: %fileName%.jpg).', 36 | MISSING_REQUIRED_PARAM: 37 | '[WpApiClient Error] Required param %PARAM% missing.', 38 | } 39 | 40 | export const END_POINT_PROTECTED = { 41 | GET: [ 42 | END_POINT.BLOCK_DIRECTORY, 43 | END_POINT.BLOCK_TYPES, 44 | END_POINT.EDITOR_BLOCKS, 45 | END_POINT.PLUGINS, 46 | END_POINT.SETTINGS, 47 | END_POINT.THEMES, 48 | END_POINT.USER_APPLICATION_PASSWORDS, 49 | END_POINT.USERS, 50 | END_POINT.USERS_ME, 51 | ], 52 | POST: Object.values(END_POINT), 53 | DELETE: Object.values(END_POINT), 54 | } 55 | 56 | export const TRASHABLE = [ 57 | END_POINT.EDITOR_BLOCKS, 58 | END_POINT.PAGES, 59 | END_POINT.POSTS, 60 | ] 61 | 62 | export const END_POINT_PUBLIC = { 63 | GET: Object.values(END_POINT).filter( 64 | endPoint => !END_POINT_PROTECTED.GET.includes(endPoint), 65 | ), 66 | POST: Object.values(END_POINT).filter( 67 | endPoint => !END_POINT_PROTECTED.POST.includes(endPoint), 68 | ), 69 | DELETE: Object.values(END_POINT).filter( 70 | endPoint => !END_POINT_PROTECTED.DELETE.includes(endPoint), 71 | ), 72 | } 73 | 74 | export const POST_STATUS_MAP = [ 75 | WP_Post_Status_Name.auto_draft, 76 | WP_Post_Status_Name.draft, 77 | WP_Post_Status_Name.future, 78 | WP_Post_Status_Name.inherit, 79 | WP_Post_Status_Name.pending, 80 | WP_Post_Status_Name.private, 81 | WP_Post_Status_Name.publish, 82 | WP_Post_Status_Name.trash, 83 | ] 84 | 85 | export const POST_TYPE_MAP = [ 86 | WP_Post_Type_Name.attachment, 87 | WP_Post_Type_Name.custom_css, 88 | WP_Post_Type_Name.customize_changeset, 89 | WP_Post_Type_Name.nav_menu_item, 90 | WP_Post_Type_Name.oembed_cache, 91 | WP_Post_Type_Name.page, 92 | WP_Post_Type_Name.post, 93 | WP_Post_Type_Name.revision, 94 | WP_Post_Type_Name.user_request, 95 | WP_Post_Type_Name.wp_block, 96 | ] 97 | -------------------------------------------------------------------------------- /src/fetch-client.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'cross-fetch' 2 | 3 | import { END_POINT_PROTECTED, END_POINT_PUBLIC } from './constants' 4 | import { AUTH_TYPE } from './types' 5 | import { getErrorMessage, useAuth, validateBaseUrl } from './util' 6 | 7 | export class FetchClient { 8 | baseUrl: string 9 | headers: Record