From 70be199dcf5fce26ed23ac769e10ad7b6b3991c1 Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 20 Dec 2022 20:37:29 +0000 Subject: [PATCH] fixed tests for ordering --- t/unit_fixture/CXGN/Stock/CatalogOrder.t | 78 ++++++++++-------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/t/unit_fixture/CXGN/Stock/CatalogOrder.t b/t/unit_fixture/CXGN/Stock/CatalogOrder.t index 039ba97c70..ec1cb2069e 100644 --- a/t/unit_fixture/CXGN/Stock/CatalogOrder.t +++ b/t/unit_fixture/CXGN/Stock/CatalogOrder.t @@ -15,7 +15,7 @@ use CXGN::Stock::OrderBatch; use CXGN::UploadFile; use CXGN::Stock::ParseUpload; use CXGN::List; - +use Test::WWW::Mechanize; use DateTime; use Data::Dumper; @@ -27,8 +27,16 @@ my $schema = $f->bcs_schema(); my $people_schema = $f->people_schema; my $dbh = $f->dbh(); +my $mech = Test::WWW::Mechanize->new; + for my $extension ("xls", "xlsx") { + $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username" => "janedoe", "password" => "secretpw", "grant_type" => "password" ]); + my $response = decode_json $mech->content; + is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull'); + my $sgn_session_id = $response->{access_token}; + print STDERR $sgn_session_id . "\n"; + #add vendor role for johndoe my $johndoe_id = CXGN::People::Person->get_person_by_username($dbh, 'johndoe'); my $role_rs = $people_schema->resultset("SpRole")->find({ name => 'vendor' }); @@ -144,47 +152,14 @@ for my $extension ("xls", "xlsx") { my $your_cart_id = CXGN::List::create_list($dbh, 'your_cart', 'test shopping cart', $janedoe_id); my $list = CXGN::List->new({ dbh => $dbh, list_id => $your_cart_id }); my $your_cart_type = $list->type('catalog_items'); - my $item1 = $list->add_element("UG120001,Quantity: 2"); - my $item2 = $list->add_element("UG120002,Quantity: 3"); + my $item1 = $list->add_element('{"Item Name":"UG120001","Quantity":"2","Comments":""}'); + my $item2 = $list->add_element('{"Item Name":"UG120002","Quantity":"3","Comments":""}'); #test storing an order from janedoe, to johndoe - my $new_order = CXGN::Stock::Order->new({ people_schema => $people_schema, dbh => $dbh }); - $new_order->order_from_id($janedoe_id); - $new_order->order_to_id($johndoe_id); - $new_order->order_status("submitted"); - $new_order->create_date($timestamp); - ok(my $order_id = $new_order->store(), "check storing order"); - - #test storing orderprop - my $your_cart = CXGN::List->new({ dbh => $dbh, list_id => $your_cart_id }); - my $items = $list->elements(); - is_deeply($items, [ 'UG120001,Quantity: 2', 'UG120002,Quantity: 3' ], 'check items'); - - my @all_items = @$items; - my @clone_list; - foreach my $ordered_item (@all_items) { - my %item_hash; - my @ordered_item_split = split /,/, $ordered_item; - my $item_name = $ordered_item_split[0]; - - my $quantity_string = $ordered_item_split[1]; - my @quantity_info = split /:/, $quantity_string; - my $quantity = $quantity_info[1]; - $quantity =~ s/^\s+|\s+$//g; - $item_hash{$item_name}{'quantity'} = $quantity; - push @clone_list, \%item_hash; - } - - my @history; - my $history_info = {}; - $history_info->{'submitted'} = $timestamp; - push @history, $history_info; - my $order_prop = CXGN::Stock::OrderBatch->new({ bcs_schema => $schema, people_schema => $people_schema }); - $order_prop->clone_list(\@clone_list); - $order_prop->parent_id($order_id); - $order_prop->history(\@history); - ok(my $order_prop_id = $order_prop->store_sp_orderprop(), "check storing orderprop"); + $mech->post_ok('http://localhost:3010/ajax/order/submit', ['list_id' => $your_cart_id,]); + $response = decode_json $mech->content; + is($response->{'success'}, 'Your order has been submitted successfully and the vendor has been notified.'); #delete your cart CXGN::List::delete_list($dbh, $your_cart_id); @@ -192,24 +167,35 @@ for my $extension ("xls", "xlsx") { #test retrieving order from janedoe my $buyer_order_obj = CXGN::Stock::Order->new({ dbh => $dbh, people_schema => $people_schema, order_from_id => $janedoe_id }); my $buyer_orders = $buyer_order_obj->get_orders_from_person_id(); - is($buyer_orders->[0][0], '1'); - is($buyer_orders->[0][2], 'UG120001, quantity:2
UG120002, quantity:3'); - is($buyer_orders->[0][3], 'submitted'); - is($buyer_orders->[0][4], undef); - is($buyer_orders->[0][5], 'John Doe'); - is($buyer_orders->[0][6], undef); + my $first_order_info = $buyer_orders->[0]; + is($first_order_info->{'order_id'}, '1'); + is($first_order_info->{'order_status'}, 'submitted'); + is($first_order_info->{'order_to_name'}, 'John Doe'); + + my $items = $first_order_info->{'clone_list'}; + my $buyer_num_items = @$items; + is($buyer_num_items, '2'); #test retrieving order to johndoe my $vendor_order_obj = CXGN::Stock::Order->new({ dbh => $dbh, people_schema => $people_schema, order_to_id => $johndoe_id }); my $vendor_orders = $vendor_order_obj->get_orders_to_person_id(); + my $order = $vendor_orders->[0]; is($order->{'order_id'}, '1'); - is($order->{'item_list'}, 'UG120001, quantity:2
UG120002, quantity:3'); is($order->{'order_status'}, 'submitted'); is($order->{'order_from_name'}, 'Jane Doe'); is($order->{'completion_date'}, undef); is($order->{'contact_person_comments'}, undef); + my $clone_list = $order->{'clone_list'}; + my $vendor_num_items = @$clone_list; + is($vendor_num_items, '2'); + + #test_single_step_submission + $mech->post_ok('http://localhost:3010/ajax/order/single_step_submission', ['item_name' => 'UG120001', 'order_details' => '{"Quantity":"2","Comments":""}']); + $response = decode_json $mech->content; + is($response->{'success'}, 'Your request has been submitted successfully and the vendor has been notified.'); + #test deleting catalog my $catalog_rs = $schema->resultset("Stock::Stockprop")->search({ type_id => $catalog_type_id });