Add HTTP Check to MailmanTypeRequest
This commit is contained in:
parent
b8eabaa501
commit
7be0ab1c82
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\RequestFactories;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
||||
class MailmanTypeRequest extends RequestFactory
|
||||
|
@ -9,10 +10,43 @@ class MailmanTypeRequest extends RequestFactory
|
|||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'url' => 'https://'.$this->faker->domainName(),
|
||||
'url' => 'https://' . $this->faker->domainName(),
|
||||
'user' => $this->faker->firstName(),
|
||||
'password' => $this->faker->password(),
|
||||
'owner' => $this->faker->safeEmail(),
|
||||
];
|
||||
}
|
||||
|
||||
public function succeeds($overwrite = []): self
|
||||
{
|
||||
return $this->afterCreating(fn ($model) => $this->fakeCheck([...$model, ...$overwrite], true));
|
||||
}
|
||||
|
||||
public function fails($overwrite = []): self
|
||||
{
|
||||
return $this->afterCreating(fn ($model) => $this->fakeCheck([...$model, ...$overwrite], false));
|
||||
}
|
||||
|
||||
protected function fakeCheck($model, bool $check): void
|
||||
{
|
||||
Http::fake(function ($request) use ($model, $check) {
|
||||
if (!$request->hasHeader('Authorization')) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$user, $password] = explode(':', base64_decode(str($request->header('Authorization')[0])->replace('Basic ', '')->toString()));
|
||||
|
||||
if ($user !== $model['user'] || $password !== $model['password']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($request->url() !== $model['url'] . '/system/versions') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $check
|
||||
? Http::response(['version' => '2.0.0'], 200)
|
||||
: Http::response([], 401);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue