Lint PHP code psr-12, add GH action

This commit is contained in:
Julien Nahum
2024-02-23 11:54:12 +01:00
parent e85e4df7fe
commit 62971a2ef4
226 changed files with 2338 additions and 2144 deletions

View File

@@ -10,7 +10,6 @@ it('can answer a form', function () {
// TODO: generate random response given a form and un-skip
})->skip('Need to finish writing a class to generated random responses');
it('can submit form if close date is in future', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
@@ -23,7 +22,7 @@ it('can submit form if close date is in future', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});
@@ -48,12 +47,12 @@ it('can submit form till max submissions count is not reached at limit', functio
$formData = FormSubmissionDataFactory::generateSubmissionData($form);
// Can submit form
for($i=1;$i<=3;$i++){
for ($i = 1; $i <= 3; $i++) {
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
}
@@ -66,7 +65,7 @@ it('can not open draft form', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'visibility' => 'draft'
'visibility' => 'draft',
]);
$this->getJson(route('forms.show', $form->slug))
@@ -77,7 +76,7 @@ it('can not submit draft form', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'visibility' => 'draft'
'visibility' => 'draft',
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form);
@@ -89,7 +88,7 @@ it('can not submit visibility closed form', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'visibility' => 'closed'
'visibility' => 'closed',
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form);
@@ -104,10 +103,11 @@ it('can not submit form with past dates', function () {
$submissionData = [];
$form->properties = collect($form->properties)->map(function ($property) use (&$submissionData) {
if(in_array($property['type'], ['date'])){
$property["disable_past_dates"] = true;
if (in_array($property['type'], ['date'])) {
$property['disable_past_dates'] = true;
$submissionData[$property['id']] = now()->subDays(4)->format('Y-m-d');
}
return $property;
})->toArray();
$form->update();
@@ -117,7 +117,7 @@ it('can not submit form with past dates', function () {
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertStatus(422)
->assertJson([
'message' => 'The Date must be a date after or equal to today.'
'message' => 'The Date must be a date after or equal to today.',
]);
});
@@ -128,10 +128,11 @@ it('can not submit form with future dates', function () {
$submissionData = [];
$form->properties = collect($form->properties)->map(function ($property) use (&$submissionData) {
if(in_array($property['type'], ['date'])){
$property["disable_future_dates"] = true;
if (in_array($property['type'], ['date'])) {
$property['disable_future_dates'] = true;
$submissionData[$property['id']] = now()->addDays(4)->format('Y-m-d');
}
return $property;
})->toArray();
$form->update();
@@ -141,6 +142,6 @@ it('can not submit form with future dates', function () {
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertStatus(422)
->assertJson([
'message' => 'The Date must be a date before or equal to today.'
'message' => 'The Date must be a date before or equal to today.',
]);
});

View File

@@ -1,6 +1,6 @@
<?php
use Illuminate\Support\Facades\Artisan;
use Spatie\Mailcoach\Domain\TransactionalMail\Models\TransactionalMail;
it('check form statistic for views & submissions counts', function () {
$user = $this->actingAsUser();
@@ -8,7 +8,7 @@ it('check form statistic for views & submissions counts', function () {
$form = $this->createForm($user, $workspace, []);
// Create 10 views & submissions (in the past of 1 day so that it's cleaned)
for($i=1;$i<=10;$i++){
for ($i = 1; $i <= 10; $i++) {
$submission = $form->submissions()->create();
$submission->created_at = now()->subDay();
$submission->save();
@@ -29,7 +29,7 @@ it('check form statistic for views & submissions counts', function () {
Artisan::call('forms:database-cleanup');
// Create 5 views & submissions
for($i=1;$i<=5;$i++){
for ($i = 1; $i <= 5; $i++) {
$form->views()->create();
$form->submissions()->create();
}
@@ -41,8 +41,8 @@ it('check form statistic for views & submissions counts', function () {
expect($form->views()->count())->toBe(5);
expect($form->submissions()->count())->toBe(16);
expect(count($statistics))->toBe(2); // 1 per day for 2 different dates
expect($statistics[0]["date"])->toBe(now()->subDays(2)->toDateString());
expect($statistics[0]["data"])->toBe(["views"=>1,"submissions"=>1]);
expect($statistics[1]["date"])->toBe(now()->subDay()->toDateString());
expect($statistics[1]["data"])->toBe(["views"=>10,"submissions"=>10]);
});
expect($statistics[0]['date'])->toBe(now()->subDays(2)->toDateString());
expect($statistics[0]['data'])->toBe(['views' => 1, 'submissions' => 1]);
expect($statistics[1]['date'])->toBe(now()->subDay()->toDateString());
expect($statistics[1]['data'])->toBe(['views' => 10, 'submissions' => 10]);
});

View File

@@ -1,7 +1,7 @@
<?php
use Illuminate\Support\Facades\Mail;
use App\Mail\Forms\SubmissionConfirmationMail;
use Illuminate\Support\Facades\Mail;
it('creates confirmation emails with the submitted data', function () {
$user = $this->actingAsUser();
@@ -17,7 +17,7 @@ it('creates confirmation emails with the submitted data', function () {
$formData = [
collect($form->properties)->first(function ($property) {
return $property['type'] == 'email';
})["id"] => "test@test.com",
})['id'] => 'test@test.com',
];
$event = new \App\Events\Forms\FormSubmitted($form, $formData);
$mailable = new SubmissionConfirmationMail($event);
@@ -40,7 +40,7 @@ it('creates confirmation emails without the submitted data', function () {
$formData = [
collect($form->properties)->first(function ($property) {
return $property['type'] == 'email';
})["id"] => "test@test.com",
})['id'] => 'test@test.com',
];
$event = new \App\Events\Forms\FormSubmitted($form, $formData);
$mailable = new SubmissionConfirmationMail($event);
@@ -61,7 +61,7 @@ it('sends a confirmation email if needed', function () {
return $property['type'] == 'email';
});
$formData = [
$emailProperty["id"] => "test@test.com",
$emailProperty['id'] => 'test@test.com',
];
Mail::fake();
@@ -70,13 +70,15 @@ it('sends a confirmation email if needed', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
Mail::assertQueued(SubmissionConfirmationMail::class,
function (SubmissionConfirmationMail $mail) use ($formData, $emailProperty) {
return $mail->hasTo("test@test.com");
});
Mail::assertQueued(
SubmissionConfirmationMail::class,
function (SubmissionConfirmationMail $mail) {
return $mail->hasTo('test@test.com');
}
);
});
it('does not send a confirmation email if not needed', function () {
@@ -89,7 +91,7 @@ it('does not send a confirmation email if not needed', function () {
return $property['type'] == 'email';
});
$formData = [
$emailProperty["id"] => "test@test.com",
$emailProperty['id'] => 'test@test.com',
];
Mail::fake();
@@ -98,12 +100,13 @@ it('does not send a confirmation email if not needed', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
Mail::assertNotQueued(SubmissionConfirmationMail::class,
function (SubmissionConfirmationMail $mail) use ($formData, $emailProperty) {
return $mail->hasTo("test@test.com");
});
Mail::assertNotQueued(
SubmissionConfirmationMail::class,
function (SubmissionConfirmationMail $mail) {
return $mail->hasTo('test@test.com');
}
);
});

View File

@@ -1,17 +1,19 @@
<?php
use Tests\Helpers\FormSubmissionDataFactory;
it('can submit form with dyanamic select option', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
$selectionsPreData = [];
$form->properties = collect($form->properties)->map(function ($property) use (&$selectionsPreData) {
if(in_array($property['type'], ['select','multi_select'])){
$property["allow_creation"] = true;
$selectionsPreData[$property['id']] = ($property['type'] == "select") ? "New single select - ".time() : ["New multi select - ".time()];
if (in_array($property['type'], ['select', 'multi_select'])) {
$property['allow_creation'] = true;
$selectionsPreData[$property['id']] = ($property['type'] == 'select') ? 'New single select - '.time() : ['New multi select - '.time()];
}
return $property;
})->toArray();
$form->update();
@@ -21,6 +23,6 @@ it('can submit form with dyanamic select option', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});
});

View File

@@ -16,5 +16,5 @@ it('create form with captcha and raise validation issue', function () {
'Please complete the captcha.',
],
],
]);
]);
});

View File

@@ -1,6 +1,6 @@
<?php
use Illuminate\Testing\Fluent\AssertableJson;
use Illuminate\Testing\Fluent\AssertableJson;
it('create form with logic', function () {
$user = $this->actingAsUser();
@@ -8,103 +8,100 @@ it('create form with logic', function () {
$form = $this->createForm($user, $workspace, [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'title',
'hidden' => false,
'required' => true,
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "email",
"value"=> [
"operator"=> "is_empty",
"property_meta"=> [
'id'=> "93ea3198-353f-440b-8dc9-2ac9a7bee124",
"type"=> "email",
'identifier' => 'email',
'value' => [
'operator' => 'is_empty',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee124',
'type' => 'email',
],
"value"=> true
]
]
]
'value' => true,
],
],
],
],
"actions" => ['make-it-optional']
]
]
'actions' => ['make-it-optional'],
],
],
],
]);
$this->getJson(route('forms.show', $form->slug))
->assertSuccessful()
->assertJson(function (AssertableJson $json) use ($form) {
return $json->where('id', $form->id)
->where('properties', function($values){
return (count($values[0]['logic']) > 0);
->where('properties', function ($values) {
return count($values[0]['logic']) > 0;
})
->etc();
});
// Should submit form
$forData = ['93ea3198-353f-440b-8dc9-2ac9a7bee124' => ""];
$forData = ['93ea3198-353f-440b-8dc9-2ac9a7bee124' => ''];
$this->postJson(route('forms.answer', $form->slug), $forData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});
it('create form with multi select logic', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'title',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "multi_select",
"value"=> [
"operator"=> "contains",
"property_meta"=> [
'id'=> "93ea3198-353f-440b-8dc9-2ac9a7bee124",
"type"=> "multi_select",
'identifier' => 'multi_select',
'value' => [
'operator' => 'contains',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee124',
'type' => 'multi_select',
],
"value"=> 'One'
]
]
]
'value' => 'One',
],
],
],
],
"actions" => ['require-answer']
]
]
'actions' => ['require-answer'],
],
],
],
]);
$this->getJson(route('forms.show', $form->slug))
->assertSuccessful()
->assertJson(function (AssertableJson $json) use ($form) {
return $json->where('id', $form->id)
->where('properties', function($values){
return (count($values[0]['logic']) > 0);
->where('properties', function ($values) {
return count($values[0]['logic']) > 0;
})
->etc();
});
// Should submit form
$forData = ['93ea3198-353f-440b-8dc9-2ac9a7bee124' => ["One"]];
$forData = ['93ea3198-353f-440b-8dc9-2ac9a7bee124' => ['One']];
$this->postJson(route('forms.answer', $form->slug), $forData)
->assertStatus(422)
->assertJson([
@@ -114,5 +111,5 @@ it('create form with multi select logic', function () {
'The Name field is required.',
],
],
]);
]);
});

