Fix customer test

This commit is contained in:
Jérémy Munsch 2023-10-05 15:03:18 +02:00
parent 85228f1bb6
commit d65d1015c8
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -310,6 +310,12 @@ class CrmClientV2CustomerTest extends CrmClientTester
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$this->assertEquals(Country::belgium(), $customer->country);
$customer->country = Country::france();
$customer->save();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$this->assertEquals(Country::france(), $customer->country);
$customer->email = 'pouet@gmail.com';
$customer->birth_date = '1992-03-08';
$customer->phone = '0388977213';
@ -499,18 +505,18 @@ class CrmClientV2CustomerTest extends CrmClientTester
private function createNewCustomer(array $data, Brand $brand)
{
$customer = \App\Models\Customer::whereEmail($data['email'])
->whereHas('brands', function ($q) use ($brand) {
$q->where('brands.id', '=', $brand->id);
})->firstOrNew();
->whereHas('brands', function ($q) use ($brand) {
$q->where('brands.id', '=', $brand->id);
})->firstOrNew();
$customer->fill($data);
$saved = $customer->save();
// * Delete Single optin if exists.
/** @var \App\Models\SingleOptin|null $singleOptin */
$singleOptin = SingleOptin::query()->where('email', $data['email'])
->whereHas('brand', function ($q) use ($brand) {
$q->where('brands.id', '=', $brand->id);
})->first();
->whereHas('brand', function ($q) use ($brand) {
$q->where('brands.id', '=', $brand->id);
})->first();
if ($singleOptin) {
$saved = $singleOptin->delete() && $saved;
}