Skip to content

Commit

Permalink
Merge pull request #2926 from 10up/burhan/improve-commands-test-coverage
Browse files Browse the repository at this point in the history
Improve wpcli commands test coverage
  • Loading branch information
felipeelia committed Aug 12, 2022
2 parents 07b4379 + de1faad commit 44a77bd
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"wp-content/plugins/unsupported-server-software.php": "./tests/cypress/wordpress-files/test-plugins/unsupported-server-software.php",
"wp-content/plugins/unsupported-elasticsearch-version.php": "./tests/cypress/wordpress-files/test-plugins/unsupported-elasticsearch-version.php",
"wp-content/plugins/shorten-autosave.php": "./tests/cypress/wordpress-files/test-plugins/shorten-autosave.php",
"wp-content/plugins/fake-log-messages.php": "./tests/cypress/wordpress-files/test-plugins/fake-log-messages.php",
"wp-content/uploads/content-example.xml": "./tests/cypress/wordpress-files/test-docs/content-example.xml"
}
}
Expand Down
75 changes: 75 additions & 0 deletions tests/cypress/integration/wp-cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ describe('WP-CLI Commands', () => {
expect(indexPerPostType).to.not.equal(indexTotal);
});
});

it('Can index without using dynamic bulk requests if user specifies --static-bulk parameter', () => {
cy.activatePlugin('fake-log-messages');

cy.wpCli('wp elasticpress index --static-bulk')
.its('stdout')
.should('contain', 'Index command with --static-bulk flag completed')
.should('contain', 'Done');

cy.deactivatePlugin('fake-log-messages');
});
});

it('Can delete the index of current blog if user runs wp elasticpress delete-index', () => {
Expand Down Expand Up @@ -291,4 +302,68 @@ describe('WP-CLI Commands', () => {
checkIfNotMissingIndexes('network');
});
});

it('Can set the algorithm version', () => {
cy.wpCli('wp elasticpress set-algorithm-version --default')
.its('stdout')
.should('contain', 'Done');

cy.wpCli('wp elasticpress get-algorithm-version')
.its('stdout')
.should('contain', 'default');

cy.wpCli('wp elasticpress set-algorithm-version --version=1.0.0')
.its('stdout')
.should('contain', 'Done');

cy.wpCli('wp elasticpress get-algorithm-version').its('stdout').should('contain', '1.0.0');

cy.wpCli('wp elasticpress set-algorithm-version', true)
.its('stderr')
.should('contain', 'This command expects a version number or the --default flag');
});

it('Can get the mapping information', () => {
cy.wpCli('wp elasticpress get-mapping').its('stdout').should('contain', 'mapping_version');
});

it('Can get the cluster indexes information', () => {
cy.wpCli('wp elasticpress get-cluster-indexes').its('stdout').should('contain', 'health');
});

it('Can get the indexes names', () => {
cy.wpCli('wp elasticpress get-indexes').its('code').should('equal', 0);

cy.wpCli('wp elasticpress get-indexes --pretty').its('stdout').should('contain', '\n');
});

it('Can stop the sync operation and clear it', () => {
// if no index is running, this will fail.
cy.wpCli('wp elasticpress stop-indexing')
.its('stderr')
.should('contain', 'There is no indexing operation running');

// mock the indexing process
cy.wpCliEval(
`update_option('ep_index_meta', true); set_transient('ep_sync_interrupted', true);`,
);

cy.wpCli('wp elasticpress stop-indexing').its('stdout').should('contain', 'Done');

cy.wpCli('wp elasticpress clear-index').its('stdout').should('contain', 'Index cleared');
});

it('can send an HTTP request to Elasticsearch', () => {
cy.wpCli('wp elasticpress request _cat/indices').its('code').should('equal', 0);

// check if it throw an error if non supported method is used?
cy.wpCli('wp elasticpress request _cat/indices --method=POST')
.its('stdout')
.should('contain', 'Incorrect HTTP method for uri');

// check if it print the debugging info?
cy.wpCli('wp elasticpress request _cat/indices --debug-http-request')
.its('stdout')
.should('contain', '[http_response] => WP_HTTP_Requests_Response Object');
});
});
17 changes: 17 additions & 0 deletions tests/cypress/wordpress-files/test-plugins/fake-log-messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* Plugin Name: Fake Log Messages
* Description: Fake log messages for E2E testings
* Version: 1.0.0
* Author: 10up Inc.
* License: GPLv2 or later
*/


/**
* Add log message for index command with --static-bulk flag.
*/
add_action( 'ep_after_bulk_index', function() {
WP_CLI::log('Index command with --static-bulk flag completed.');
} );

0 comments on commit 44a77bd

Please sign in to comment.