Skip to content

Commit

Permalink
Merge branch 'add/protect-waf-phase-2' into update/jetpack-waf-settin…
Browse files Browse the repository at this point in the history
…gs-ui
  • Loading branch information
nateweller committed Jan 7, 2023
2 parents 195f82e + 85f6edc commit a6367b5
Show file tree
Hide file tree
Showing 64 changed files with 825 additions and 123 deletions.
10 changes: 5 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ Please add testing instructions to projects/plugins/jetpack/to-test.md in a new

Fixes #

#### Changes proposed in this Pull Request:
## Proposed changes:
<!--- Explain what functional changes your PR includes -->
*

#### Other information:
### Other information:

- [ ] Have you written new tests for your changes, if applicable?
- [ ] Have you checked the E2E test CI results, and verified that your changes do not break them?
- [ ] Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

#### Jetpack product discussion
## Jetpack product discussion
<!-- If you're an Automattician, include a shortlink to the p2 discussion with Jetpack Product here. -->
<!-- Make sure any changes to existing products have been discussed and agreed upon -->

#### Does this pull request change what data or activity we track or use?
## Does this pull request change what data or activity we track or use?
<!--- If so, please add the "[Status] Needs Privacy Updates" label and explain what changes there are. -->
<!--- Check existing Jetpack support documents for a preview of the information we need. -->

