Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Conversation

atwixfirster
Copy link
Contributor

@atwixfirster atwixfirster commented Apr 3, 2019

This PR is a:

  • New topic
  • Content update
  • Content fix or rewrite
  • Bug fix or improvement

Summary

When this pull request is merged, it will add information to "GraphQL functional testing" page how to cover negative scenarios with expected exceptions.

Additional information

List all affected URLs

Thank you!

whatsnew
Added section about exceptions to GraphQL functional testing.

1. Add information how to cover negative scenarios with expected exceptions to "GraphQL functional testing"

Page: https://devdocs.magento.com/guides/v2.3/graphql/functional-testing.html
@devops-devdocs
Copy link
Collaborator

An admin must run tests on this PR before it can be merged.

@rogyar
Copy link
Contributor

rogyar commented Apr 10, 2019

Hi @atwixfirster. Thank you for your collaboration. Please, consider making minor adjustments mentioned in the review.

@rogyar rogyar added Technical Updates to the code or processes that alter the technical content of the doc Major Update Significant original updates to existing content labels Apr 10, 2019
@rogyar rogyar self-assigned this Apr 10, 2019
@keharper
Copy link
Contributor

I've got this, @shrielenee . This PR expands #4082

@keharper
Copy link
Contributor

@atwixfirster please pull in the changes from this PR

#4082

@keharper keharper self-assigned this Apr 10, 2019
- in the body of test
- in test function annotation

#### Define exception message expectation in the body of test
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete one of the #s. The previous heading was a H2, so this one should be a H3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
```

#### Define expected exception message in test function annotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to a H3 as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
```

There is a list of functions which you can use to cover expected exceptions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
There is a list of functions which you can use to cover expected exceptions:
Use the following functions to cover expected exceptions:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
There is a list of functions which you can use to cover expected exceptions:
Use the following functions to cover expected exceptions:

done

```

There is a list of functions which you can use to cover expected exceptions:
- expectException
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap the functions with a text code block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrap the functions with a text code block

done

Thank you, @keharper 👍

Merge remote-tracking branch 'upstream/master' into expected-exceptions

# Conflicts:
#	guides/v2.3/graphql/functional-testing.md
@atwixfirster
Copy link
Contributor Author

@atwixfirster please pull in the changes from this PR

#4082

done

@@ -193,3 +193,128 @@ try {
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
```

## Expected exceptions
When it is necessary to cover negative test scenarios and ensure that testing elicits proper responses, define the expected exception message:
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest something like this:

Your functional tests should include events that cause exceptions. Since your tests expect an exception to occur, set up your tests so that they elicit the proper responses. You can define expected exception messages either in:

  • The body of the test
  • The test function annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented

- in the body of test
- in test function annotation

### Define exception message expectation in the body of test
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Define exception message expectation in the body of test
### Exception messages in the body of a test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

```

{:.bs-callout .bs-callout-info}
Please note that the exception message expectation should be defined before invoking a logic that generates the exception.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Please note that the exception message expectation should be defined before invoking a logic that generates the exception.
Define the exception message before invoking logic that generates the exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented

{:.bs-callout .bs-callout-info}
Please note that the exception message expectation should be defined before invoking a logic that generates the exception.

For example, if `customer A` wants to retrieve information about `customer B cart. In this situation, `customer A` will get an error - "`The current user cannot perform operations on cart "XXXXX`", where `XXXXX` - is an unique ID of `customer B` cart. See code below to understand how to cover this example with `expectExceptionMessage` function:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For example, if `customer A` wants to retrieve information about `customer B cart. In this situation, `customer A` will get an error - "`The current user cannot perform operations on cart "XXXXX`", where `XXXXX` - is an unique ID of `customer B` cart. See code below to understand how to cover this example with `expectExceptionMessage` function:
As an example, consider the case where `customer A` tries to retrieve information about `customer B`'s cart. In this situation, `customer A` will get an error:
"`The current user cannot perform operations on cart "XXXXX`"
where `XXXXX` - is an unique ID of `customer B`'s cart. The following shows how to cover this example with an `expectExceptionMessage` function:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented

}
```

### Define expected exception message in test function annotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Define expected exception message in test function annotation
### Exception messages in the annotation of a test function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

*/
```

Example: a customer wants to retrieve information about his own cart but he provides incorrect cart ID.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Example: a customer wants to retrieve information about his own cart but he provides incorrect cart ID.
In the following query, a customer provides an incorrect cart ID while trying to retrieve information about his own cart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
```

See the code below how to cover this example with `@expectExceptionMessage` annotation:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
See the code below how to cover this example with `@expectExceptionMessage` annotation:
The `@expectExceptionMessage` annotation provides the text for the exception in this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

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 very much for your review , @keharper !

@keharper
Copy link
Contributor

I built this file locally and saw that some changes to the spacing need to be made. So I did that, made a few grammatical changes, and also added Atwix as the author, since more than half of the content was contributed by your company in the last couple of weeks.

- The test function annotation

### Exception messages in the body of a test
The following examples show two ways how to define expected exception message through `expectExceptionMessage` function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The following examples show two ways how to define expected exception message through `expectExceptionMessage` function.
The following examples show two ways to define an expected exception message with the `expectExceptionMessage` function.

@keharper
Copy link
Contributor

running tests

@keharper keharper merged commit 2b42ae5 into magento:master Apr 11, 2019
@ghost
Copy link

ghost commented Apr 11, 2019

Hi @atwixfirster, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@keharper
Copy link
Contributor

Thanks for your contribution @atwixfirster

@dshevtsov
Copy link
Collaborator

@keharper the PR contains two labels to indicate the type of changes: Technical and Major update. Please use only one and add whatsnew if needed.

@dshevtsov
Copy link
Collaborator

@keharper add labels to indicate the affected versions.

@keharper keharper added 2.3.x Magento 2.3 related changes and removed Technical Updates to the code or processes that alter the technical content of the doc labels Apr 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2.3.x Magento 2.3 related changes Major Update Significant original updates to existing content Partner: Atwix partners-contribution PR created by Magento partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants