Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements metadata for customer register and update #402

Merged
merged 3 commits into from
Jan 27, 2021

Conversation

believelody
Copy link
Contributor

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

馃毃Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix branch (right side). Don't pull request from your master!

What does this implement/fix? Explain your changes.

Allow Customer to include metadata in registerCustomer mutation and updateCustomer mutation

Does this close any currently open issues?

No

Any relevant logs, error output, GraphiQL screenshots, etc?

Metadata in registerCustomer mutation
image

Metadata in customers query
image

Metadata in updateCustomer mutation
image

Any other comments?

Tell me if this enough and meet your requirements. Inspired by woocommerce-rest-api customer register feature

Where has this been tested?

Operating System: Ubuntu 18.04.5

WordPress Version: 5.5.3

@ohuu
Copy link

ohuu commented Jan 10, 2021

Looks like the linting issues that this PR is failing on aren't related to the changes in this PR, is that correct? I really need this feature, any chance of merging it? I'm happy to help in any way I can to speed this up?
Cheers

@believelody
Copy link
Contributor Author

@PaperPlaneSoftware feel free to check whatever you can add. I'm still waiting owners to review my PR. Hope they' will find some time, this library is so much great !

@aresrioja10
Copy link

aresrioja10 commented Jan 13, 2021

Hi! I also need this feature! I'm using custom fields (saved as meta data in Worpdress) in the billing and shipping form and it's the only way to update this information!

@believelody Can we help you to speed this up?

Thanks for your work by the way 馃殌

@believelody
Copy link
Contributor Author

@aresrioja10 sure, feel free to check what you can do. It seems the big problem is lint code. Still waiting for @kidunot89 to check if something is wrong.

Copy link
Member

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@believelody @aresrioja10 I'm sorry for the delayed response been fixing a few fires with CI here and there. To answer your question the hold up is testing.

I can't add new code without ensuring its covered by the tests, too much risk involved with sites in production. This typically means for every new PR I have to usually pull down the PR branch, add a new test if the incoming changes warrant it and this change definitely warrants a test.

I have two other PRs to do before this one, but if one of you adds a working test for the changes to this test file. I can expedite this PR immediately.

Copy link
Member

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@believelody @aresrioja10 With the test I added, this PR is ready for merging as soon as CI passes.

Comment on lines +566 to +729
$query = '
mutation( $input: UpdateCustomerInput! ) {
updateCustomer( input: $input ) {
customer {
databaseId
email
metaData {
key
value
}
}
}
}
';
$variables = array(
'input' => array(
'clientMutationId' => 'some_id',
'id' => \GraphQLRelay\Relay::toGlobalId( 'customer', $user->ID ),
'metaData' => array(
array(
'key' => 'test_meta_key',
'value' => 'new_meta_value',
),
),
)
);

$actual = graphql( compact( 'query', 'variables' ) );
codecept_debug( $actual );

$expected = array(
'data' => array(
'updateCustomer' => array(
'customer' => array(
'databaseId' => $user->ID,
'email' => 'user@woographql.test',
'metaData' => array(
array(
'key' => 'test_meta_key',
'value' => 'new_meta_value',
)
)
),
),
),
);

$this->assertEquals( $expected, $actual );

/**
* Assertion Three
*
* Test "metaData" input field with "updateCustomer" mutation on the session user.
*/
$query = '
mutation( $input: UpdateCustomerInput! ) {
updateCustomer( input: $input ) {
customer {
id
metaData {
key
value
}
}
}
}
';
$variables = array(
'input' => array(
'clientMutationId' => 'some_id',
'metaData' => array(
array(
'key' => 'test_meta_key',
'value' => 'test_meta_value',
),
),
)
);

$actual = graphql( compact( 'query', 'variables' ) );
codecept_debug( $actual );

$expected = array(
'data' => array(
'updateCustomer' => array(
'customer' => array(
'id' => 'guest',
'metaData' => array(
array(
'key' => 'test_meta_key',
'value' => 'test_meta_value',
)
)
),
),
),
);

$this->assertEquals( $expected, $actual );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@believelody @aresrioja10 Test added. Please use this as a reference in future when making PRs introducing logic that needs to be tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @kidunot89.Don't worry for your delayed reply, I will use your test code and learn better about that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kidunot89 Thank you so much! I'm gonna test it right now :)

@kidunot89 kidunot89 merged commit 35121e5 into wp-graphql:develop Jan 27, 2021
@kidunot89 kidunot89 added enhancement New feature or request new types Feature adds a new type(s) and removed new types Feature adds a new type(s) labels Feb 24, 2021
@kidunot89 kidunot89 mentioned this pull request Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants