callApiWithToken($service, 'post', route('apiV2.optin'), [ 'email' => 'warthogdj@hotmail.fr', 'opt_in' => 1 ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [ 'email' => 'warthogdj@hotmail.fr', 'opt_in' => 0 ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $this->assertNull(SingleOptin::where('email', 'warthogdj@hotmail.fr')->first()); } public function testSingleOptinOnCustomerExsits() { $service = Service::firstOrFail(); $this->storeCustomer($service); $response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [ 'email' => 'warthogdj@hotmail.fr', 'opt_in' => 1 ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO()); $this->assertEquals(ApiError::singleOptinCustomerExists()->value, $json->json('data.code')); $this->assertEquals(ApiError::singleOptinCustomerExists()->label, $json->json('data.message')); } private function storeCustomer(Service $service) { $data = [ 'firstname' => 'Jean', 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), 'address' => '10 impasse Maryse Bastié', 'email' => 'warthogdj@hotmail.fr', 'password' => '123.Mot.De.P4sse', 'phone' => '+33654821562', 'country' => (string)Country::france(), 'city' => 'Connerré', 'postcode' => '72160', 'opt_in' => true ]; $this->callApiWithToken($service, 'post', route('apiV2.customers.store'), $data); } }