Skip to content

Commit

Permalink
ok the run is there not show how to guaratee a return type yet to sho…
Browse files Browse the repository at this point in the history
…w in the output
  • Loading branch information
alnutile committed Jun 11, 2023
1 parent fb4ee51 commit 4d13c0c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/Sources/WebHookSourceController.php
Expand Up @@ -78,20 +78,21 @@ public function update(Project $project, Source $source)
]);
}

public function webhook(Project $project, Source $source) {
public function webhook(Project $project, Source $source)
{
/**
* @TODO
* Security
* Allow to dump into queue
* Allow to return any response
*/
$payload = request()->all();
logger("Webhook coming in", $payload);
logger('Webhook coming in', $payload);
/**
* Do something with the incoming data
*/
$response = $source->run($payload);

return response()->json("OK", 200);
return response()->json('OK', 200);
}
}
3 changes: 2 additions & 1 deletion app/Models/Source.php
Expand Up @@ -50,6 +50,7 @@ public function run(array $payload = [])
{
try {
$sourceType = $this->getSourceTypeClass();

return $sourceType->setPayload($payload)->handle();
} catch (\Exception $e) {
logger($e);
Expand All @@ -62,7 +63,7 @@ public function getTypeFormattedAttribute()
return str($this->type->value)->headline();
}

protected function getSourceTypeClass() : BaseSourceType | \Exception
protected function getSourceTypeClass(): BaseSourceType|\Exception
{
$statusTypes = config('larachain.sources');
$statusType = $this->type->value;
Expand Down
1 change: 0 additions & 1 deletion routes/api.php
Expand Up @@ -20,7 +20,6 @@
[WebHookSourceController::class, 'webhook'])
->name('api.sources.webhook');


Route::middleware('auth:sanctum')
->get('/outbounds/{outbound}/response_types/{response_type}/chat_api',
[ChatApiResponseTypeController::class, 'api'])
Expand Down
Expand Up @@ -117,13 +117,14 @@ public function testCreateWebHook()
$this->assertDatabaseCount('sources', 1);
}

public function test_api() {
public function test_api()
{
Http::fake();
$data = get_fixture("github_webhook.json");
$data = get_fixture('github_webhook.json');
$source = Source::factory()->webFileMetaData()->create();
$this->post(route('api.sources.webhook', [
'project' => $source->project_id,
'source' => $source->id
'source' => $source->id,
]), $data)
->assertStatus(200);

Expand Down
1 change: 0 additions & 1 deletion tests/Feature/Models/SourceTest.php
Expand Up @@ -23,7 +23,6 @@ public function test_project_rel()
$this->assertNotNull($model->project->sources()->first()->id);
}


public function test_run_source_type()
{
Http::fake();
Expand Down

0 comments on commit 4d13c0c

Please sign in to comment.