Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,16 @@ public function get_item_schema() {
'app_id' => array(
'description' => __( 'A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.' ),
'type' => 'string',
'format' => 'uuid',
'oneOf' => array(
array(
'type' => 'string',
'format' => 'uuid',
),
array(
'type' => 'string',
'enum' => array( '' ),
),
),
'context' => array( 'view', 'edit', 'embed' ),
),
'name' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,67 @@ public function test_prepare_item() {
$this->check_response( $prepared->get_data(), $item );
}

/**
* @ticket 53692
*/
public function test_app_id_schema() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/me/application-passwords' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertArrayHasKey( 'app_id', $properties );
$this->assertSame( 'string', $properties['app_id']['type'] );
$this->assertCount( 2, $properties['app_id']['oneOf'] );

$this->assertSame( 'string', $properties['app_id']['oneOf'][0]['type'] );
$this->assertSame( 'uuid', $properties['app_id']['oneOf'][0]['format'] );

$this->assertSame( 'string', $properties['app_id']['oneOf'][1]['type'] );
$this->assertSame( array( '' ), $properties['app_id']['oneOf'][1]['enum'] );
}

/**
* @ticket 53692
*/
public function test_create_item_with_empty_app_id() {
wp_set_current_user( self::$admin );

$request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' );
$request->set_body_params(
array(
'name' => 'Test',
'app_id' => '',
)
);

$response = rest_get_server()->dispatch( $request );
$this->assertSame( 201, $response->get_status() );
$data = $response->get_data();
$this->assertSame( '', $data['app_id'] );
}

/**
* @ticket 53692
*/
public function test_create_item_with_uuid_app_id() {
wp_set_current_user( self::$admin );

$uuid = wp_generate_uuid4();
$request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' );
$request->set_body_params(
array(
'name' => 'Test',
'app_id' => $uuid,
)
);

$response = rest_get_server()->dispatch( $request );
$this->assertSame( 201, $response->get_status() );
$data = $response->get_data();
$this->assertSame( $uuid, $data['app_id'] );
}

/**
* Checks the password response matches the expected format.
*
Expand Down
26 changes: 24 additions & 2 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -10053,7 +10053,18 @@ mockedApiResponse.Schema = {
"app_id": {
"description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.",
"type": "string",
"format": "uuid",
"oneOf": [
{
"type": "string",
"format": "uuid"
},
{
"type": "string",
"enum": [
""
]
}
],
"required": false
},
"name": {
Expand Down Expand Up @@ -10137,7 +10148,18 @@ mockedApiResponse.Schema = {
"app_id": {
"description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.",
"type": "string",
"format": "uuid",
"oneOf": [
{
"type": "string",
"format": "uuid"
},
{
"type": "string",
"enum": [
""
]
}
],
"required": false
},
"name": {
Expand Down
Loading