update/expand core tests and api readmes
This commit is contained in:
parent
34ef87acd3
commit
ed4f3af997
|
@ -49,11 +49,19 @@ httpClient.get( '/wc/v3/products' ).then( ( response ) => {
|
|||
|
||||
### Repositories
|
||||
|
||||
As a convenience utility we've created repositories for core data types that can simplify interacting with the API.
|
||||
As a convenience utility we've created repositories for core data types that can simplify interacting with the API:
|
||||
|
||||
- `SimpleProduct`
|
||||
- `ExternalProduct`
|
||||
- `GroupedProduct`
|
||||
- `VariableProduct`
|
||||
- `ProductVariation`
|
||||
- `Coupon`
|
||||
|
||||
These repositories provide CRUD methods for ease-of-use:
|
||||
|
||||
```javascript
|
||||
import { SimpleProduct } from '@woocommerce/api';
|
||||
import { HTTPClientFactory, SimpleProduct } from '@woocommerce/api';
|
||||
|
||||
// Prepare the HTTP client that will be consumed by the repository.
|
||||
// This is necessary so that it can make requests to the REST API.
|
||||
|
@ -68,5 +76,86 @@ const product = repository.create( { name: 'Simple Product', regularPrice: '9.99
|
|||
|
||||
// The response will be one of the models with structured properties and TypeScript support.
|
||||
product.id;
|
||||
|
||||
```
|
||||
|
||||
#### Repository Methods
|
||||
|
||||
The following methods are available on all repositories:
|
||||
|
||||
- `create( {...properties} )` - Create a single object of the model type
|
||||
- `delete( objectId )` - Delete a single object of the model type
|
||||
- `list` - Retrieve a list of the existing objects of that model type
|
||||
- `read( objectId )` - Read a single object of the model type
|
||||
- `update( objectId, {...properties} )` - Update a single object of the model type
|
||||
|
||||
#### Child Repositories
|
||||
|
||||
`ProductVariation` is a child model repository. In child model repositories, each method requires the `parentId` as the first parameter:
|
||||
|
||||
```javascript
|
||||
import { HTTPClientFactory, VariableProduct, ProductVariation } from '@woocommerce/api';
|
||||
|
||||
const httpClient = HTTPClientFactory.build( 'https://example.com' )
|
||||
.withBasicAuth( 'username', 'password' )
|
||||
.withIndexPermalinks()
|
||||
.create();
|
||||
|
||||
const productRepository = VariableProduct.restRepository( httpClient );
|
||||
const variationRepository = ProductVariation.restRepository( httpClient );
|
||||
|
||||
const product = await productRepository.create({
|
||||
"name": "Variable Product with Three Attributes",
|
||||
"defaultAttributes": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Size",
|
||||
"option": "Medium"
|
||||
},
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Colour",
|
||||
"option": "Blue"
|
||||
}
|
||||
],
|
||||
"attributes": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Colour",
|
||||
"isVisibleOnProductPage": true,
|
||||
"isForVariations": true,
|
||||
"options": [
|
||||
"Red",
|
||||
"Green",
|
||||
"Blue"
|
||||
],
|
||||
"sortOrder": 0
|
||||
},
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Size",
|
||||
"isVisibleOnProductPage": true,
|
||||
"isForVariations": true,
|
||||
"options": [
|
||||
"Small",
|
||||
"Medium",
|
||||
"Large"
|
||||
],
|
||||
"sortOrder": 0
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const variation = await variationRepository.create( product.id, {
|
||||
"regularPrice": "19.99",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "Size",
|
||||
"option": "Large"
|
||||
},
|
||||
{
|
||||
"name": "Colour",
|
||||
"option": "Red"
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
|
|
@ -45,20 +45,20 @@ The functions to access the core tests are:
|
|||
### Merchant
|
||||
|
||||
- `runMerchantTests` - Run all merchant tests
|
||||
- `runCreateCouponTest` - Merchant can create coupon
|
||||
- `runCreateOrderTest` - Merchant can create order
|
||||
- `runAddSimpleProductTest` - Merchant can create a simple product
|
||||
- `runAddVariableProductTest` - Merchant can create a variable product
|
||||
- `runUpdateGeneralSettingsTest` - Merchant can update general settings
|
||||
- `runProductSettingsTest` - Merchant can update product settings
|
||||
- `runTaxSettingsTest` - Merchant can update tax settings
|
||||
- `runCreateCouponTest` - Merchant can create coupon
|
||||
- `runCreateOrderTest` - Merchant can create order
|
||||
- `runMerchantOrdersCustomerPaymentPage` - Merchant can visit the customer payment page
|
||||
- `runMerchantOrderEmailsTest` - Merchant can receive order emails and resend emails by Order Actions
|
||||
- `runOrderStatusFilterTest` - Merchant can filter orders by order status
|
||||
- `runOrderRefundTest` - Merchant can refund an order
|
||||
- `runOrderApplyCouponTest` - Merchant can apply a coupon to an order
|
||||
- `runProductEditDetailsTest` - Merchant can edit an existing product
|
||||
- `runProductSearchTest` - Merchant can search for a product and view it
|
||||
- `runMerchantOrdersCustomerPaymentPage` - Merchant can visit the customer payment page
|
||||
- `runMerchantOrderEmailsTest` - Merchant can receive order emails and resend emails by Order Actions
|
||||
- `runProductSettingsTest` - Merchant can update product settings
|
||||
- `runTaxSettingsTest` - Merchant can update tax settings
|
||||
- `runUpdateGeneralSettingsTest` - Merchant can update general settings
|
||||
|
||||
### Shopper
|
||||
|
||||
|
@ -68,13 +68,20 @@ The functions to access the core tests are:
|
|||
- `runCheckoutApplyCouponsTest` - Shopper can use coupons on checkout
|
||||
- `runCheckoutPageTest` - Shopper can complete checkout
|
||||
- `runMyAccountPageTest` - Shopper can access my account page
|
||||
- `runSingleProductPageTest` - Shopper can view single product page in many variations (simple, variable, grouped)
|
||||
- `runMyAccountPayOrderTest` - Shopper can pay for his order in My Account
|
||||
- `runCartApplyCouponsTest` - Shopper can apply coupons in the cart
|
||||
- `runCheckoutApplyCouponsTest` - Shopper can apply coupons in the checkout
|
||||
- `runMyAccountPayOrderTest` - Shopper can pay for their order in My Account
|
||||
- `runProductBrowseSearchSortTest` - Shopper can browse, search & sort products
|
||||
- `runSingleProductPageTest` - Shopper can view single product page in many variations (simple, variable, grouped)
|
||||
- `runVariableProductUpdateTest` - Shopper can view and update variations on a variable product
|
||||
|
||||
### REST API
|
||||
|
||||
- `runApiTests` - Run all API tests
|
||||
- `runExternalProductAPITest` - Can create, read, and delete an external product
|
||||
- `runGroupedProductAPITest` - Can create, read, and delete a grouped product
|
||||
- `runVariableProductAPITest` - Can create, read, and delete a variable product and its variations
|
||||
- `runCouponApiTest` - Can create, read, and delete a coupon
|
||||
|
||||
|
||||
## Contributing a new test
|
||||
|
||||
- In your branch create a new `example-test-name.test.js` under the `tests/e2e/core-tests/specs` folder.
|
||||
|
|
Loading…
Reference in New Issue