zapier improvements (#532)

* zapier improvements

* Fix test case

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2024-08-19 19:04:01 +05:30 committed by GitHub
parent 7ac8503201
commit 943e906c86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 18 additions and 23 deletions

View File

@ -18,15 +18,13 @@ class PollSubmissionRequest extends FormRequest
return [ return [
'form_id' => [ 'form_id' => [
'required', 'required',
Rule::exists(Form::getModel()->getTable(), 'slug'), Rule::exists(Form::getModel()->getTable(), 'id'),
], ],
]; ];
} }
public function form(): Form public function form(): Form
{ {
return Form::query() return Form::findOrFail($this->input('form_id'));
->where('slug', $this->input('form_id'))
->firstOrFail();
} }
} }

View File

@ -13,7 +13,7 @@ class CreateIntegrationRequest extends FormRequest
return [ return [
'form_id' => [ 'form_id' => [
'required', 'required',
Rule::exists(Form::getModel()->getTable(), 'slug'), Rule::exists(Form::getModel()->getTable(), 'id'),
], ],
'hookUrl' => [ 'hookUrl' => [
'required', 'required',
@ -24,8 +24,6 @@ class CreateIntegrationRequest extends FormRequest
public function form(): Form public function form(): Form
{ {
return Form::query() return Form::findOrFail($this->input('form_id'));
->where('slug', $this->input('form_id'))
->firstOrFail();
} }
} }

View File

@ -13,7 +13,7 @@ class DeleteIntegrationRequest extends FormRequest
return [ return [
'form_id' => [ 'form_id' => [
'required', 'required',
Rule::exists(Form::getModel()->getTable(), 'slug'), Rule::exists(Form::getModel()->getTable(), 'id'),
], ],
'hookUrl' => [ 'hookUrl' => [
'required', 'required',
@ -24,8 +24,6 @@ class DeleteIntegrationRequest extends FormRequest
public function form(): Form public function form(): Form
{ {
return Form::query() return Form::findOrFail($this->input('form_id'));
->where('slug', $this->input('form_id'))
->firstOrFail();
} }
} }

View File

@ -12,8 +12,9 @@ class FormResource extends JsonResource
public function toArray($request) public function toArray($request)
{ {
return [ return [
'id' => $this->resource->slug, 'id' => $this->resource->id,
'name' => $this->resource->title, 'name' => $this->resource->title,
'label' => $this->resource->title . ' (' . $this->resource->slug . ')'
]; ];
} }
} }

View File

@ -37,7 +37,7 @@ module.exports = {
key: 'form_id', key: 'form_id',
type: 'string', type: 'string',
label: 'Form', label: 'Form',
dynamic: 'list_forms.id.name', dynamic: 'list_forms.id.label',
required: true, required: true,
list: false, list: false,
altersDynamicFields: false, altersDynamicFields: false,

View File

@ -23,7 +23,7 @@ test('create an integration', function () {
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
post(route('zapier.webhooks.store'), [ post(route('zapier.webhooks.store'), [
'form_id' => $form->slug, 'form_id' => $form->id,
'hookUrl' => $hookUrl = 'https://zapier.com/hook/test' 'hookUrl' => $hookUrl = 'https://zapier.com/hook/test'
]) ])
->assertOk(); ->assertOk();
@ -45,7 +45,7 @@ test('cannot create an integration without a corresponding ability', function ()
Sanctum::actingAs($user); Sanctum::actingAs($user);
post(route('zapier.webhooks.store'), [ post(route('zapier.webhooks.store'), [
'form_id' => $form->slug, 'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test' 'hookUrl' => 'https://zapier.com/hook/test'
]) ])
->assertForbidden(); ->assertForbidden();
@ -64,7 +64,7 @@ test('cannot create an integration for other users form', function () {
Sanctum::actingAs($user); Sanctum::actingAs($user);
post(route('zapier.webhooks.store'), [ post(route('zapier.webhooks.store'), [
'form_id' => $form->slug, 'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test' 'hookUrl' => 'https://zapier.com/hook/test'
]) ])
->assertForbidden(); ->assertForbidden();
@ -94,7 +94,7 @@ test('delete an integration', function () {
assertDatabaseCount('form_integrations', 1); assertDatabaseCount('form_integrations', 1);
delete(route('zapier.webhooks.destroy', $integration), [ delete(route('zapier.webhooks.destroy', $integration), [
'form_id' => $form->slug, 'form_id' => $form->id,
'hookUrl' => $hookUrl, 'hookUrl' => $hookUrl,
]) ])
->assertOk(); ->assertOk();
@ -122,7 +122,7 @@ test('cannot delete an integration with an incorrect hook url', function () {
]); ]);
delete(route('zapier.webhooks.destroy', $integration), [ delete(route('zapier.webhooks.destroy', $integration), [
'form_id' => $form->slug, 'form_id' => $form->id,
'hookUrl' => 'https://google.com', 'hookUrl' => 'https://google.com',
]) ])
->assertOk(); ->assertOk();
@ -178,7 +178,7 @@ test('poll for the latest submission', function () {
Sanctum::actingAs($user, ['view', 'manage-integrations']); Sanctum::actingAs($user, ['view', 'manage-integrations']);
// Call the poll endpoint // Call the poll endpoint
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug])); $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
// Assert the response status is OK // Assert the response status is OK
$response->assertOk(); $response->assertOk();
@ -229,7 +229,7 @@ test('make up a submission when polling without any submission', function () {
// Call the poll endpoint // Call the poll endpoint
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug])); $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
// Assert the response status is OK // Assert the response status is OK
$response->assertOk(); $response->assertOk();

View File

@ -22,11 +22,11 @@ test('list all forms of a given workspace', function () {
->assertJsonCount(2) ->assertJsonCount(2)
->assertJson([ ->assertJson([
[ [
'id' => $form1->slug, 'id' => $form1->id,
'name' => $form1->title, 'name' => $form1->title,
], ],
[ [
'id' => $form2->slug, 'id' => $form2->id,
'name' => $form2->title, 'name' => $form2->title,
], ],
]); ]);