create(['camp_published' => 1, 'camp_type' => 1]); $contact = Contact::factory()->create(); $panier = Panier::factory()->create([ 'panier_ref' => 'BASKET123', 'panier_campId' => $campagne->camp_id, 'panier_contactId' => $contact->contact_id, 'panier_pending' => 1 ]); $coupon = Coupon::factory()->create(); $coupon->campagnes()->attach($campagne->camp_id); // Act $quantity = 2; $response = $this->json('POST', $endpoint, [ 'basketid' => $panier->panier_ref, 'panier' => sprintf('(%s)%s', $quantity, $coupon->coupon_code), 'admin' => true ]); // Assert $response->assertStatus(200); $response->assertJson(['Statut' => 'OK']); } /** * Test updating basket with invalid panier parameter */ public function test_update_basket_with_invalid_panier_param() { $endpoint = "/updatebasket"; // Arrange - create sample Panier, Coupon, Campagne, Contact $campagne = Campagne::factory()->create(['camp_published' => 1, 'camp_type' => 1]); $contact = Contact::factory()->create(); $panier = Panier::factory()->create([ 'panier_ref' => 'BASKET123', 'panier_campId' => $campagne->camp_id, 'panier_contactId' => $contact->contact_id, 'panier_pending' => 1 ]); $coupon = Coupon::factory()->create(); $coupon->campagnes()->attach($campagne->camp_id); $response = $this->json('POST', $endpoint, [ 'basketid' => $panier->panier_ref, 'panier' => 'test', ]); $response->assertStatus(200); $response->assertJson(['Statut' => 'KO', 'Code' => 101]); } /** * Test updating basket with nonexistent panier */ public function test_update_basket_with_nonexistent_panier() { $endpoint = "/updatebasket"; $response = $this->json('POST', $endpoint, [ 'basketid' => 'NONEXISTENT' ]); $response->assertStatus(200); $response->assertJson(['Statut' => 'KO', 'Code' => 106]); } /** * Test creating or updating basket without basketid but with required campaign and contact info */ public function test_create_or_update_basket_without_basketid_valid_info() { $endpoint = "/updatebasket"; $campagne = Campagne::factory()->create(['camp_published' => 1, 'camp_type' => 1]); $site = Site::factory()->create(['site_id' => $campagne->camp_siteId]); $contactData = [ 'refcamp' => $campagne->camp_id, 'refadherent' => 'contact-ref', 'nom' => 'Doe', 'prenom' => 'John', 'email' => 'john.doe@example.com', 'code_postal' => '12345', 'commune' => 'CityTown', 'refsite' => $campagne->camp_siteId, 'panier' => '(1)9999' ]; $response = $this->json('POST', $endpoint, $contactData); $response->assertStatus(200); $response->assertJson(['Statut' => 'OK']); } }