ARCANEDEV / noCAPTCHA

:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

Repository from Github https://github.comARCANEDEV/noCAPTCHARepository from Github https://github.comARCANEDEV/noCAPTCHA

Laravel Dusk Testing not working

Morinohtar opened this issue · comments

  • noCaptcha Version: 13.0.0
  • Laravel Version: 9.9
  • PHP Version: 8.1

Using Vue for the form submission.

Also left the same comment in a topic that was already closed #39

Cant seem to make the test work with Dusk, though the Feature Test works fine.
Dont think the mock is working in Dusk...

If i log the response from the rule, it spits this:

`{"Arcanedev\\NoCaptcha\\Utilities\\ResponseV2":{"success":false,"hostname":null,"challenge_ts":null,"apk_package_name":null,"error-codes":["invalid-input-response"]}}`

So, the rule response comes as false.

Code:

    protected function ignoreCaptcha(string $name = 'g-recaptcha-response'): void
    {
        NoCaptchaFacade::shouldReceive('display')
            ->andReturn('<input type="textarea"  value="anything, really" name="' . $name . '">');
            
        NoCaptchaFacade::shouldReceive('script')
            ->andReturn('<script src="captcha.js"></script>');
            
        NoCaptchaFacade::shouldReceive('verify')
            ->andReturn(NoCaptchaFacade::getFacadeRoot());
            
        NoCaptchaFacade::shouldReceive('isSuccess')
            ->andReturn(true);
    }

    /** @test */
    public function it_submits_contact_form()
    {
        $this->ignoreCaptcha();

        $this->browse(function (Browser $browser) {
            $browser->visitRoute('contact')
                ->type('name', $this->faker->name)
                ->type('email', $this->faker->safeEmail)
                ->type('message', $this->faker->paragraphs(3, true))
                ->fillHidden('g-recaptcha-response', '1')
                ->pressAndWaitFor('Submit', 3)
                ->assertSee('Message sent!');
        });
    }