/** * Edit product page, quantity, price and discount. * * @group success * @group billCombined */ public function testEditProductPageProductQuantityProductPriceAndProductDiscount() { $data = $this->generateData(); // Edit product page first $post = ['product_id' => $data['product']->id, 'bill_product_id' => $data['billProduct']->id, 'product_code' => $data['product']->code, 'product_page' => rand(1, 999)]; $this->actingAs($data['user'])->post(TestUrlBuilder::editBillProductPage($data['bill']->id), $post)->seeJson(['success' => true, 'message' => trans('bill.page_updated')])->seeInDatabase('bill_products', ['id' => $data['billProduct']->id, 'page' => $post['product_page']]); // Edit product quantity unset($post['product_page']); $post['product_quantity'] = rand(1, 99); $newPrice = Products::newPrice($data['billProduct']->price, $data['billProduct']->quantity, $post['product_quantity']); $newCalculatedDiscount = Products::discount($newPrice, $data['billProduct']->discount); $newFinalPrice = $newPrice - $newCalculatedDiscount; $this->actingAs($data['user'])->post(TestUrlBuilder::editBillProductQuantity($data['bill']->id), $post)->seeJson(['success' => true, 'message' => trans('bill.quantity_updated')])->seeInDatabase('bill_products', ['id' => $data['billProduct']->id, 'price' => $newPrice, 'calculated_discount' => $newCalculatedDiscount, 'final_price' => $newFinalPrice]); $data['billProduct']->quantity = $post['product_quantity']; // Edit product price unset($post['product_quantity']); $post['product_price'] = rand(1, 200); $newCalculatedDiscount = Products::discount($post['product_price'] * $data['billProduct']->quantity, $data['billProduct']->discount); $newFinalPrice = $post['product_price'] * $data['billProduct']->quantity - $newCalculatedDiscount; $this->actingAs($data['user'])->post(TestUrlBuilder::editBillProductPrice($data['bill']->id), $post)->seeJson(['success' => true, 'message' => trans('bill.price_updated')])->seeInDatabase('bill_products', ['id' => $data['billProduct']->id, 'calculated_discount' => $newCalculatedDiscount, 'final_price' => $newFinalPrice]); $data['billProduct']->price = $post['product_price'] * $data['billProduct']->quantity; // And finally edit product discount unset($post['product_price']); $post['product_discount'] = rand(0, 100); $newCalculatedDiscount = Products::discount($data['billProduct']->price, $post['product_discount']); $this->actingAs($data['user'])->post(TestUrlBuilder::editBillProductDiscount($data['bill']->id), $post)->seeJson(['success' => true, 'message' => trans('bill.discount_updated')])->seeInDatabase('bill_products', ['id' => $data['billProduct']->id, 'calculated_discount' => $newCalculatedDiscount, 'final_price' => $data['billProduct']->price - $newCalculatedDiscount]); }
/** * Edit bill product discount using product id and bill product id of another product. * * @group fail * @group editBillProduct * @group editBillProductDiscount */ public function testEditBillProductDiscountWithProductIdAndBillProductIdOfAnotherProduct() { $data = $this->generateData(); // Generate another product and add to bill $secondProduct = $data['user']->products()->save(factory(App\Product::class)->make()); $secondBillProduct = $data['bill']->products()->save(factory(App\BillProduct::class)->make(['product_id' => $secondProduct->id])); $post = ['product_id' => $secondProduct->id, 'bill_product_id' => $secondBillProduct->id, 'product_code' => $data['product']->code, 'product_discount' => rand(0, 100)]; $this->actingAs($data['user'])->post(TestUrlBuilder::editBillProductDiscount($data['bill']->id), $post)->seeJson(['success' => false, 'message' => trans('common.general_error')]); }
/** * Delete bill application product of another user. * * @group fail * @group deleteBillProduct */ public function testDeleteBillProductOfAnotherUser() { $firstData = $this->generateData(); $secondData = $this->generateData(); $this->actingAs($secondData['user'])->get(TestUrlBuilder::deleteBillProduct($firstData['bill']->id, $firstData['product']->id, $firstData['product']->code, $firstData['billProduct']->id))->seeJson(['success' => false, 'message' => trans('common.general_error')]); }
/** * Add bill product with too long and too short product quantity. * * @group fail * @group addBillProduct */ public function testAddBillProductWithTooSmallAndTooBigProductQuantity() { $data = $this->generateAddBillData(); $post = ['product_code' => $data['product']->code, 'product_page' => rand(1, 999), 'product_price' => rand(1, 999), 'product_discount' => rand(0, 100), 'product_quantity' => rand(1000, 9999)]; $this->actingAs($data['user'])->post(TestUrlBuilder::addBillProduct($data['bill']->id), $post)->seeJson(['success' => false, 'message' => trans('validation.between.numeric', ['attribute' => trans('validation.attributes.product_quantity'), 'min' => 1, 'max' => 999])]); }
/** * Delete an application product from bill using the code of another. Fail response is expected. */ public function testDeleteBillApplicationProductWithCodeOfAnotherProduct() { // Generate user, client and bill $user = factory(App\User::class)->create(); $client = $user->clients()->save(factory(App\Client::class)->make()); $bill = $user->bills()->save(factory(App\Bill::class)->make(['client_id' => $client->id])); // Generate 2 application products $firstApplicationProduct = factory(App\ApplicationProduct::class)->create(); $secondApplicationProduct = factory(App\ApplicationProduct::class)->create(); // Add to bill application products table $bill->applicationProducts()->save(factory(App\BillApplicationProduct::class)->make(['product_id' => $firstApplicationProduct->id])); $bill->applicationProducts()->save(factory(App\BillApplicationProduct::class)->make(['product_id' => $secondApplicationProduct->id])); // Try to delete first application product from bill using code of the second $this->actingAs($user)->get(TestUrlBuilder::deleteBillProduct($bill->id, $firstApplicationProduct->id, $secondApplicationProduct->code))->seeJson(['success' => false, 'message' => trans('common.general_error')]); }