-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09db0b8
commit 273cf40
Showing
14 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class FormSessionWebhook extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $guarded = []; | ||
} |
28 changes: 28 additions & 0 deletions
28
database/migrations/2023_04_07_173653_create_form_session_webhooks_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use App\Models\FormSession; | ||
use App\Models\FormWebhook; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('form_session_webhooks', function (Blueprint $table) { | ||
$table->id(); | ||
$table->integer('status')->nullable(); | ||
$table->json('response')->nullable(); | ||
$table->integer('tries')->default(0); | ||
$table->foreignIdFor(FormSession::class); | ||
$table->foreignIdFor(FormWebhook::class); | ||
$table->timestamps(); | ||
|
||
// make form_session_id and form_webhook_id unique, so we can't have duplicate entries | ||
$table->unique(['form_session_id', 'form_webhook_id']); | ||
}); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* Style */ | ||
.v-popper--theme-tooltip .v-popper__inner { | ||
background: #1e293b; | ||
color: #ffffff; | ||
padding: 3px 12px; | ||
border-radius: 6px; | ||
} | ||
|
||
.v-popper--theme-tooltip .v-popper__arrow-outer { | ||
border-color: #1e293b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
resources/js/components/Factory/Submissions/SubmissionWebhookStatus.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
<div class="inline-flex cursor-pointer items-center" v-tooltip="'200 OK'"> | ||
<span class="mr-1 inline-block h-3 w-3 rounded-full bg-green-400"></span> | ||
<span>{{ name }}</span> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
defineProps<{ | ||
name: string; | ||
}>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
use App\Models\Form; | ||
use App\Models\FormSession; | ||
use App\Models\FormWebhook; | ||
use App\Jobs\CallWebhookJob; | ||
use Illuminate\Support\Facades\Http; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
uses(RefreshDatabase::class); | ||
|
||
it('can create a database entry for a session and configured form webhook response', function () { | ||
Http::fake(); | ||
|
||
$form = Form::factory()->has( | ||
FormWebhook::factory() | ||
)->create(); | ||
$session = FormSession::factory()->for($form)->create(); | ||
|
||
CallWebhookJob::dispatch($session, $form->formWebhooks->first()); | ||
|
||
$this->assertDatabaseHas('form_session_webhooks', [ | ||
'form_session_id' => $session->id, | ||
'form_webhook_id' => $form->formWebhooks->first()->id, | ||
'status' => 200, | ||
'tries' => 1, | ||
]); | ||
|
||
Http::assertSentCount(1); | ||
}); | ||
|
||
it('will use the same database entry if a webhook gets called twice for the same session', function () { | ||
Http::fake(); | ||
|
||
$form = Form::factory()->has( | ||
FormWebhook::factory() | ||
)->create(); | ||
$session = FormSession::factory()->for($form)->create(); | ||
|
||
CallWebhookJob::dispatch($session, $form->formWebhooks->first()); | ||
CallWebhookJob::dispatch($session, $form->formWebhooks->first()); | ||
|
||
$this->assertDatabaseHas('form_session_webhooks', [ | ||
'form_session_id' => $session->id, | ||
'form_webhook_id' => $form->formWebhooks->first()->id, | ||
'status' => 200, | ||
'tries' => 2, | ||
]); | ||
|
||
Http::assertSentCount(2); | ||
}); | ||
|
||
it('submissions api endpoint will include the session webhook data', function () { | ||
Http::fake(function () { | ||
return Http::response('OK!', 200); | ||
}); | ||
|
||
$form = Form::factory()->has( | ||
FormWebhook::factory() | ||
)->create(); | ||
$session = FormSession::factory()->for($form)->completed()->create(); | ||
|
||
CallWebhookJob::dispatch($session, $form->formWebhooks->first()); | ||
|
||
$response = $this->actingAs($form->user) | ||
->json('get', route('api.forms.submissions', ['form' => $form->uuid])) | ||
->assertStatus(200); | ||
|
||
$response->assertJson([ | ||
'data' => [ | ||
[ | ||
'webhooks' => [ | ||
[ | ||
'response' => 'OK!', | ||
'status' => 200, | ||
'tries' => 1, | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
}); |
Oops, something went wrong.