-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backup: add on-demand backup feature (#37998)
* Add enqueue backup endpoint * changelog * Add hook to decide whether to show the back up now button * Update composer and changelog for backup package * Fetch backups stopped flag from /site/backup/size endpoint * Update hooks * Update getBackupStoppedFlag * Add back up now button component * Add `@wordpress/components` and `prop-types` to the backup package * Adjust in progress message when it is the initial backup or not * Update `useBackupState` to return if the latest backup is an initial backup * Add back up now button on the header * Refetch backup state once the new backup is enqueued * Add actions, reducers and selectors for fetching backups * Update useBackupsState hook to use redux for backup state management * Refactor ReviewMessage to use useBackupsState() * Update useBackupsState hook to include enqueued parameter on BackupNowButton * Refactor useBackupsState.js tests * Add site-backups reducer tests * Add tests for getBackups action * Add site-backups selectors tests * Update inProgressBackup to not use __() with ternary operators * Add translations to `Back up now` button labels and tooltip descriptions
- Loading branch information
Showing
28 changed files
with
824 additions
and
134 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add on-demand backups feature in the backup package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
projects/packages/backup/src/js/actions/test/get-backups.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import actions from '../index'; | ||
import { SITE_BACKUPS_GET, SITE_BACKUPS_GET_SUCCESS, SITE_BACKUPS_GET_FAILED } from '../types'; | ||
|
||
jest.mock( '@wordpress/api-fetch' ); | ||
|
||
const anyFunction = () => {}; | ||
|
||
const apiFixtures = { | ||
requestOptions: { | ||
path: '/jetpack/v4/backups', | ||
}, | ||
successResponse: [ | ||
{ | ||
id: '123456789', | ||
started: '2024-06-26 11:40:54', | ||
last_updated: '2024-06-26 11:44:55', | ||
status: 'not-accessible', | ||
period: '321321321', | ||
percent: '0', | ||
is_backup: '1', | ||
is_scan: '0', | ||
}, | ||
{ | ||
id: '987654321', | ||
started: '2024-06-26 06:36:08', | ||
last_updated: '2024-06-26 06:39:05', | ||
status: 'finished', | ||
period: '123123123', | ||
percent: '100', | ||
is_backup: '1', | ||
is_scan: '0', | ||
has_snapshot: true, | ||
discarded: '0', | ||
stats: {}, | ||
}, | ||
], | ||
failureResponse: 'Timeout error', | ||
}; | ||
|
||
describe( 'getBackups', () => { | ||
beforeEach( () => jest.clearAllMocks() ); | ||
|
||
it( 'dispatches SITE_BACKUPS_GET and SITE_BACKUPS_GET_SUCCESS on successful fetch', async () => { | ||
const dispatch = jest.fn( anyFunction ); | ||
apiFetch.mockReturnValue( Promise.resolve( apiFixtures.successResponse ) ); | ||
|
||
await actions.getBackups()( { dispatch } ); | ||
expect( apiFetch ).toHaveBeenCalledWith( apiFixtures.requestOptions ); | ||
|
||
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch ).toHaveBeenCalledWith( { type: SITE_BACKUPS_GET } ); | ||
expect( dispatch ).toHaveBeenCalledWith( { | ||
type: SITE_BACKUPS_GET_SUCCESS, | ||
payload: apiFixtures.successResponse, | ||
} ); | ||
} ); | ||
|
||
it( 'dispatches SITE_BACKUPS_GET and SITE_BACKUPS_GET_FAILED when API call fails', async () => { | ||
const dispatch = jest.fn( anyFunction ); | ||
apiFetch.mockReturnValue( Promise.reject( apiFixtures.failureResponse ) ); | ||
|
||
await actions.getBackups()( { dispatch } ); | ||
expect( apiFetch ).toHaveBeenCalledWith( apiFixtures.requestOptions ); | ||
|
||
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch ).toHaveBeenCalledWith( { type: SITE_BACKUPS_GET } ); | ||
expect( dispatch ).toHaveBeenCalledWith( { type: SITE_BACKUPS_GET_FAILED } ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.