PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / api / __tests__ / wp.test.js

wp.test.js in Extendify 3.0.4, at src/Shared/api/__tests__/wp.test.js

42 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import * as wpAPI from '@shared/api/wp';
2 import apiFetch from '@wordpress/api-fetch';
3
4 jest.mock('@wordpress/api-fetch');
5
6 describe('WordPress Plugin API helpers', () => {
7 afterEach(() => {
8 jest.clearAllMocks();
9 });
10
11 it('getPlugin calls correct endpoint', async () => {
12 apiFetch.mockResolvedValueOnce([{ name: 'test-plugin' }]);
13
14 const result = await wpAPI.getPlugin('test-plugin');
15 expect(apiFetch).toHaveBeenCalledWith({
16 path: '/wp/v2/plugins?search=test-plugin',
17 });
18 expect(result).toEqual({ name: 'test-plugin' });
19 });
20
21 it('installPlugin calls correct POST endpoint', async () => {
22 apiFetch.mockResolvedValueOnce({ success: true });
23
24 const result = await wpAPI.installPlugin('my-plugin');
25 expect(apiFetch).toHaveBeenCalledWith({
26 path: '/wp/v2/plugins',
27 method: 'POST',
28 data: { slug: 'my-plugin' },
29 });
30 expect(result).toEqual({ success: true });
31 });
32
33 it('activatePlugin calls correct POST endpoint', async () => {
34 apiFetch.mockResolvedValueOnce([{ name: 'plugin-x' }]);
35 apiFetch.mockResolvedValueOnce({ activated: true });
36
37 const result = await wpAPI.activatePlugin('plugin-x');
38 expect(apiFetch).toHaveBeenCalledTimes(2);
39 expect(result).toEqual({ activated: true });
40 });
41 });
42