PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
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 / AutoLaunch / functions / __tests__ / plugins.test.js

plugins.test.js in Extendify 3.1.0, at src/AutoLaunch/functions/__tests__/plugins.test.js

51 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2
3 jest.mock('@wordpress/api-fetch');
4 jest.mock('@shared/api/DataApi', () => ({ recordPluginActivity: jest.fn() }));
5 jest.mock('@shared/api/wp', () => ({ enableAutoUpdate: jest.fn() }));
6
7 const { activatePlugin } = require('@auto-launch/functions/plugins');
8
9 describe('activatePlugin', () => {
10 beforeEach(() => {
11 apiFetch.mockReset();
12 });
13
14 // Regression: when a required plugin 500s during install it never lands on
15 // disk, so the activate retry's getPlugin lookup comes back empty. The old
16 // code destructured `{ plugin }` off that undefined and threw a TypeError
17 // out of the catch as an unhandled rejection, aborting the install loop.
18 it('resolves without throwing when the plugin is not installed', async () => {
19 apiFetch.mockImplementation((opts) =>
20 opts.method === 'POST'
21 ? Promise.reject(new Error('500'))
22 : Promise.resolve([]),
23 );
24
25 await expect(activatePlugin('jetbackup')).resolves.toBeUndefined();
26 expect(console).toHaveWarned();
27 expect(console).toHaveErrored();
28 });
29
30 it('retries activation against the resolved plugin path when found', async () => {
31 apiFetch.mockImplementation((opts) => {
32 if (opts.method !== 'POST') {
33 return Promise.resolve([{ plugin: 'jetbackup/jetbackup.php' }]);
34 }
35 // The bare-slug attempt fails; the resolved-path retry succeeds.
36 return opts.path === '/wp/v2/plugins/jetbackup'
37 ? Promise.reject(new Error('400'))
38 : Promise.resolve();
39 });
40
41 await expect(activatePlugin('jetbackup')).resolves.toBeUndefined();
42 expect(apiFetch).toHaveBeenCalledWith(
43 expect.objectContaining({
44 path: '/wp/v2/plugins/jetbackup/jetbackup.php',
45 method: 'POST',
46 }),
47 );
48 expect(console).toHaveWarned();
49 });
50 });
51