Revision 9124f9ab
Von Werner Hahn vor mehr als 7 Jahren hinzugefügt
t/shop/json_ok.json | ||
---|---|---|
1 |
{"data":{"id":2,"number":"20001","customerId":1,"paymentId":5,"dispatchId":9,"partnerId":"","shopId":1,"invoiceAmount":153.85,"invoiceAmountNet":129.29,"invoiceShipping":3.9,"invoiceShippingNet":3.28,"orderTime":"2017-09-07T14:15:44+0200","transactionId":"","comment":"","customerComment":"","internalComment":"","net":0,"taxFree":0,"temporaryId":"","referer":"","clearedDate":null,"trackingCode":"","languageIso":"1","currency":"EUR","currencyFactor":1,"remoteAddress":"91.36.133.94","deviceType":"desktop","details":[{"id":2,"orderId":2,"articleId":2,"taxId":1,"taxRate":19,"statusId":0,"number":"20001","articleNumber":"SW10002","price":149.95,"quantity":1,"articleName":"TITANIUM CARBON GS 120 cm","shipped":0,"shippedGroup":0,"releaseDate":"-0001-11-30T00:00:00+0100","mode":0,"esdArticle":0,"config":"","ean":"","unit":"","packUnit":"Paar","attribute":{"id":2,"orderDetailId":2,"attribute1":"","attribute2":null,"attribute3":null,"attribute4":null,"attribute5":null,"attribute6":null}}],"documents":[],"payment":{"id":5,"name":"prepayment","description":"Vorkasse","template":"prepayment.tpl","class":"prepayment.php","table":"","hide":false,"additionalDescription":"Sie zahlen einfach vorab und erhalten die Ware bequem und g\u00fcnstig bei Zahlungseingang nach Hause geliefert.","debitPercent":0,"surcharge":0,"surchargeString":"","position":1,"active":true,"esdActive":false,"mobileInactive":false,"embedIFrame":"","hideProspect":0,"action":null,"pluginId":null,"source":null,"attribute":null},"paymentStatus":{"id":17,"name":"open","description":"Offen","position":0,"group":"payment","sendMail":0},"orderStatus":{"id":0,"name":"open","description":"Offen","position":1,"group":"state","sendMail":1},"customer":{"number":"20003","id":1,"paymentId":5,"groupKey":"EK","shopId":1,"priceGroupId":null,"encoderName":"bcrypt","hashPassword":"$2y$10$.TqdM5h2qNqtJbzKF7GpP.kUXWL2UOylkgbqKBU6WuOpDladvkGva","active":true,"email":"werner.hahn@vulke.de","firstLogin":"2017-09-07T00:00:00+0200","lastLogin":"2017-09-07T14:15:44+0200","accountMode":1,"confirmationKey":"","sessionId":"10i196b4lm3r1gjdnurkq18j22","newsletter":0,"validation":"","affiliate":0,"paymentPreset":0,"languageId":"1","referer":"","internalComment":"","failedLogins":0,"lockedUntil":null,"salutation":"mr","title":null,"firstname":"Kalli","lastname":"Kr\u00fcger","birthday":null},"paymentInstances":[{"orderId":2,"firstName":"Kalli","lastName":"Kr\u00fcger","address":"Dorfstr. 6","zipCode":"37318","city":"Sch\u00f6nhagen","bankName":null,"bankCode":null,"accountNumber":null,"accountHolder":null,"bic":null,"iban":null,"amount":"153.8500","createdAt":"2017-09-07T00:00:00+0200","id":1}],"billing":{"title":null,"additionalAddressLine1":null,"additionalAddressLine2":null,"id":1,"orderId":2,"customerId":1,"countryId":2,"stateId":null,"company":"","department":"","salutation":"mr","number":"20003","firstName":"Kalli","lastName":"Kr\u00fcger","street":"Dorfstr. 6","zipCode":"37318","city":"Sch\u00f6nhagen","phone":"","vatId":null,"country":{"id":2,"name":"Deutschland","iso":"DE","isoName":"GERMANY","position":1,"description":"","taxFree":0,"taxFreeUstId":0,"taxFreeUstIdChecked":0,"active":true,"iso3":"DEU","displayStateInRegistration":false,"forceStateInRegistration":false,"areaId":1},"state":null,"attribute":{"id":1,"orderBillingId":1,"text1":null,"text2":null,"text3":null,"text4":null,"text5":null,"text6":null}},"shipping":{"title":"","additionalAddressLine1":"","additionalAddressLine2":"","id":1,"orderId":2,"countryId":2,"stateId":null,"customerId":1,"company":"","department":"","salutation":"mr","firstName":"Kalli","lastName":"Kr\u00fcger","street":"Dorfstr. 6","zipCode":"37318","city":"Sch\u00f6nhagen","attribute":{"id":1,"orderShippingId":1,"text1":null,"text2":null,"text3":null,"text4":null,"text5":null,"text6":null},"country":{"id":2,"name":"Deutschland","iso":"DE","isoName":"GERMANY","position":1,"description":"","taxFree":0,"taxFreeUstId":0,"taxFreeUstIdChecked":0,"active":true,"iso3":"DEU","displayStateInRegistration":false,"forceStateInRegistration":false,"areaId":1},"state":null},"shop":{"id":1,"mainId":null,"categoryId":3,"name":"Demoshop","title":null,"position":0,"host":"shopware.vulke.de","basePath":"","baseUrl":null,"hosts":"shopware.vulke.de","secure":false,"alwaysSecure":false,"secureHost":null,"secureBasePath":null,"templateId":23,"default":true,"active":true,"customerScope":false},"dispatch":{"id":9,"name":"Standard Versand","type":0,"description":"","comment":"","active":true,"position":0,"calculation":0,"surchargeCalculation":3,"taxCalculation":0,"shippingFree":null,"multiShopId":null,"customerGroupId":null,"bindShippingFree":0,"bindTimeFrom":null,"bindTimeTo":null,"bindInStock":null,"bindLastStock":0,"bindWeekdayFrom":null,"bindWeekdayTo":null,"bindWeightFrom":null,"bindWeightTo":null,"bindPriceFrom":null,"bindPriceTo":null,"bindSql":null,"statusLink":"","calculationSql":null,"attribute":null},"attribute":{"id":2,"orderId":2,"attribute1":null,"attribute2":null,"attribute3":null,"attribute4":null,"attribute5":null,"attribute6":null},"languageSubShop":{"id":1,"mainId":null,"categoryId":3,"name":"Demoshop","title":null,"position":0,"host":"shopware.vulke.de","basePath":"","baseUrl":null,"hosts":"shopware.vulke.de","secure":false,"alwaysSecure":false,"secureHost":null,"secureBasePath":null,"templateId":23,"default":true,"active":true,"customerScope":false,"locale":{"id":1,"locale":"de_DE","language":"Deutsch","territory":"Deutschland"}},"paymentStatusId":17,"orderStatusId":0},"success":true} |
t/shop/shop_order.t | ||
---|---|---|
1 |
use strict; |
|
2 |
use Test::More; |
|
3 |
|
|
4 |
use lib 't'; |
|
5 |
use Support::TestSetup; |
|
6 |
use Carp; |
|
7 |
use Test::Exception; |
|
8 |
use SL::Dev::ALL; |
|
9 |
use SL::DB::Shop; |
|
10 |
use SL::DB::ShopOrder; |
|
11 |
use SL::DB::ShopOrderItem; |
|
12 |
use SL::Controller::ShopOrder; |
|
13 |
use Data::Dumper; |
|
14 |
|
|
15 |
my ($shop, $shop_order, $shop_part, $part, $customer, $employee); |
|
16 |
|
|
17 |
sub reset_state { |
|
18 |
my %params = @_; |
|
19 |
|
|
20 |
clear_up(); |
|
21 |
|
|
22 |
$shop = SL::Dev::Shop::new_shop->save; |
|
23 |
$part = SL::Dev::Part::new_part->save; |
|
24 |
$shop_part = SL::Dev::Shop::new_shop_part(part => $part, shop => $shop)->save; |
|
25 |
|
|
26 |
$employee = SL::DB::Manager::Employee->current || croak "No employee"; |
|
27 |
|
|
28 |
$customer = SL::Dev::CustomerVendor::new_customer( |
|
29 |
name => 'Evil Inc', |
|
30 |
street => 'Evil Street', |
|
31 |
zipcode => '66666', |
|
32 |
email => 'evil@evilinc.com' |
|
33 |
)->save; |
|
34 |
} |
|
35 |
|
|
36 |
sub save_shorcontroller_to_string { |
|
37 |
|
|
38 |
my $output; |
|
39 |
open(my $outputFH, '<', \$output) or die "OUTPUT"; |
|
40 |
my $oldFH = select $outputFH; |
|
41 |
my $shor_controller = SL::Controller::ShopOrder->new; |
|
42 |
$shor_controller->action_transfer; |
|
43 |
|
|
44 |
select $oldFH; |
|
45 |
close $outputFH; |
|
46 |
return $output; |
|
47 |
} |
|
48 |
sub test_transfer { |
|
49 |
my ( %params ) = @_; |
|
50 |
$::form = Support::TestSetup->create_new_form; |
|
51 |
$::form->{import_id} = $params{import_id}; |
|
52 |
$::form->{customer} = $params{customer}; |
|
53 |
my $test_name = 'Test Controller Action Transfer'; |
|
54 |
save_shorcontroller_to_string(); |
|
55 |
my @links_record = RecordLinks->get_links( 'from_table' => 'shop_orders', |
|
56 |
'from_id' => $params{import_id}, |
|
57 |
'to_table' => 'oe', |
|
58 |
); |
|
59 |
is($links_record[0]->{from_id} , $params{import_id}, "record from id check"); |
|
60 |
is($links_record[0]->{from_table} , 'shop_orders' , "record from table <shop_orders> check"); |
|
61 |
is($links_record[0]->{to_table} , 'oe' , "record to table <oe> check"); |
|
62 |
} |
|
63 |
|
|
64 |
Support::TestSetup::login(); |
|
65 |
|
|
66 |
reset_state(); |
|
67 |
|
|
68 |
my $shop_trans_id = 1; |
|
69 |
|
|
70 |
$shop_order = SL::Dev::Shop::new_shop_order( |
|
71 |
shop => $shop, |
|
72 |
shop_trans_id => $shop_trans_id, |
|
73 |
amount => 59.5, |
|
74 |
billing_lastname => 'Schmidt', |
|
75 |
billing_firstname => 'Sven', |
|
76 |
billing_company => 'Evil Inc', |
|
77 |
billing_street => 'Evil Street', |
|
78 |
billing_zipcode => $customer->zipcode, |
|
79 |
billing_email => $customer->email, |
|
80 |
); |
|
81 |
|
|
82 |
my $shop_order_item = SL::DB::ShopOrderItem->new( |
|
83 |
partnumber => $part->partnumber, |
|
84 |
position => 1, |
|
85 |
quantity => 5, |
|
86 |
price => 10, |
|
87 |
shop_trans_id => $shop_trans_id, |
|
88 |
); |
|
89 |
$shop_order->shop_order_items( [ $shop_order_item ] ); |
|
90 |
$shop_order->save; |
|
91 |
|
|
92 |
note('testing check_for_existing_customers'); |
|
93 |
my $fuzzy_customers = $shop_order->check_for_existing_customers; |
|
94 |
|
|
95 |
is(scalar @{ $fuzzy_customers }, 1, 'found 1 matching customer'); |
|
96 |
is($fuzzy_customers->[0]->name, 'Evil Inc', 'matched customer Evil Inc'); |
|
97 |
|
|
98 |
note('adding a not-so-similar customer'); |
|
99 |
my $customer_different = SL::Dev::CustomerVendor::new_customer( |
|
100 |
name => "Different Name", |
|
101 |
street => 'Good Straet', # difference large enough from "Evil Street" |
|
102 |
zipcode => $customer->zipcode, |
|
103 |
email => "foo", |
|
104 |
)->save; |
|
105 |
$fuzzy_customers = $shop_order->check_for_existing_customers; |
|
106 |
is(scalar @{ $fuzzy_customers }, 1, 'still only found 1 matching customer (zipcode equal + street dissimilar'); |
|
107 |
|
|
108 |
note('adding a similar customer'); |
|
109 |
my $customer_similar = SL::Dev::CustomerVendor::new_customer( |
|
110 |
name => "Different Name", |
|
111 |
street => 'Good Street', # difference not large enough from "Evil Street", street matches |
|
112 |
zipcode => $customer->zipcode, |
|
113 |
email => "foo", |
|
114 |
)->save; |
|
115 |
$fuzzy_customers = $shop_order->check_for_existing_customers; |
|
116 |
is(scalar @{ $fuzzy_customers }, 2, 'found 2 matching customers (zipcode equal + street similar)'); |
|
117 |
|
|
118 |
is($shop->description , 'testshop' , 'shop description ok'); |
|
119 |
is($shop_order->shop_id , $shop->id , "shop_id ok"); |
|
120 |
|
|
121 |
note('testing convert_to_sales_order'); |
|
122 |
my $order = $shop_order->convert_to_sales_order(employee => $employee, customer => $customer); |
|
123 |
$order->calculate_prices_and_taxes; |
|
124 |
$order->save; |
|
125 |
|
|
126 |
is(ref($order), 'SL::DB::Order', 'order ok'); |
|
127 |
is($order->amount, 59.5, 'order amount ok'); |
|
128 |
is($order->netamount, 50, 'order netamount ok'); |
|
129 |
|
|
130 |
test_transfer( import_id => $shop_order->id , customer => $customer->id ); |
|
131 |
|
|
132 |
done_testing; |
|
133 |
|
|
134 |
clear_up(); |
|
135 |
|
|
136 |
1; |
|
137 |
|
|
138 |
sub clear_up { |
|
139 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(OrderItem Order); |
|
140 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(ShopPart Part ShopOrderItem ShopOrder Shop Customer); |
|
141 |
} |
t/shop/shopware.t | ||
---|---|---|
1 |
use strict; |
|
2 |
use Test::More; |
|
3 |
|
|
4 |
use lib 't'; |
|
5 |
use Support::TestSetup; |
|
6 |
use Carp; |
|
7 |
use Test::Exception; |
|
8 |
use SL::Dev::ALL; |
|
9 |
use SL::DB::Shop; |
|
10 |
use SL::DB::ShopOrder; |
|
11 |
use SL::DB::ShopOrderItem; |
|
12 |
use SL::Controller::ShopOrder; |
|
13 |
use SL::Shop; |
|
14 |
use Data::Dumper; |
|
15 |
use SL::JSON; |
|
16 |
use SL::ShopConnector::Shopware; |
|
17 |
my ($shop, $shopware, $shop_order, $shop_part, $part, $customer, $employee, $json_import); |
|
18 |
|
|
19 |
sub reset_state { |
|
20 |
my %params = @_; |
|
21 |
|
|
22 |
clear_up(); |
|
23 |
|
|
24 |
$shop = SL::Dev::Shop::new_shop( connector => 'shopware', |
|
25 |
last_order_number => 20000, |
|
26 |
pricetype => 'brutto', |
|
27 |
price_source => 'master_data', |
|
28 |
taxzone_id => 1, |
|
29 |
); |
|
30 |
$shopware = SL::Shop->new( config => $shop ); |
|
31 |
$part = SL::Dev::Part::new_part( partnumber => 'SW10002', |
|
32 |
description => 'TITANIUM CARBON GS 12m cm', |
|
33 |
); |
|
34 |
$shop_part = SL::Dev::Shop::new_shop_part(part => $part, shop => $shop); |
|
35 |
|
|
36 |
$employee = SL::DB::Manager::Employee->current || croak "No employee"; |
|
37 |
|
|
38 |
$customer = SL::Dev::CustomerVendor::new_customer( |
|
39 |
name => 'Evil Inc', |
|
40 |
street => 'Evil Street', |
|
41 |
zipcode => '66666', |
|
42 |
email => 'evil@evilinc.com' |
|
43 |
)->save; |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
sub get_json { |
|
48 |
local $/; |
|
49 |
my $file = "t/shop/json_ok.json"; |
|
50 |
my $json_text = do { |
|
51 |
open(my $json_fh, "<:encoding(UTF-8)", $file) |
|
52 |
or die("Can't open \"$file\": $!\n"); |
|
53 |
local $/; |
|
54 |
<$json_fh> |
|
55 |
}; |
|
56 |
|
|
57 |
return $json_text; |
|
58 |
} |
|
59 |
|
|
60 |
sub test_import { |
|
61 |
|
|
62 |
my $json_import = get_json(); |
|
63 |
note('testing shoporder mapping json good'); |
|
64 |
my $import = SL::JSON::decode_json($json_import); |
|
65 |
$shop_order = $shopware->connector->import_data_to_shop_order($import); |
|
66 |
is($shop_order->shop_id , $shop->id , "shop_id ok"); |
|
67 |
} |
|
68 |
|
|
69 |
Support::TestSetup::login(); |
|
70 |
|
|
71 |
reset_state(); |
|
72 |
|
|
73 |
test_import(); |
|
74 |
|
|
75 |
done_testing; |
|
76 |
|
|
77 |
clear_up(); |
|
78 |
|
|
79 |
1; |
|
80 |
|
|
81 |
sub clear_up { |
|
82 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(OrderItem Order); |
|
83 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(ShopPart Part ShopOrderItem ShopOrder Shop Customer); |
|
84 |
} |
Auch abrufbar als: Unified diff
WebshopApi: Tests