我已经用 Laravel 设置了一个 Nuxt 应用程序,在做太多之前我想设置 Dusk 测试。该应用程序/登录名运行良好,但我无法使其在自动化 Dusk 测试中运行。
它使用lighthouse-graphql-passport-auth和此处描述的设置。我认为问题可能与 Dusk 环境中的令牌生成有关。
这是我无法进行的示例测试:
public function testWithLoggedIn()
{
$user = factory(User::class)->create([
'email' => 'test@dusk.com',
'password' => bcrypt('test'),
]);
$this->browse(function ($browser) use ($user) {
$browser->visit('/login')
->type('username', $user->email)
->type('password', 'test')
->press('Login')
->assertSee('Hello First User');
});
}
所以我已经尝试了一些东西。例如,如果我在setUp()方法中添加它:
$this->artisan('passport:install');
$client = Client::findOrFail(2);
config()->set('lighthouse-graphql-passport.client_id', 2);
config()->set('lighthouse-graphql-passport.client_secret', $client->secret);
我收到此错误:
Error: GraphQL error: Client authentication failed
我还尝试为 oauth_clients 添加与本地相同的信息。不幸的是,重定向是不同的(' http://local.test '用于本地,' http://apache '在黄昏测试时)。
DB::table('oauth_clients')->insert([
'id' => 2,
'name' => 'Apps Password Grant Client',
'secret' => 'SWjOP5Y8NzxEx7z3dlaVs08VDUWgrSl96l4V9JO3',
'redirect' => 'http://apache',
'personal_access_client' => 0,
'password_client' => 1,
'revoked' => 0,
'created_at' => '2020-02-17 11:02:33',
'updated_at' => '2020-02-17 11:02:33',
]);
这会返回这种错误:
Error: GraphQL error: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.
我应该如何测试这个应用程序?一切都将在此登录屏幕后面,因此可能有一种方法,如果需要,我可以更改登录方法(可能不使用护照)。