Skip to content

Commit

Permalink
refactor: prevent returning forms without the "formBuilderSettings" a…
Browse files Browse the repository at this point in the history
…nd "formBuilderFields" meta keys
  • Loading branch information
glaubersilva committed May 17, 2024
1 parent a97ce17 commit dcd3290
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DonationForms/Repositories/DonationFormRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private function validateProperties(DonationForm $donationForm)
}

/**
* @unreleased Prevent returning forms without the "formBuilderSettings" and "formBuilderFields" meta keys
* @since 3.0.0
*
* @return ModelQueryBuilder<DonationForm>
Expand All @@ -288,6 +289,8 @@ public function prepareQuery(): ModelQueryBuilder
'form_id',
...DonationFormMetaKeys::getColumnsForAttachMetaQuery()
)
->whereIsNotNull("give_formmeta_attach_meta_settings.meta_value")
->whereIsNotNull("give_formmeta_attach_meta_fields.meta_value")
->where('post_type', 'give_forms');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,34 @@ public function testShouldGetTotalRevenueFromSubscriptions(): void

$this->assertEquals($amount->formatToDecimal(), $this->repository->getTotalInitialAmountFromSubscriptions($form->id));
}

/**
* @unreleased
*
* @throws Exception
*/
public function testShouldNotReturnDonationFormWithoutSettingsMetaKey()
{
$donationForm = $this->modelFactory->create();

give()->form_meta->delete_meta($donationForm->id, 'formBuilderSettings');
$donationFormFromDatabase = $this->repository->getById($donationForm->id);

$this->assertNull($donationFormFromDatabase);
}

/**
* @unreleased
*
* @throws Exception
*/
public function testShouldNotReturnDonationFormWithoutFieldsMetaKey()
{
$donationForm = $this->modelFactory->create();

give()->form_meta->delete_meta($donationForm->id, 'formBuilderFields');
$donationFormFromDatabase = $this->repository->getById($donationForm->id);

$this->assertNull($donationFormFromDatabase);
}
}

0 comments on commit dcd3290

Please sign in to comment.