# $atMost()

This method can help you verify that at most a maximum number of calls have been made to all mocked methods or a specific mocked method.

```javascript
Boolean $atLeast(minNumberOfInvocations,[methodname])
```

Parameters:

* maxNumberOfInvocations - The max number of calls to assert
* methodName - The optional method name to assert the number of method calls

Examples:

```javascript
// let's say we have a service that verifies user credentials
// and if not valid, then tries to check if the user can be inflated from a cookie
// and then verified again
function verifyUser(){

    if( isValidUser() ){
        log.info("user is valid, doing valid operations");
    }

    // check if user cookie exists
    if( isUserCookieValid() ){
        // inflate credentials
        inflateUserFromCookie();
        // Validate them again
        if( NOT isValidUser() ){
            log.error("user from cookie invalid, aborting");
        }
    }
}

// Now the test
it( "can verify a user", function(){
    security = createMock("model.security").$("isValidUser",false);
    security.storeUserCookie("valid");
    security.verifyUser();

    // Asserts that isValidUser() has been called at most 1 times
    expect( security.$atMost(1,"isValidUser") ).toBeFalse();
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://testbox.ortusbooks.com/v2.x-1/mocking/mockbox/verification-methods/usdatmost.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
