Skip to content

Commit 44c2717

Browse files
authored
fix: WP User core field support fixed in updateCustomer mutation (#789)
* devops: CustomerMutationsTest refactored heavily * fix: `updateCustomer` mutation patched
1 parent 87d7a7b commit 44c2717

File tree

6 files changed

+340
-247
lines changed

6 files changed

+340
-247
lines changed

bin/_lib.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ install_local_test_library() {
7171
codeception/module-rest:* \
7272
codeception/util-universalframework:^1.0 \
7373
wp-graphql/wp-graphql-testcase:^2.3 \
74-
stripe/stripe-php
74+
stripe/stripe-php \
75+
fakerphp/faker
7576

7677
}
7778

@@ -102,7 +103,8 @@ remove_local_test_library() {
102103
codeception/module-rest \
103104
codeception/util-universalframework \
104105
lucatume/wp-browser \
105-
stripe/stripe-php
106+
stripe/stripe-php \
107+
fakerphp/faker
106108
}
107109

108110
cleanup_composer_file() {

composer.lock

Lines changed: 50 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/data/mutation/class-customer-mutation.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static function empty_shipping() {
9696
'state' => '',
9797
'postcode' => '',
9898
'country' => '',
99+
'phone' => '',
99100
];
100101
}
101102

@@ -107,10 +108,7 @@ public static function empty_shipping() {
107108
public static function empty_billing() {
108109
return array_merge(
109110
self::empty_shipping(),
110-
[
111-
'email' => '',
112-
'phone' => '',
113-
]
111+
[ 'email' => '' ]
114112
);
115113
}
116114

includes/mutation/class-customer-update.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,17 @@ public static function get_output_fields() {
9393
*/
9494
public static function mutate_and_get_payload() {
9595
return static function ( $input, AppContext $context, ResolveInfo $info ) {
96-
$session_only = empty( $input['id'] );
96+
$session_only = empty( $input['id'] ) && ! is_user_logged_in();
9797
$payload = null;
9898

9999
if ( ! $session_only ) {
100100
// Get closure from "UserRegister::mutate_and_get_payload".
101101
$update_user = UserUpdate::mutate_and_get_payload();
102102

103+
if ( ! isset( $input['id'] ) ) {
104+
$input['id'] = get_current_user_id();
105+
}
106+
103107
// Update customer with core UserUpdate closure.
104108
$payload = $update_user( $input, $context, $info );
105109

tests/_support/Factory/CustomerFactory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Tests\WPGraphQL\WooCommerce\Factory;
1010

11-
use Tests\WPGraphQL\WooCommerce\Utils\Dummy;
11+
use Faker\Factory;
1212

1313
/**
1414
* Customer factory class for testing.
@@ -18,7 +18,7 @@ public function __construct( $factory = null ) {
1818
parent::__construct( $factory );
1919

2020
$this->default_generation_definitions = [];
21-
$this->dummy = Dummy::instance();
21+
$this->dummy = Factory::create();
2222
}
2323

2424
public function create_object( $args ) {
@@ -29,16 +29,16 @@ public function create_object( $args ) {
2929
$customer = new \WC_Customer();
3030

3131
// Create customer details
32-
$username = $this->dummy->username();
33-
$first_name = $this->dummy->firstname();
34-
$last_name = $this->dummy->lastname();
35-
$street = $this->dummy->street();
32+
$username = $this->dummy->userName();
33+
$first_name = $this->dummy->firstName();
34+
$last_name = $this->dummy->lastName();
35+
$street = $this->dummy->streetAddress();
3636
$city = $this->dummy->city();
3737
$state = $this->dummy->state();
38-
$postcode = $this->dummy->zipcode();
38+
$postcode = $this->dummy->postcode();
3939
$country = 'US';
4040
$email = $this->dummy->email();
41-
$phone = $this->dummy->telephone();
41+
$phone = $this->dummy->phoneNumber();
4242

4343
$args = array_merge(
4444
[
@@ -66,6 +66,7 @@ public function create_object( $args ) {
6666
$customer->set_shipping_state( ! empty( $args['shipping']['state'] ) ? $args['shipping']['state'] : $state );
6767
$customer->set_shipping_postcode( ! empty( $args['shipping']['postcode'] ) ? $args['shipping']['postcode'] : $postcode );
6868
$customer->set_shipping_country( ! empty( $args['shipping']['country'] ) ? $args['shipping']['country'] : $country );
69+
$customer->set_shipping_phone( ! empty( $args['shipping']['phone'] ) ? $args['shipping']['phone'] : $phone );
6970

7071
// Set data.
7172
$customer->set_props(

0 commit comments

Comments
 (0)