Skip to content

Commit

Permalink
fix OpenAI Embeddings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Jan 11, 2024
1 parent b6647ec commit 9d4b9a8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,30 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => {
cy.get( '#classifai_feature_classification_post_types_post' ).check();
cy.get( '#classifai_feature_classification_post_statuses_publish' ).check();
cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category' ).check();
cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category_threshold' ).type( 80 ); // "Test" requires 80% confidence. At 81%, it does not apply.
cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category_threshold' ).clear().type( 100 ); // "Test" requires 80% confidence. At 81%, it does not apply.
cy.get( '#number_of_terms' ).clear().type( 1 );
cy.get( '#submit' ).click();
} );

it( 'Can see the preview on the settings page', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification'
);

cy.get( '#submit' ).click();

// Click the Preview button.
const closePanelSelector = '#get-classifier-preview-data-btn';
cy.get( closePanelSelector ).click();

// Check the term is received and visible.
cy.get( '.tax-row--Category' ).should( 'exist' );
} );

it( 'Can create category and post and category will get auto-assigned', () => {
// Remove custom taxonomies so those don't interfere with the test.
cy.visit(
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
'/wp-admin/tools.php?page=classifai&tab=language_processing'
);
cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category' ).uncheck();
cy.get( '#submit' ).click();
Expand Down Expand Up @@ -79,25 +94,13 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => {
.should( 'be.checked' );
cy.wrap( $panel )
.find(
'.editor-post-taxonomies__hierarchical-terms-list .editor-post-taxonomies__hierarchical-terms-choice:first label'
'.editor-post-taxonomies__hierarchical-terms-list'
)
.children()
.contains( 'Test' );
} );
} );

it( 'Can see the preview on the settings page', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification'
);

// Click the Preview button.
const closePanelSelector = '#get-classifier-preview-data-btn';
cy.get( closePanelSelector ).click();

// Check the term is received and visible.
cy.get( '.tax-row--Category' ).should( 'exist' );
} );

it( 'Can create category and post and category will not get auto-assigned if feature turned off', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification'
Expand Down Expand Up @@ -203,7 +206,7 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => {
it( 'Can enable/disable content classification feature by role', () => {
// Remove custom taxonomies so those don't interfere with the test.
cy.visit(
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
'/wp-admin/tools.php?page=classifai&tab=language_processing'
);

cy.get( '#submit' ).click();
Expand Down
2 changes: 2 additions & 0 deletions tests/test-plugin/e2e-test-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) {

if ( strpos( $url, 'http://e2e-test-nlu-server.test/v1/analyze' ) !== false ) {
$response = file_get_contents( __DIR__ . '/nlu.json' );
} elseif ( strpos( $url, 'https://api.openai.com/v1/models' ) !== false ) {
$response = file_get_contents( __DIR__ . '/models.json' );
} elseif ( strpos( $url, 'https://api.openai.com/v1/completions' ) !== false ) {
$response = file_get_contents( __DIR__ . '/chatgpt.json' );
} elseif ( strpos( $url, 'https://api.openai.com/v1/chat/completions' ) !== false ) {
Expand Down
23 changes: 23 additions & 0 deletions tests/test-plugin/models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"object": "list",
"data": [
{
"id": "model-id-0",
"object": "model",
"created": 1686935002,
"owned_by": "organization-owner"
},
{
"id": "model-id-1",
"object": "model",
"created": 1686935002,
"owned_by": "organization-owner"
},
{
"id": "model-id-2",
"object": "model",
"created": 1686935002,
"owned_by": "openai"
}
]
}

0 comments on commit 9d4b9a8

Please sign in to comment.