Add HTTP Check to MailmanTypeRequest
This commit is contained in:
parent
b190a4aecf
commit
e67325e643
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\RequestFactories;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
||||
class MailmanTypeRequest extends RequestFactory
|
||||
|
@ -15,4 +16,37 @@ class MailmanTypeRequest extends RequestFactory
|
|||
'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