Add HTTP Check to MailmanTypeRequest
This commit is contained in:
parent
2871a90847
commit
85c0727b72
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\RequestFactories;
|
namespace Tests\RequestFactories;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Worksome\RequestFactories\RequestFactory;
|
use Worksome\RequestFactories\RequestFactory;
|
||||||
|
|
||||||
class MailmanTypeRequest extends RequestFactory
|
class MailmanTypeRequest extends RequestFactory
|
||||||
|
@ -9,10 +10,43 @@ class MailmanTypeRequest extends RequestFactory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'url' => 'https://'.$this->faker->domainName(),
|
'url' => 'https://' . $this->faker->domainName(),
|
||||||
'user' => $this->faker->firstName(),
|
'user' => $this->faker->firstName(),
|
||||||
'password' => $this->faker->password(),
|
'password' => $this->faker->password(),
|
||||||
'owner' => $this->faker->safeEmail(),
|
'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