Skip to content

Commit 4d24037

Browse files
committed
"testRegisterMutationWithoutAnyInfo" test added to the "CustomerMutationsTest" test case.
1 parent 2dd6ae2 commit 4d24037

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

includes/mutation/class-customer-register.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public static function get_input_fields() {
6161
)
6262
);
6363

64-
// Make the username field optional
64+
// Make the username field optional.
6565
$result['username']['type'] = 'String';
66-
66+
6767
return $result;
6868
}
6969

@@ -116,10 +116,10 @@ public static function mutate_and_get_payload() {
116116
$user_args = UserMutation::prepare_user_object( $input, 'registerCustomer' );
117117

118118
// Create the user using native WooCommerce function.
119-
$user_id = wc_create_new_customer(
119+
$user_id = \wc_create_new_customer(
120120
$user_args['user_email'],
121-
isset($user_args['user_login']) ? $user_args['user_login'] : '',
122-
isset($user_args['user_pass']) ? $user_args['user_pass'] : '',
121+
isset( $user_args['user_login'] ) ? $user_args['user_login'] : '',
122+
isset( $user_args['user_pass'] ) ? $user_args['user_pass'] : '',
123123
$user_args
124124
);
125125

tests/wpunit/CustomerMutationsTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ private function updateCustomer( $input ) {
201201
return $actual;
202202
}
203203

204-
// tests
205204
public function testRegisterMutationWithoutCustomerInfo() {
206205
/**
207206
* Assertion One
@@ -518,4 +517,50 @@ public function testUpdateMutationWithShippingSameAsBilling() {
518517

519518
$this->assertEquals( $expected, $actual );
520519
}
520+
521+
public function testRegisterMutationWithoutAnyInfo() {
522+
/**
523+
* Assertion One
524+
*
525+
* Tests mutation without a providing an username and password.
526+
*/
527+
$actual = $this->registerCustomer(
528+
array(
529+
'clientMutationId' => 'someId',
530+
'email' => $this->email,
531+
'firstName' => $this->first_name,
532+
'lastName' => $this->last_name,
533+
)
534+
);
535+
536+
// use --debug flag to view.
537+
codecept_debug( $actual );
538+
539+
$user = get_user_by( 'email', '[email protected]' );
540+
$this->assertTrue( is_a( $user, WP_User::class ) );
541+
542+
$expected = array(
543+
'data' => array(
544+
'registerCustomer' => array(
545+
'clientMutationId' => 'someId',
546+
'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ),
547+
'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ),
548+
'customer' => array(
549+
'databaseId' => $user->ID,
550+
'email' => $this->email,
551+
'username' => $user->user_login,
552+
'firstName' => $this->first_name,
553+
'lastName' => $this->last_name,
554+
'billing' => $this->empty_billing(),
555+
'shipping' => $this->empty_shipping(),
556+
),
557+
'viewer' => array(
558+
'userId' => $user->ID,
559+
)
560+
),
561+
),
562+
);
563+
564+
$this->assertEquals( $expected, $actual );
565+
}
521566
}

0 commit comments

Comments
 (0)