Skip to content

Commit 943e906

Browse files
zapier improvements (#532)
* zapier improvements * Fix test case --------- Co-authored-by: Julien Nahum <julien@nahum.net>
1 parent 7ac8503 commit 943e906

File tree

7 files changed

+18
-23
lines changed

7 files changed

+18
-23
lines changed

app/Http/Requests/Integration/Zapier/PollSubmissionRequest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ public function rules(): array
1818
return [
1919
'form_id' => [
2020
'required',
21-
Rule::exists(Form::getModel()->getTable(), 'slug'),
21+
Rule::exists(Form::getModel()->getTable(), 'id'),
2222
],
2323
];
2424
}
2525

2626
public function form(): Form
2727
{
28-
return Form::query()
29-
->where('slug', $this->input('form_id'))
30-
->firstOrFail();
28+
return Form::findOrFail($this->input('form_id'));
3129
}
3230
}

app/Http/Requests/Zapier/CreateIntegrationRequest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function rules()
1313
return [
1414
'form_id' => [
1515
'required',
16-
Rule::exists(Form::getModel()->getTable(), 'slug'),
16+
Rule::exists(Form::getModel()->getTable(), 'id'),
1717
],
1818
'hookUrl' => [
1919
'required',
@@ -24,8 +24,6 @@ public function rules()
2424

2525
public function form(): Form
2626
{
27-
return Form::query()
28-
->where('slug', $this->input('form_id'))
29-
->firstOrFail();
27+
return Form::findOrFail($this->input('form_id'));
3028
}
3129
}

app/Http/Requests/Zapier/DeleteIntegrationRequest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function rules()
1313
return [
1414
'form_id' => [
1515
'required',
16-
Rule::exists(Form::getModel()->getTable(), 'slug'),
16+
Rule::exists(Form::getModel()->getTable(), 'id'),
1717
],
1818
'hookUrl' => [
1919
'required',
@@ -24,8 +24,6 @@ public function rules()
2424

2525
public function form(): Form
2626
{
27-
return Form::query()
28-
->where('slug', $this->input('form_id'))
29-
->firstOrFail();
27+
return Form::findOrFail($this->input('form_id'));
3028
}
3129
}

app/Http/Resources/Zapier/FormResource.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class FormResource extends JsonResource
1212
public function toArray($request)
1313
{
1414
return [
15-
'id' => $this->resource->slug,
15+
'id' => $this->resource->id,
1616
'name' => $this->resource->title,
17+
'label' => $this->resource->title . ' (' . $this->resource->slug . ')'
1718
];
1819
}
1920
}

integrations/zapier/triggers/new_submission.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
key: 'form_id',
3838
type: 'string',
3939
label: 'Form',
40-
dynamic: 'list_forms.id.name',
40+
dynamic: 'list_forms.id.label',
4141
required: true,
4242
list: false,
4343
altersDynamicFields: false,

tests/Feature/Zapier/IntegrationsTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
$this->withoutExceptionHandling();
2525
post(route('zapier.webhooks.store'), [
26-
'form_id' => $form->slug,
26+
'form_id' => $form->id,
2727
'hookUrl' => $hookUrl = 'https://zapier.com/hook/test'
2828
])
2929
->assertOk();
@@ -45,7 +45,7 @@
4545
Sanctum::actingAs($user);
4646

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

6666
post(route('zapier.webhooks.store'), [
67-
'form_id' => $form->slug,
67+
'form_id' => $form->id,
6868
'hookUrl' => 'https://zapier.com/hook/test'
6969
])
7070
->assertForbidden();
@@ -94,7 +94,7 @@
9494
assertDatabaseCount('form_integrations', 1);
9595

9696
delete(route('zapier.webhooks.destroy', $integration), [
97-
'form_id' => $form->slug,
97+
'form_id' => $form->id,
9898
'hookUrl' => $hookUrl,
9999
])
100100
->assertOk();
@@ -122,7 +122,7 @@
122122
]);
123123

124124
delete(route('zapier.webhooks.destroy', $integration), [
125-
'form_id' => $form->slug,
125+
'form_id' => $form->id,
126126
'hookUrl' => 'https://google.com',
127127
])
128128
->assertOk();
@@ -178,7 +178,7 @@
178178
Sanctum::actingAs($user, ['view', 'manage-integrations']);
179179

180180
// Call the poll endpoint
181-
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug]));
181+
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
182182

183183
// Assert the response status is OK
184184
$response->assertOk();
@@ -229,7 +229,7 @@
229229

230230
// Call the poll endpoint
231231
$this->withoutExceptionHandling();
232-
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug]));
232+
$response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
233233
// Assert the response status is OK
234234
$response->assertOk();
235235

tests/Feature/Zapier/ListFormsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
->assertJsonCount(2)
2323
->assertJson([
2424
[
25-
'id' => $form1->slug,
25+
'id' => $form1->id,
2626
'name' => $form1->title,
2727
],
2828
[
29-
'id' => $form2->slug,
29+
'id' => $form2->id,
3030
'name' => $form2->title,
3131
],
3232
]);

0 commit comments

Comments
 (0)