0

I'm trying to test an API that requires users to be logged in via Laravel through the web. Javascript will be accessing a REST API with a CSRF token. When I try to test this using Codeception it seems like the authentication is not being recognized with the sendPOST call.

I'm using the following Modules in my Api Suite:

modules:
    enabled:
        - Laravel5
        - \Helper\Api
        - REST:
              depends: PhpBrowser
              url: http://app.dev/api/

Here is my test:

public function verifyFileIsRequired(ApiTester $I)
{
    $I->amLoggedAs($this->user);
    $I->sendPOST(self::URL_GOES_HERE);
    $I->seeResponseCodeIs(422);
}

I keep getting a 401 response code. I have a feeling that this is due to the sendPOST method not sending the Laravel session info. Is there a way to make this work?

Thanks!

3
  • 1
    You could use codeception.com/docs/modules/Laravel5#sendAjaxPostRequest instead Commented Jun 27, 2016 at 16:32
  • That seems to work well! As long as the REST module is disabled. Is there any reason to use the REST module & the Laravel5 module? Commented Jun 27, 2016 at 16:56
  • 1
    REST module has useful methods for inspecting JSON and XML responses. Commented Jun 27, 2016 at 17:00

1 Answer 1

1

Naktibalda pointed me in the right direction to get this solved. Posting answer incase someone else runs into this problem.

In my api.suite.yml I should have had REST module depend on Laravel5.

modules:
    enabled:
        - Laravel5
        - \Helper\Api
        - REST:
            depends: Laravel5    <-- this was the fix
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.