Skip to content

Commit e5588b7

Browse files
committed
Fix the tests cleanup
1 parent 221cec4 commit e5588b7

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

tests/e2e/plugins/scf-test-setup-post-types.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,26 @@ function scf_test_create_scf_post_type_entry() {
9898
$result = $instance->update_post( $post_type_config );
9999

100100
if ( is_array( $result ) && isset( $result['ID'] ) ) {
101-
// Mark as created so we don't duplicate it
102-
update_option( 'scf_test_post_type_created', true );
101+
// Store the post ID so we can delete it later
102+
update_option( 'scf_test_post_type_created', $result['ID'] );
103103
}
104104
}
105105

106+
/**
107+
* Clean up on plugin deactivation
108+
*/
109+
function scf_test_cleanup() {
110+
// Get the stored post ID and delete the post
111+
$post_id = get_option( 'scf_test_post_type_created' );
112+
if ( $post_id ) {
113+
wp_delete_post( $post_id, true );
114+
}
115+
116+
// Clean up the option
117+
delete_option( 'scf_test_post_type_created' );
118+
}
119+
106120
// Register hooks
107121
add_action( 'init', 'scf_test_register_post_types', 20 );
108122
add_action( 'acf/init', 'scf_test_create_scf_post_type_entry', 15 );
123+
register_deactivation_hook( __FILE__, 'scf_test_cleanup' );

tests/e2e/rest-api-types-endpoint.spec.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ test.describe( 'REST API Types Endpoint', () => {
151151
} );
152152

153153
// Should succeed if our test post type is properly registered with SCF
154-
expect( typeWithScfSource ).toHaveProperty(
155-
'slug',
156-
customTestType
157-
);
154+
expect( typeWithScfSource ).toHaveProperty( 'slug', customTestType );
158155
} );
159156

160157
test( 'should validate source parameter values', async ( {
@@ -283,9 +280,7 @@ test.describe( 'REST API Types Endpoint', () => {
283280

284281
// Test that it only appears in one source
285282
const sourceCount =
286-
( inScf ? 1 : 0 ) +
287-
( inCore ? 1 : 0 ) +
288-
( inOther ? 1 : 0 );
283+
( inScf ? 1 : 0 ) + ( inCore ? 1 : 0 ) + ( inOther ? 1 : 0 );
289284
expect( sourceCount ).toBe( 1 );
290285

291286
// It should never be in core source
@@ -355,7 +350,10 @@ test.describe( 'REST API Types Endpoint', () => {
355350
path: `/wp/v2/types/${ customTestType }`,
356351
params: { source: 'scf' },
357352
} );
358-
expect( customTypeWithScf ).toHaveProperty( 'slug', customTestType );
353+
expect( customTypeWithScf ).toHaveProperty(
354+
'slug',
355+
customTestType
356+
);
359357

360358
// SCF test type should NOT be accessible with other source
361359
try {
@@ -386,15 +384,7 @@ test.describe( 'REST API Types Endpoint', () => {
386384
} );
387385

388386
test.afterAll( async ( { requestUtils } ) => {
389-
// Deactivate the plugins
390387
await requestUtils.deactivatePlugin( 'scf-test-setup-post-types' );
391388
await requestUtils.deactivatePlugin( PLUGIN_SLUG );
392-
393-
// Clean up by deleting the option that marks the post types as created
394-
await requestUtils.rest( {
395-
path: '/wp/v2/settings',
396-
method: 'POST',
397-
data: { scf_test_post_type_created: false },
398-
} );
399389
} );
400390
} );

0 commit comments

Comments
 (0)