> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Functional Testing Examples

## Article: Functional Testing Examples

## Article Link: https://dev.wix.com/docs/develop-websites/articles/workspace-tools/testing-monitoring/functional-testing/functional-testing-examples.md

## Article Content:

# Functional Testing Examples

With functional testing you can easily test your backend functions individually, reducing the need to build your own system for triggering and testing your backend code. 

You can use functional testing to test a variety of scenarios, such as functions with:
- [HTTP requests](#http-requests)
- [Destructured parameters](#destructured-parameters)
- [Missing arguments](#missing-arguments)
- [JavaScript arguments objects](#javascript-arguments-objects)
- [Date objects](#date-objects)

## HTTP requests

Here is an example of a function with an HTTP request that performs basic arithmetic operations based on the request path and query parameters:

<div style="text-align:center">

<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-http.png" style="max-width:30vw"/>

</div>

To test [HTTP functions](https://www.wix.com/velo/reference/wix-http-functions) with functional testing, specify the HTTP request object in the Set Parameters section. A request template is initially created for you with placeholder data, but you need to edit it to fit your specific needs.

For example, when testing a `post` function, replace the placeholder JSON object in the `body` property with a JSON object you want to test with.

The following properties are included in the request templates:
*   For `get` and `delete` functions: `path`, `headers`, and `query`
*   For `put` and `post` functions: `path`, `headers`, and `body`
*   For `options` functions: `path` and `headers`
*   For `use` functions: `path`, `headers`, `query`, and `method`

<div style="text-align:center">

<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-http-params.png" style="max-width:60vw"/>
</div>

## Destructured parameters

Destructuring allows you to extract values from arrays or properties from objects into distinct variables. Here is an example of a function that destructures the parameters `{ factor1, factor2 }` directly from the passed object and returns their product:

<div style="text-align:center">

<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-destructured.png" style="max-width:30vw"/>
</div>

To test a function with destructured parameters, place parameter values in a JSON object inside an array:

<div style="text-align:center">

<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-destructured-params.png" style="max-width:60vw"/>
</div>

## Missing arguments

When you set default values in your function declarations, you can test those functions without needing to provide all of the arguments. Here is an example of a function that uses default values for `factor2` and `factor3`. 

<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-default.png" style="max-width:30vw"/>
</div>


To test a function without providing all of the arguments, place the arguments in an array in the Set Parameters section, and leave out at least one of the arguments that has a default value.

For example, the `multiplyWithDefaults()` function above was tested three times with the following arguments:

*   [1,2,3]
*   [1,2]
*   [1]

The following results were returned:

*   1 * 2 * 3 = 6
*   1 * 2 * 2 = 4
*   1 * -1 * 2 = -2

<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-default-params.png" style="max-width:60vw"/>
</div>


## JavaScript 'arguments' objects

The JavaScript [arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object can accept any number of arguments in a function. Here is an example of a function that uses the arguments object to find the sum of all the arguments provided.

<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-args.png" style="max-width:30vw"/>
</div>

To test a function containing the JavaScript [arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object, place the arguments in an array in the Set Parameters section:


<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-args-params.png" style="max-width:60vw"/>
</div>

## Date objects

Here is an example of a function that takes a Date object as the parameter:

<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-dateobj.png" style="max-width:30vw"/>
</div>

To test a function with a parameter of type **Date**, you need to use a [stringified date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) in the JSON object. You can use one of the following syntaxes:

```javascript
{
  "date": {
    "$date": "<myStringifiedDate>"
  }
}
```

```javascript
[
  {
    "$date": "<myStringifiedDate>"
  }
]
```

<div style="text-align:center">
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/functional-testing-examples-md_velo-articles_testing-and-troubleshooting_images_functional-testing-date-params.png" style="max-width:60vw"/>
</div>

## See also
- [About Functional Testing](https://dev.wix.com/docs/develop-websites/articles/workspace-tools/testing-monitoring/functional-testing/about-functional-testing.md)
- [Test Backend Functions with Functional Testing](https://dev.wix.com/docs/develop-websites/articles/workspace-tools/testing-monitoring/functional-testing/test-backend-functions-with-functional-testing.md)