Massenerstellen von Rechnungen aus LS: js: Klasse "loading" setzen raus
[kivitendo-erp.git] / 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::Dev::Part qw(new_part);
10 use SL::Dev::Shop qw(new_shop new_shop_part);
11 use SL::Dev::CustomerVendor qw(new_customer);
12 use SL::DB::Shop;
13 use SL::DB::ShopOrder;
14 use SL::DB::ShopOrderItem;
15 use SL::Controller::ShopOrder;
16 use SL::Shop;
17 use Data::Dumper;
18 use SL::JSON;
19 use SL::ShopConnector::Shopware;
20 my ($shop, $shopware, $shop_order, $shop_part, $part, $customer, $employee, $json_import);
21
22 sub reset_state {
23   my %params = @_;
24
25   clear_up();
26
27   $shop = new_shop( connector         => 'shopware',
28                     last_order_number => 20000,
29                     pricetype         => 'brutto',
30                     price_source      => 'master_data',
31                     taxzone_id        => 1,
32                   );
33   $shopware = SL::Shop->new( config => $shop );
34   $part = new_part( partnumber   => 'SW10002',
35                     description  => 'TITANIUM CARBON GS 12m cm',
36                   );
37   $shop_part = new_shop_part(part => $part, shop => $shop);
38
39   $employee = SL::DB::Manager::Employee->current || croak "No employee";
40
41   $customer = new_customer( name    => 'Evil Inc',
42                             street  => 'Evil Street',
43                             zipcode => '66666',
44                             email   => 'evil@evilinc.com'
45                           )->save;
46 }
47
48 sub get_json {
49   local $/;
50   my $file = "t/shop/json_ok.json";
51   my $json_text = do {
52     open(my $json_fh, "<:encoding(UTF-8)", $file)
53          or die("Can't open \"$file\": $!\n");
54     local $/;
55     <$json_fh>
56   };
57
58   return $json_text;
59 }
60
61 sub test_import {
62
63   my $json_import = get_json();
64   note('testing shoporder mapping json good');
65   my $import = SL::JSON::decode_json($json_import);
66   $shop_order = $shopware->connector->import_data_to_shop_order($import);
67   is($shop_order->shop_id , $shop->id  , "shop_id ok");
68 }
69
70 Support::TestSetup::login();
71
72 reset_state();
73
74 test_import();
75
76 done_testing;
77
78 clear_up();
79
80 1;
81
82 sub clear_up {
83   "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(OrderItem Order);
84   "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(ShopPart Part ShopOrderItem ShopOrder Shop Customer);
85 }