Completed Cancel Cash On Delivery Test Cases

This commit is contained in:
devansh bawari 2020-11-13 00:47:39 +05:30
parent fdf0a0bb1c
commit 5fc2e6c091
1 changed files with 47 additions and 123 deletions

View File

@ -6,25 +6,28 @@ use Faker\Factory;
use FunctionalTester;
use Codeception\Util\Locator;
use Webkul\Sales\Models\Order;
use Webkul\Core\Models\Channel;
use Webkul\Customer\Models\Customer;
use Webkul\Sales\Models\OrderItem;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Sales\Models\OrderPayment;
use Webkul\Checkout\Models\CartAddress;
use Webkul\Checkout\Models\CartPayment;
use Webkul\Core\Helpers\Laravel5Helper;
class OrderCest
{
public function testIndex(FunctionalTester $I): void
{
/* simple order no further association like address, shipping method, payment method, etc. */
$order = $I->have(Order::class);
/* login as admin */
$I->loginAsAdmin();
/* go to order view page */
$I->amOnAdminRoute('admin.dashboard.index');
$I->click(__('admin::app.layouts.sales'), '//*[contains(@class, "navbar-left")]');
$I->seeCurrentRouteIs('admin.sales.orders.index');
$I->click(__('admin::app.layouts.orders'), '//*[contains(@class, "aside-nav")]');
/* now test index page */
$I->seeCurrentRouteIs('admin.sales.orders.index');
$I->see($order->id, '//script[@type="text/x-template"]');
$I->see($order->sub_total, '//script[@type="text/x-template"]');
@ -32,39 +35,63 @@ class OrderCest
public function testCancelCashOnDeliveryOrder(FunctionalTester $I): void
{
/* place order for customer */
$order = $this->placeCashOnDeliveryOrderForCustomer($I);
/* generate cash on delivery order */
$order = $this->generateCashOnDeliveryOrder($I);
/* go to admin page and login */
$this->goToAdminLoginPageAndSignIn($I);
/* login as admin */
$I->loginAsAdmin();
/* go to order view page */
$I->amOnPage(route('admin.sales.orders.view', $order->id));
$I->seeCurrentRouteIs('admin.sales.orders.view');
/* now cancel order test */
/* now test cancel order */
$I->see('Cancel', Locator::href(route('admin.sales.orders.cancel', $order->id)));
$I->click('Cancel', Locator::href(route('admin.sales.orders.cancel', $order->id)));
$I->seeCurrentRouteIs('admin.sales.orders.view');
$I->see(0.00, '#due-amount-on-cancelled');
}
private function goToAdminLoginPageAndSignIn(FunctionalTester $I): void
private function generateCashOnDeliveryOrder(FunctionalTester $I)
{
$I->amOnRoute('admin.session.create');
$I->fillField('email', 'admin@example.com');
$I->fillField('password', 'admin123');
$I->click('Sign In');
$I->seeCurrentRouteIs('admin.dashboard.index');
$product = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, [
'productAttributes' => [],
'productInventory' => [
'qty' => 5,
],
'attributeValues' => [
'status' => 1,
],
]);
$order = $I->have(OrderItem::class, ['product_id' => $product->id])->order;
$I->have(OrderAddress::class, $this->generateAddressData([
'order_id' => $order->id,
'address_type' => OrderAddress::ADDRESS_TYPE_SHIPPING,
'customer_id' => $order->customer->id,
]));
$I->have(OrderAddress::class, $this->generateAddressData([
'order_id' => $order->id,
'address_type' => OrderAddress::ADDRESS_TYPE_BILLING,
'customer_id' => $order->customer->id,
]));
$I->have(OrderPayment::class, [
'method' => 'cashondelivery',
'method_title' => null,
'order_id' => $order->id,
]);
return $order;
}
private function placeCashOnDeliveryOrderForCustomer(FunctionalTester $I): object
private function generateAddressData(array $additionalData): array
{
$customer = $I->loginAsCustomer();
$faker = Factory::create();
$addressData = [
return array_merge([
'city' => $faker->city,
'company_name' => $faker->company,
'country' => $faker->countryCode,
@ -74,109 +101,6 @@ class OrderCest
'phone' => $faker->phoneNumber,
'postcode' => $faker->postcode,
'state' => $faker->state,
];
$mocks = $I->prepareCart([
'customer' => $customer,
]);
$I->amOnRoute('shop.checkout.onepage.index');
$I->seeCurrentRouteIs('shop.checkout.onepage.index');
$I->sendAjaxPostRequest(route('shop.checkout.save-address'), [
'_token' => csrf_token(),
'billing' => array_merge($addressData, [
'address1' => ['900 Nobel Parkway'],
'save_as_address' => true,
'use_for_shipping' => true,
]),
'shipping' => array_merge($addressData, [
'address1' => ['900 Nobel Parkway'],
'save_as_address' => true,
'use_for_shipping' => true,
]),
]);
$I->seeResponseCodeIsSuccessful();
$I->seeRecord(CartAddress::class, array_merge($addressData, [
'address_type' => CartAddress::ADDRESS_TYPE_SHIPPING,
'cart_id' => $mocks['cart']->id,
'customer_id' => $mocks['customer']->id,
]));
$I->seeRecord(CartAddress::class, array_merge($addressData, [
'address_type' => CartAddress::ADDRESS_TYPE_BILLING,
'cart_id' => $mocks['cart']->id,
'customer_id' => $mocks['customer']->id,
]));
$I->sendAjaxPostRequest(route('shop.checkout.save-shipping'), [
'_token' => csrf_token(),
'shipping_method' => 'free_free',
]);
$I->seeResponseCodeIsSuccessful();
$I->sendAjaxPostRequest(route('shop.checkout.save-payment'), [
'_token' => csrf_token(),
'payment' => [
'method' => 'cashondelivery',
],
]);
$I->seeResponseCodeIsSuccessful();
$I->seeRecord(CartPayment::class, [
'method' => 'cashondelivery',
'method_title' => null,
'cart_id' => $mocks['cart']->id,
]);
$I->sendAjaxPostRequest(route('shop.checkout.save-order'),
['_token' => csrf_token()]
);
$I->seeResponseCodeIsSuccessful();
$order = $I->grabRecord(Order::class, [
'status' => 'pending',
'channel_name' => 'Default',
'is_guest' => 0,
'customer_first_name' => $customer->first_name,
'customer_last_name' => $customer->last_name,
'customer_email' => $customer->email,
'shipping_method' => 'free_free',
'shipping_title' => 'Free Shipping - Free Shipping',
'shipping_description' => 'Free Shipping',
'customer_type' => Customer::class,
'channel_id' => 1,
'channel_type' => Channel::class,
'cart_id' => $mocks['cart']->id,
'customer_id' => $customer->id,
'total_item_count' => count($mocks['cartItems']),
'total_qty_ordered' => $mocks['totalQtyOrdered'],
]);
$I->seeRecord(OrderAddress::class, array_merge($addressData, [
'order_id' => $order->id,
'address_type' => OrderAddress::ADDRESS_TYPE_SHIPPING,
'customer_id' => $mocks['customer']->id,
]));
$I->seeRecord(OrderAddress::class, array_merge($addressData, [
'order_id' => $order->id,
'address_type' => OrderAddress::ADDRESS_TYPE_BILLING,
'customer_id' => $mocks['customer']->id,
]));
$I->seeRecord(OrderPayment::class, [
'method' => 'cashondelivery',
'method_title' => null,
'order_id' => $order->id,
]);
return $order;
], $additionalData);
}
}