View File

@@ -1,10 +1,10 @@
<?php
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\Helpers\FormSubmissionDataFactory;
beforeEach(function () {
$this->password = "12345";
$this->password = '12345';
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$this->form = $this->createForm($user, $workspace, [
@@ -13,7 +13,6 @@ beforeEach(function () {
$this->formData = FormSubmissionDataFactory::generateSubmissionData($this->form);
});
it('can allow form owner to access and submit form without password', function () {
// As Form Owner so can access form without password
$this->getJson(route('forms.show', $this->form->slug))
@@ -30,7 +29,7 @@ it('can allow form owner to access and submit form without password', function (
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});
@@ -54,26 +53,26 @@ it('can not submit form without password for guest user', function () {
->assertStatus(403)
->assertJson([
'status' => 'Unauthorized',
'message' => 'Form is protected.'
'message' => 'Form is protected.',
]);
});
it('can not submit form with wrong password for guest user', function () {
$this->actingAsGuest();
$this->withHeaders(['form-password'=>hash('sha256', 'WRONGPASSWORD')])
$this->withHeaders(['form-password' => hash('sha256', 'WRONGPASSWORD')])
->postJson(route('forms.answer', $this->form->slug), $this->formData)
->assertStatus(403)
->assertJson([
'status' => 'Unauthorized',
'message' => 'Form is protected.'
'message' => 'Form is protected.',
]);
});
it('can access form with right password for guest user', function () {
$this->actingAsGuest();
$this->withHeaders(['form-password'=>hash('sha256', $this->password)])
$this->withHeaders(['form-password' => hash('sha256', $this->password)])
->getJson(route('forms.show', $this->form->slug))
->assertSuccessful()
->assertJson(function (AssertableJson $json) {
@@ -87,11 +86,11 @@ it('can access form with right password for guest user', function () {
it('can submit form with right password for guest user', function () {
$this->actingAsGuest();
$this->withHeaders(['form-password'=>hash('sha256', $this->password)])
$this->withHeaders(['form-password' => hash('sha256', $this->password)])
->postJson(route('forms.answer', $this->form->slug), $this->formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});

View File

@@ -1,202 +1,201 @@
<?php
<?php
use App\Rules\FormPropertyLogicRule;
it('can validate form logic rules for actions', function () {
$rules = [
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()]
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()],
];
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'title',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => null,
"actions" => []
]
]
]
'conditions' => null,
'actions' => [],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertTrue($validatorObj->passes());
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'title',
'hidden' => true,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "title",
"value"=> [
"operator"=> "equals",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
'identifier' => 'title',
'value' => [
'operator' => 'equals',
'property_meta' => [
'id' => 'title',
'type' => 'text',
],
"value"=> "TEST"
]
]
]
'value' => 'TEST',
],
],
],
],
"actions" => ['hide-block']
]
]
]
'actions' => ['hide-block'],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic actions for Name are not valid.");
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe('The logic actions for Name are not valid.');
$data = [
'properties' => [
[
'id' => "text",
'name' => "Custom Test",
'id' => 'text',
'name' => 'Custom Test',
'type' => 'nf-text',
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "title",
"value"=> [
"operator"=> "equals",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
'identifier' => 'title',
'value' => [
'operator' => 'equals',
'property_meta' => [
'id' => 'title',
'type' => 'text',
],
"value"=> "TEST"
]
]
]
'value' => 'TEST',
],
],
],
],
"actions" => ['require-answer']
]
]
]
'actions' => ['require-answer'],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic actions for Custom Test are not valid.");
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe('The logic actions for Custom Test are not valid.');
});
it('can validate form logic rules for conditions', function () {
$rules = [
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()]
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()],
];
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'text',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "title",
"value"=> [
"operator"=> "equals",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
'identifier' => 'title',
'value' => [
'operator' => 'equals',
'property_meta' => [
'id' => 'title',
'type' => 'text',
],
"value"=> "TEST"
]
]
]
'value' => 'TEST',
],
],
],
],
"actions" => ['hide-block']
]
]
]
'actions' => ['hide-block'],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertTrue($validatorObj->passes());
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'text',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> "and",
"children"=> [
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
[
"identifier"=> "title",
"value"=> [
"operator"=> "starts_with",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
'identifier' => 'title',
'value' => [
'operator' => 'starts_with',
'property_meta' => [
'id' => 'title',
'type' => 'text',
],
]
]
]
],
],
],
],
"actions" => ['hide-block']
]
]
]
'actions' => ['hide-block'],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing condition value");
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe('The logic conditions for Name are not complete. Error detail(s): missing condition value');
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'id' => 'title',
'name' => 'Name',
'type' => 'text',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> null,
"children"=> [
'conditions' => [
'operatorIdentifier' => null,
'children' => [
[
"identifier"=> "title",
"value"=> [
"operator"=> "starts_with",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
'identifier' => 'title',
'value' => [
'operator' => 'starts_with',
'property_meta' => [
'id' => 'title',
'type' => 'text',
],
]
]
]
],
],
],
],
"actions" => ['hide-block']
]
]
]
'actions' => ['hide-block'],
],
],
],
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing operator");
});
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe('The logic conditions for Name are not complete. Error detail(s): missing operator');
});