#### Testing instructions:
## Testing instructions:
<!-- If you were reviewing this PR, how would you like the instructions to be presented? -->
<!-- Please include detailed testing steps, explaining how to test your change. -->
<!-- Bear in mind that context you working on is not obvious for everyone. -->
Expand Down
20 changes: 16 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Changed headings in the `PULL_REQUEST_TEMPLATE`
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ function renderRecommendations( statusChecks ) {
'Please edit your PR description and explain what functional changes your PR includes, and why those changes are needed.',
hasPrivacy: `We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:
~~~
#### Does this pull request change what data or activity we track or use?
## Does this pull request change what data or activity we track or use?
My PR adds *x* and *y*.
~~~`,
hasTesting: `Please include detailed testing steps, explaining how to test your change, like so:
~~~
#### Testing instructions:
## Testing instructions:
* Go to '..'
*
Expand Down
5 changes: 5 additions & 0 deletions projects/js-packages/config/changelog/fix-react-native-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed

Config: Metro JS cannot resolve `./src/index.sj` without adding the path as the `main` property in package.json

3 changes: 2 additions & 1 deletion projects/js-packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-config",
"version": "0.1.16",
"version": "0.1.17-alpha",
"description": "Handles Jetpack global configuration shared across all packages",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/config/#readme",
"bugs": {
Expand Down Expand Up @@ -29,5 +29,6 @@
"exports": {
".": "./src/index.js"
},
"main": "./src/index.js",
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed

Connection: Metro JS is unable to build the component SCSS files. Adding a native index file to only export the modules required for the mobile editor build.

1 change: 1 addition & 0 deletions projects/js-packages/connection/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useConnection } from './components/use-connection';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Fixed an issue that would break the release process
2 changes: 1 addition & 1 deletion projects/js-packages/image-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"prepare": "pnpm build",
"prepare": "[ -e ./build/index.js ] || pnpm build",
"build": "tsc",
"clean": "rm -rf build/",
"watch": "pnpm run build && pnpm webpack watch",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Setup js tests and add some tests to existing reducers, selectors and hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix JS deps added in #28130.


3 changes: 3 additions & 0 deletions projects/packages/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-js": [
"pnpm run test"
],
"test-php": [
"@composer phpunit"
],
Expand Down
7 changes: 7 additions & 0 deletions projects/packages/backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build-concurrently": "pnpm run clean && concurrently 'pnpm:build-client' 'pnpm:build-php'",
"build-production-concurrently": "pnpm run clean && concurrently 'NODE_ENV=production BABEL_ENV=production pnpm run build-client' && pnpm run validate",
"clean": "rm -rf build/",
"test": "jest --config=tests/jest.config.js",
"validate": "pnpm exec validate-es build/",
"watch": "pnpm run build && webpack watch"
},
Expand All @@ -44,8 +45,14 @@
"@babel/preset-env": "7.20.2",
"@babel/register": "7.18.9",
"@babel/runtime": "7.20.7",
"@testing-library/dom": "8.19.1",
"@testing-library/react": "12.1.5",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "14.4.3",
"@wordpress/browserslist-config": "5.5.0",
"concurrently": "6.0.2",
"jest": "29.3.1",
"jest-environment-jsdom": "29.3.1",
"sass": "1.43.3",
"sass-loader": "12.4.0",
"webpack": "5.72.1",
Expand Down
100 changes: 100 additions & 0 deletions projects/packages/backup/src/js/hooks/test/useBackupsState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { renderHook } from '@testing-library/react-hooks';
import apiFetch from '@wordpress/api-fetch';
import { BACKUP_STATE } from '../../constants';
import useBackupState from '../useBackupsState';

const fixtures = {
no_backups: [],
no_backups_retry: [
{
id: 123456,
started: '2023-01-01 02:16:32',
last_updated: '2023-01-01 02:16:34',
status: 'error-will-retry',
period: 1672530000,
percent: 0,
is_backup: 1,
is_scan: 0,
},
],
complete: [
{
id: 381971090,
started: '2023-01-01 02:16:32',
last_updated: '2023-01-01 02:16:34',
status: 'finished',
period: 1672530000,
percent: 100,
is_backup: 1,
is_scan: 0,
has_warnings: false,
stats: {
prefix: 'wp_',
plugins: { count: 100 },
themes: { count: 100 },
uploads: { count: 100 },
tables: {
wp_posts: {
post_published: 100,
},
},
}, // full stats details are not required currently
},
],
no_good_backups: [
{
id: 123456,
started: '2023-01-01 02:16:32',
last_updated: '2023-01-01 02:16:34',
status: 'finished',
period: 1672530000,
percent: 0,
is_backup: 1,
is_scan: 0,
},
],
};

jest.mock( '@wordpress/api-fetch' );

describe( 'useBackupsState', () => {
it( 'backupState should be NO_BACKUPS when the site has no backups', async () => {
apiFetch.mockReturnValue( Promise.resolve( fixtures.no_backups ) );
const { result, waitForNextUpdate } = renderHook( () => useBackupState() );

await waitForNextUpdate();
expect( result.current.backupState ).toBe( BACKUP_STATE.NO_BACKUPS );
} );

it( 'backupState should be NO_BACKUPS_RETRY when last backup has a retry state', async () => {
apiFetch.mockReturnValue( Promise.resolve( fixtures.no_backups_retry ) );
const { result, waitForNextUpdate } = renderHook( () => useBackupState() );

await waitForNextUpdate();
expect( result.current.backupState ).toBe( BACKUP_STATE.NO_BACKUPS_RETRY );
} );

it( 'backupState should be COMPLETE when last backup has finished successfully', async () => {
apiFetch.mockReturnValue( Promise.resolve( fixtures.complete ) );
const { result, waitForNextUpdate } = renderHook( () => useBackupState() );

await waitForNextUpdate();
expect( result.current.backupState ).toBe( BACKUP_STATE.COMPLETE );
} );

it( 'backupState should be NO_GOOD_BACKUPS when last backup finished with no stats', async () => {
apiFetch.mockReturnValue( Promise.resolve( fixtures.no_good_backups ) );
const { result, waitForNextUpdate } = renderHook( () => useBackupState() );

await waitForNextUpdate();
expect( result.current.backupState ).toBe( BACKUP_STATE.NO_GOOD_BACKUPS );
} );

it( 'backupState should be NO_GOOD_BACKUPS when fetch backups API call fails', async () => {
apiFetch.mockReturnValue( Promise.reject( 'any error' ) );
const { result, waitForNextUpdate } = renderHook( () => useBackupState() );

await waitForNextUpdate();
expect( result.current.backupState ).toBe( BACKUP_STATE.NO_GOOD_BACKUPS );
} );
} );
2 changes: 1 addition & 1 deletion projects/packages/backup/src/js/hooks/useBackupsState.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const useBackupsState = () => {
}

// Repeat query for NO_BACKUPS (before first) and IN_PROGRESS
if ( res.length === 0 || 'started' === latestBackup.status ) {
if ( res.length === 0 || ( latestBackup && 'started' === latestBackup.status ) ) {
// Grab progress and update every progressInterval until complete.
setTimeout( () => {
fetchBackupsState();
Expand Down
9 changes: 9 additions & 0 deletions projects/packages/backup/src/js/reducers/test/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import API from '../api';

describe( 'reducer', () => {
describe( 'API', () => {
test( 'should return the initial state when undefined state is passed', () => {
expect( API( undefined, {} ) ).toEqual( {} );
} );
} );
} );
9 changes: 9 additions & 0 deletions projects/packages/backup/src/js/reducers/test/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import assets from '../assets';

describe( 'reducer', () => {
describe( 'assets', () => {
test( 'should return the initial state when undefined state is passed', () => {
expect( assets( undefined, {} ) ).toEqual( {} );
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import connectedPlugins from '../connected-plugins';

describe( 'reducer', () => {
describe( 'connectedPlugins', () => {
test( 'should return the initial state when undefined state is passed', () => {
expect( connectedPlugins( undefined, {} ) ).toEqual( {} );
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import jetpackStatus from '../jetpack-status';

describe( 'reducer', () => {
describe( 'jetpackStatus', () => {
test( 'should return the initial state when undefined state is passed', () => {
expect( jetpackStatus( undefined, {} ) ).toEqual( {} );
} );
} );
} );
9 changes: 9 additions & 0 deletions projects/packages/backup/src/js/reducers/test/site-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import siteData from '../site-data';

describe( 'reducer', () => {
describe( 'siteData', () => {
test( 'should return the initial state when undefined state is passed', () => {
expect( siteData( undefined, {} ) ).toEqual( {} );
} );
} );
} );
Loading

0 comments on commit a6367b5

Please sign in to comment.