Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve wpcli commands test coverage #2926

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
73 changes: 73 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,15 @@ 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');
felipeelia marked this conversation as resolved.
Show resolved Hide resolved

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

it('Can delete the index of current blog if user runs wp elasticpress delete-index', () => {
Expand Down Expand Up @@ -291,4 +300,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.');
} );