diff --git a/plugins/wpe-content-model/includes/content-registration/custom-post-types-registration.php b/plugins/wpe-content-model/includes/content-registration/custom-post-types-registration.php index 8595e1870..2060d2f99 100644 --- a/plugins/wpe-content-model/includes/content-registration/custom-post-types-registration.php +++ b/plugins/wpe-content-model/includes/content-registration/custom-post-types-registration.php @@ -207,10 +207,10 @@ function map_html_field_type_to_graphql_field_type( string $field_type ): ?strin case 'textarea': case 'string': case 'date': - case 'media': // ? + case 'media': return 'String'; case 'number': - return 'Int'; + return 'Float'; default: return null; } diff --git a/plugins/wpe-content-model/tests/integration/content-registration/example-data/expected-post-types.php b/plugins/wpe-content-model/tests/integration/content-registration/example-data/expected-post-types.php index 13a73da53..170256f83 100644 --- a/plugins/wpe-content-model/tests/integration/content-registration/example-data/expected-post-types.php +++ b/plugins/wpe-content-model/tests/integration/content-registration/example-data/expected-post-types.php @@ -79,6 +79,12 @@ 'show_in_rest' => false, 'show_in_graphql' => false, ), + 'dog-weight' => array( + 'type' => 'number', + 'description' => 'dog-weight description', + 'show_in_rest' => true, + 'show_in_graphql' => true, + ), ), ), 'cat' => diff --git a/plugins/wpe-content-model/tests/integration/content-registration/test-custom-post-type-registration.php b/plugins/wpe-content-model/tests/integration/content-registration/test-custom-post-type-registration.php index c0adfccd2..a9b4c3c06 100644 --- a/plugins/wpe-content-model/tests/integration/content-registration/test-custom-post-type-registration.php +++ b/plugins/wpe-content-model/tests/integration/content-registration/test-custom-post-type-registration.php @@ -54,6 +54,7 @@ public function setUp() { ] ); update_post_meta( $this->dog_post_id, 'dog-test-field', 'dog-test-field string value' ); + update_post_meta( $this->dog_post_id, 'dog-weight', '100.25' ); } public function tearDown() { @@ -79,6 +80,9 @@ public function test_post_meta_that_is_configured_to_show_in_rest_is_accessible( $response_data = $response->get_data(); $this->assertArrayHasKey( 'dog-test-field', $response_data['meta'] ); $this->assertSame( $response_data['meta']['dog-test-field'][0], 'dog-test-field string value' ); + + self::assertArrayHasKey( 'dog-weight', $response_data['meta'] ); + self::assertEquals( '100.25', $response_data['meta']['dog-weight'][0] ); } public function test_post_meta_that_is_configured_to_not_show_in_rest_is_not_accessible(): void { @@ -126,15 +130,19 @@ public function test_graphql_query_result_has_custom_fields_data(): void { title content dogTestField + dogWeight } } } ' ] ); - self::assertTrue( true, array_key_exists( 'dogTestField', $results['data']['dogs']['nodes'][0] ) ); + self::assertArrayHasKey( 'dogTestField', $results['data']['dogs']['nodes'][0] ); self::assertSame( $results['data']['dogs']['nodes'][0]['dogTestField'], 'dog-test-field string value' ); + self::assertArrayHasKey( 'dogWeight', $results['data']['dogs']['nodes'][0] ); + self::assertSame( $results['data']['dogs']['nodes'][0]['dogWeight'], 100.25 ); + } catch ( Exception $exception ) { throw new PHPUnitRunnerException( sprintf( __FUNCTION__ . ' failed with exception: %s', $exception->getMessage() ) ); }