Skip to content

Commit eff21ef

Browse files
committed
Rename the routes file to api and enable the storing of the hooks data
1 parent de4be0b commit eff21ef

File tree

7 files changed

+34
-8
lines changed

7 files changed

+34
-8
lines changed

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
bootstrap="vendor/autoload.php"
55
cacheResultFile=".phpunit.cache/test-results"
66
executionOrder="depends,defects"
7-
forceCoversAnnotation="true"
87
beStrictAboutCoversAnnotation="true"
98
beStrictAboutOutputDuringTests="true"
109
beStrictAboutTodoAnnotatedTests="true"
File renamed without changes.

src/Actions/StoreInComingWebhookRequestData.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
use Illuminate\Support\Arr;
88
use JsonException;
9+
use TJVB\GitLabWebhooks\Contracts\Actions\InComingWebhookRequestStoring;
910
use TJVB\GitLabWebhooks\Exceptions\InvalidInputException;
1011
use TJVB\GitLabWebhooks\Http\Requests\GitLabWebhookRequest;
1112
use TJVB\GitLabWebhooks\Models\GitLabHook;
1213

13-
class StoreInComingWebhookRequestData implements \TJVB\GitLabWebhooks\Contracts\Actions\InComingWebhookRequestStoring
14+
class StoreInComingWebhookRequestData implements InComingWebhookRequestStoring
1415
{
1516

1617
public function handle(GitLabWebhookRequest $request): void
@@ -21,11 +22,11 @@ public function handle(GitLabWebhookRequest $request): void
2122
} catch (JsonException $jsonException) {
2223
throw InvalidInputException::fromJsonException($jsonException);
2324
}
24-
$hook = $this->createHook();
25+
$hook = $this->createHook($body, $request);
2526
unset($hook);
2627
}
2728

28-
private function createHook(string $body, GitLabWebhookRequest $request)
29+
private function createHook(array $body, GitLabWebhookRequest $request)
2930
{
3031
$data = [
3132
'body' => $body,

src/GitLabWebhooksServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function boot(): void
2121
__DIR__ . '/../database/migrations/' => database_path('migrations')
2222
], 'migrations');
2323

24-
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
24+
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
2525
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
2626

2727
if ($this->app->runningInConsole()) {

src/Models/GitLabHook.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ class GitLabHook extends Model
1111
{
1212
use SoftDeletes;
1313

14+
/**
15+
* The attributes that should be cast.
16+
*
17+
* @var array
18+
*/
19+
protected $casts = [
20+
'body' => 'array',
21+
'system_hook' => 'boolean',
22+
];
23+
1424
/**
1525
* The attributes that are mass assignable.
1626
*

tests/TestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@ protected function getPackageProviders($app): array
1515
GitLabWebhooksServiceProvider::class,
1616
];
1717
}
18+
19+
protected function getEnvironmentSetUp($app): void
20+
{
21+
# Setup default database to use sqlite :memory:
22+
$app['config']->set('database.default', 'testbench');
23+
$app['config']->set('database.connections.testbench', [
24+
'driver' => 'sqlite',
25+
'database' => ':memory:',
26+
'prefix' => '',
27+
]);
28+
}
1829
}

tests/WebhookReceiverTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
namespace TJVB\GitLabWebhooks\Tests;
66

7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
use Illuminate\Http\Response;
9+
710
class WebhookReceiverTest extends TestCase
811
{
12+
use DatabaseMigrations;
913

1014
/**
1115
* @test
@@ -23,20 +27,21 @@ public function weCanStoreAValidRequest(): void
2327
/**
2428
* @test
2529
*/
26-
public function weGetABadRequestIfWeHaveInvallidData(): void
30+
public function weGetABadRequestIfWeHaveInvalidData(): void
2731
{
28-
$this->markTestIncomplete('TODO');
2932
// setup / mock
3033

3134
// run
35+
$response = $this->post(config('gitlab-webhooks-receiver.url', '/gitlabwebhook'), ['invalidjson']);
3236

3337
// verify/assert
38+
$response->assertStatus(Response::HTTP_BAD_REQUEST);
3439
}
3540

3641
/**
3742
* @test
3843
*/
39-
public function weGetAnInternalServerErrorIfWeHaveAnUnkownError(): void
44+
public function weGetAnInternalServerErrorIfWeHaveAnUnknownError(): void
4045
{
4146
$this->markTestIncomplete('TODO');
4247
// setup / mock

0 commit comments

Comments
 (0)