View File

@@ -1,4 +1,5 @@
<?php
use Illuminate\Support\Facades\Artisan;
it('check formstat chart data', function () {
@@ -9,7 +10,7 @@ it('check formstat chart data', function () {
$views = [];
$submissions = [];
// Create 10 views & submissions for past days
for($i=1;$i<=10;$i++){
for ($i = 1; $i <= 10; $i++) {
$date = now()->subDays($i);
$dateString = $date->format('d-m-Y');
@@ -28,7 +29,7 @@ it('check formstat chart data', function () {
Artisan::call('forms:database-cleanup');
// Create 5 views & submissions
for($i=1;$i<=5;$i++){
for ($i = 1; $i <= 5; $i++) {
$form->views()->create();
$form->submissions()->create();
@@ -43,20 +44,22 @@ it('check formstat chart data', function () {
->assertJson(function (\Illuminate\Testing\Fluent\AssertableJson $json) use ($views, $submissions) {
return $json->whereType('views', 'array')
->whereType('submissions', 'array')
->where('views', function($values) use ($views) {
foreach($values as $date=>$count){
if((isset($views[$date]) && $views[$date] != $count) || (!isset($views[$date]) && $count != 0)){
->where('views', function ($values) use ($views) {
foreach ($values as $date => $count) {
if ((isset($views[$date]) && $views[$date] != $count) || (! isset($views[$date]) && $count != 0)) {
return false;
}
}
return true;
})
->where('submissions', function($values) use ($submissions) {
foreach($values as $date=>$count){
if((isset($submissions[$date]) && $submissions[$date] != $count) || (!isset($submissions[$date]) && $count != 0)){
->where('submissions', function ($values) use ($submissions) {
foreach ($values as $date => $count) {
if ((isset($submissions[$date]) && $submissions[$date] != $count) || (! isset($submissions[$date]) && $count != 0)) {
return false;
}
}
return true;
})
->etc();

View File

@@ -12,7 +12,7 @@ it('can create a contact form', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form created.'
'message' => 'Form created.',
]);
expect($workspace->forms()->count())->toBe(1);
@@ -47,7 +47,7 @@ it('can update a form', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form updated.'
'message' => 'Form updated.',
]);
$this->assertDatabaseHas('forms', [
@@ -73,10 +73,13 @@ it('can regenerate a form url', function () {
->assertJson(function (AssertableJson $json) {
return $json->where('type', 'success')
->where('form.slug', function ($value) {
if (!is_string($value) || (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/',
$value) !== 1)) {
if (! is_string($value) || (preg_match(
'/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/',
$value
) !== 1)) {
return false;
}
return true;
})
->etc();
@@ -103,7 +106,7 @@ it('can duplicate a form', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form successfully duplicated.'
'message' => 'Form successfully duplicated.',
]);
expect($user->forms()->count())->toBe(2);
@@ -124,7 +127,7 @@ it('can delete a form', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form was deleted.'
'message' => 'Form was deleted.',
]);
expect($user->forms()->count())->toBe(0);
expect($workspace->forms()->count())->toBe(0);
@@ -134,7 +137,7 @@ it('can create form with dark mode', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'dark_mode' => "dark",
'dark_mode' => 'dark',
]);
$formData = (new \App\Http\Resources\FormResource($form))->toArray(request());
@@ -142,7 +145,7 @@ it('can create form with dark mode', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form created.'
'message' => 'Form created.',
]);
$this->getJson(route('forms.show', $form->slug))

View File

@@ -11,7 +11,7 @@ it('can update form with existing record', function () {
$nameProperty = collect($form->properties)->filter(function ($property) {
return $property['name'] == 'Name';
})->first();
})->first();
$response = $this->postJson(route('forms.answer', $form->slug), [$nameProperty['id'] => 'Testing'])
->assertSuccessful()
@@ -22,8 +22,8 @@ it('can update form with existing record', function () {
$submissionId = $response->json('submission_id');
expect($submissionId)->toBeString();
if($submissionId){
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['submission_id'=>$submissionId, $nameProperty['id'] => 'Testing Updated']);
if ($submissionId) {
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['submission_id' => $submissionId, $nameProperty['id'] => 'Testing Updated']);
$response = $this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
@@ -35,7 +35,7 @@ it('can update form with existing record', function () {
expect($submissionId2)->toBe($submissionId);
$response = $this->getJson(route('forms.fetchSubmission', [$form->slug, $submissionId]))
->assertSuccessful();
->assertSuccessful();
expect($response->json('data.'.$nameProperty['id']))->toBe('Testing Updated');
}
});

View File

@@ -17,7 +17,6 @@ it('can see form without counting view for form owner', function () {
expect($form->views()->count())->toBe(0);
});
it('can see form and count view for guest', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);

View File

@@ -1,6 +1,7 @@
<?php
use Tests\Helpers\FormSubmissionDataFactory;
use App\Models\User;
use Tests\Helpers\FormSubmissionDataFactory;
it('can validate Update Workspace Select Option Job', function () {
$user = $this->actingAsUser();
@@ -12,7 +13,7 @@ it('can validate Update Workspace Select Option Job', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form);
@@ -20,7 +21,7 @@ it('can validate Update Workspace Select Option Job', function () {
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
});
@@ -30,6 +31,6 @@ it('can validate scope with active subscription', function () {
$this->createProUser();
$this->createProUser();
$this->createUser();
expect(User::WithActiveSubscription()->count())->toBe(3);
});
});

View File

@@ -6,9 +6,9 @@ it('can login to Forms', function () {
$user = User::factory()->create();
$this->postJson('/login', [
'email' => $user->email,
'password' => 'password',
])
'email' => $user->email,
'password' => 'password',
])
->assertSuccessful()
->assertJsonStructure(['token', 'expires_in'])
->assertJson(['token_type' => 'bearer']);
@@ -28,11 +28,10 @@ it('can log out', function () {
])->assertSuccessful();
$this->assertAuthenticated();
$this->postJson("/logout")
$this->postJson('/logout')
->assertSuccessful();
$this->assertGuest();
$this->getJson("/user")
$this->getJson('/user')
->assertStatus(401);
});

View File

@@ -1,7 +1,7 @@
<?php
use App\Models\User;
use Tests\TestCase;
use function Pest\Faker\faker;
it('can register', function () {
@@ -11,13 +11,13 @@ it('can register', function () {
'hear_about_us' => 'google',
'password' => 'secret',
'password_confirmation' => 'secret',
'agree_terms' => true
'agree_terms' => true,
])
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);
$this->assertDatabaseHas('users', [
'name' => 'Test User',
'email' => 'test@test.app'
'email' => 'test@test.app',
]);
});
@@ -40,17 +40,17 @@ it('cannot register with disposable email', function () {
'dumliyupse@gufum.com',
'kcs79722@zslsz.com',
'pfizexwxtdifxupdhr@tpwlb.com',
'qvj86ypqfm@email.edu.pl'
'qvj86ypqfm@email.edu.pl',
]);
$this->postJson('/register', [
'name' => 'Test disposable',
'email' => $email,
'hear_about_us' => 'google',
'password' => 'secret',
'password_confirmation' => 'secret',
'agree_terms' => true
])
'name' => 'Test disposable',
'email' => $email,
'hear_about_us' => 'google',
'password' => 'secret',
'password_confirmation' => 'secret',
'agree_terms' => true,
])
->assertStatus(422)
->assertJsonValidationErrors(['email'])
->assertJson([

View File

@@ -2,31 +2,30 @@
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
it('update profile info',function() {
$this->actingAs($user = User::factory()->create())
->patchJson('/settings/profile', [
'name' => 'Test User',
'email' => 'test@test.app',
])
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);
$this->assertDatabaseHas('users', [
'id' => $user->id,
it('update profile info', function () {
$this->actingAs($user = User::factory()->create())
->patchJson('/settings/profile', [
'name' => 'Test User',
'email' => 'test@test.app',
]);
])
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);
$this->assertDatabaseHas('users', [
'id' => $user->id,
'name' => 'Test User',
'email' => 'test@test.app',
]);
});
it('update password',function() {
$this->actingAs($user = User::factory()->create())
->patchJson('/settings/password', [
'password' => 'updated',
'password_confirmation' => 'updated',
])
->assertSuccessful();
it('update password', function () {
$this->actingAs($user = User::factory()->create())
->patchJson('/settings/password', [
'password' => 'updated',
'password_confirmation' => 'updated',
])
->assertSuccessful();
$this->assertTrue(Hash::check('updated', $user->password));
$this->assertTrue(Hash::check('updated', $user->password));
});

View File

@@ -9,23 +9,23 @@ it('can update form submission', function () {
$form = $this->createForm($user, $workspace, [
'closes_at' => \Carbon\Carbon::now()->addDays(1)->toDateTimeString(),
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['text' => 'John']);
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['text' => 'John']);
$textFieldId = array_keys($formData)[0];
$updatedFormData = $formData;
$updatedFormTextValue = "Updated text";
$updatedFormTextValue = 'Updated text';
$updatedFormData[$textFieldId] = $updatedFormTextValue;
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
$submission = $form->submissions()->first();
$updateResponse = $this->putJson(route('open.forms.submissions.update', ['id'=>$form->id, 'submission_id' => $submission->id]), $updatedFormData)
$updateResponse = $this->putJson(route('open.forms.submissions.update', ['id' => $form->id, 'submission_id' => $submission->id]), $updatedFormData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Record successfully updated.'
'message' => 'Record successfully updated.',
]);
$expectedTextString = $updateResponse->json('data')['data'][$textFieldId];
expect($expectedTextString)->toBe($updatedFormTextValue);
@@ -34,28 +34,26 @@ it('can update form submission', function () {
});
it('cannot update form submission as non admin', function () {
$secondUser =$this->createUser();
$secondUser = $this->createUser();
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->makeForm($user, $workspace);
$form = $this->createForm($user, $workspace, [
'closes_at' => \Carbon\Carbon::now()->addDays(1)->toDateTimeString(),
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['text' => 'John']);
$formData = FormSubmissionDataFactory::generateSubmissionData($form, ['text' => 'John']);
$textFieldId = array_keys($formData)[0];
$updatedFormData = $formData;
$updatedFormTextValue = "Updated text";
$updatedFormTextValue = 'Updated text';
$updatedFormData[$textFieldId] = $updatedFormTextValue;
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.'
'message' => 'Form submission saved.',
]);
$submission = $form->submissions()->first();
$this->actingAs($secondUser);
$updateResponse = $this->putJson(route('open.forms.submissions.update', ['id'=>$form->id, 'submission_id' => $submission->id]), $updatedFormData)
$updateResponse = $this->putJson(route('open.forms.submissions.update', ['id' => $form->id, 'submission_id' => $submission->id]), $updatedFormData)
->assertStatus(403);
});

View File

@@ -2,7 +2,7 @@
it('can create template', function () {
$user = $this->createUser([
'email' => 'admin@opnform.com'
'email' => 'admin@opnform.com',
]);
$this->actingAsUser($user);
@@ -19,12 +19,12 @@ it('can create template', function () {
'image_url' => 'https://d3ietpyl4f2d18.cloudfront.net/6c35a864-ee3a-4039-80a4-040b6c20ac60/img/pages/welcome/product_cover.jpg',
'publicly_listed' => true,
'form' => $form->getAttributes(),
'questions' => [['question'=>'Question 1','answer'=>'Answer 1 will be here...']]
'questions' => [['question' => 'Question 1', 'answer' => 'Answer 1 will be here...']],
];
$this->postJson(route('templates.create', $templateData))
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Template was created.'
'message' => 'Template was created.',
]);
});

View File

@@ -1,12 +1,9 @@
<?php
use App\Models\User;
use App\Notifications\VerifyEmail;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
it('can verify email', function () {
$user = User::factory()->create(['email_verified_at' => null]);

View File

@@ -3,31 +3,31 @@
it('can create and delete Workspace', function () {
$user = $this->actingAsUser();
for($i=1;$i<=3;$i++){
for ($i = 1; $i <= 3; $i++) {
$this->postJson(route('open.workspaces.create'), [
'name' => 'Workspace Test - '.$i,
'icon' => '🧪',
])
'name' => 'Workspace Test - '.$i,
'icon' => '🧪',
])
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Workspace created.'
'message' => 'Workspace created.',
]);
}
expect($user->workspaces()->count())->toBe(3);
$i=0;
foreach($user->workspaces as $workspace){
$i = 0;
foreach ($user->workspaces as $workspace) {
$i++;
if($i !== 3){
if ($i !== 3) {
$this->deleteJson(route('open.workspaces.delete', $workspace->id))
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Workspace deleted.'
'message' => 'Workspace deleted.',
]);
}else{
} else {
// Last workspace can not delete
$this->deleteJson(route('open.workspaces.delete', $workspace->id))
->assertStatus(403);