Skip to content

Commit

Permalink
zapier improvements (#532)
Browse files Browse the repository at this point in the history
* zapier improvements

* Fix test case

---------

Co-authored-by: Julien Nahum <[email protected]>
  • Loading branch information
chiragchhatrala and JhumanJ authored Aug 19, 2024
1 parent 7ac8503 commit 943e906
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public function rules(): array
return [
'form_id' => [
'required',
Rule::exists(Form::getModel()->getTable(), 'slug'),
Rule::exists(Form::getModel()->getTable(), 'id'),
],
];
}

public function form(): Form
{
return Form::query()
->where('slug', $this->input('form_id'))
->firstOrFail();
return Form::findOrFail($this->input('form_id'));
}
}
6 changes: 2 additions & 4 deletions app/Http/Requests/Zapier/CreateIntegrationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function rules()
return [
'form_id' => [
'required',
Rule::exists(Form::getModel()->getTable(), 'slug'),
Rule::exists(Form::getModel()->getTable(), 'id'),
],
'hookUrl' => [
'required',
Expand All @@ -24,8 +24,6 @@ public function rules()

public function form(): Form
{
return Form::query()
->where('slug', $this->input('form_id'))
->firstOrFail();
return Form::findOrFail($this->input('form_id'));
}
}
6 changes: 2 additions & 4 deletions app/Http/Requests/Zapier/DeleteIntegrationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function rules()
return [
'form_id' => [
'required',
Rule::exists(Form::getModel()->getTable(), 'slug'),
Rule::exists(Form::getModel()->getTable(), 'id'),
],
'hookUrl' => [
'required',
Expand All @@ -24,8 +24,6 @@ public function rules()

public function form(): Form
{
return Form::query()
->where('slug', $this->input('form_id'))
->firstOrFail();
return Form::findOrFail($this->input('form_id'));
}
}
3 changes: 2 additions & 1 deletion app/Http/Resources/Zapier/FormResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class FormResource extends JsonResource
public function toArray($request)
{
return [
'id' => $this->resource->slug,
'id' => $this->resource->id,
'name' => $this->resource->title,
'label' => $this->resource->title . ' (' . $this->resource->slug . ')'
];
}
}
2 changes: 1 addition & 1 deletion integrations/zapier/triggers/new_submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
key: 'form_id',
type: 'string',
label: 'Form',
dynamic: 'list_forms.id.name',
dynamic: 'list_forms.id.label',
required: true,
list: false,
altersDynamicFields: false,
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/Zapier/IntegrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

$this->withoutExceptionHandling();
post(route('zapier.webhooks.store'), [
'form_id' => $form->slug,
'form_id' => $form->id,
'hookUrl' => $hookUrl = 'https://zapier.com/hook/test'
])
->assertOk();
Expand All @@ -45,7 +45,7 @@
Sanctum::actingAs($user);

post(route('zapier.webhooks.store'), [
'form_id' => $form->slug,
'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test'
])
->assertForbidden();
Expand All @@ -64,7 +64,7 @@
Sanctum::actingAs($user);

post(route('zapier.webhooks.store'), [
'form_id' => $form->slug,
'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test'
])
->assertForbidden();
Expand Down Expand Up @@ -94,7 +94,7 @@
assertDatabaseCount('form_integrations', 1);

delete(route('zapier.webhooks.destroy', $integration), [
'form_id' => $form->slug,
'form_id' => $form->id,
'hookUrl' => $hookUrl,
])
->assertOk();
Expand Down Expand Up @@ -122,7 +122,7 @@
]);

delete(route('zapier.webhooks.destroy', $integration), [
'form_id' => $form->slug,
'form_id' => $form->id,
'hookUrl' => 'https://google.com',
])
->assertOk();
Expand Down Expand Up @@ -178,7 +178,7 @@
Sanctum::actingAs($user, ['view', 'manage-integrations']);

// 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
$response->assertOk();
Expand Down Expand Up @@ -229,7 +229,7 @@

// Call the poll endpoint
$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
$response->assertOk();

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Zapier/ListFormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
->assertJsonCount(2)
->assertJson([
[
'id' => $form1->slug,
'id' => $form1->id,
'name' => $form1->title,
],
[
'id' => $form2->slug,
'id' => $form2->id,
'name' => $form2->title,
],
]);
Expand Down

0 comments on commit 943e906

Please sign in to comment.