assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', true)); $this->assertTrue(ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists()); // Set single optin again should not fail. $this->assertTrue(CrmApiV4::setStatus('singleoptinrandom@gmail.com', true)); // Remove single optin test and check. $this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', false)); $this->assertTrue(!ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists()); } /** * Test create single optin should fail if a customer exists. * * @return void */ public function testCreateSingleOptinShouldFailBecauseCustomerExists() { $this->expectException(ApiErrorException::class); $this->expectExceptionMessage(ApiError::singleOptinCustomerExists->label()); $customer = new Customer(); $randomMail = Str::uuid() . 'totosingleoptin.delarogerie@gmail.com'; $customer->firstname = 'toto singleoptin'; $customer->lastname = 'delarogerie'; $customer->email = $randomMail; $customer->password = 'Complic4tEd!P4assW0rd'; $customer->birth_date = '1992-03-08'; $customer->phone = '0673891160'; $customer->address = 'rue des totos'; $customer->city = 'Toto ville'; $customer->postcode = '72160'; $customer->country = Country::france->value(); $this->assertTrue($customer->save()); $this->assertFalse(SingleOptin::setStatus($randomMail, true)); } /** * Remove single optin with hashcode test * * Calling multiple times single optin true should not fail. * * @return void */ public function testRemoveSingleOptinWithHashcode() { // Set single optin and check. $this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', true)); $this->assertTrue(ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists()); $hashcode = ModelsSingleOptin::query() ->where('email', 'singleoptinrandom@gmail.com')->sole('hashcode')->hashcode; // Remove single optin test and check. $this->assertTrue(SingleOptin::unsetStatusWithHashcode($hashcode)); $this->assertTrue(!ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists()); } }