Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1f0148b4

Von Kivitendo Admin vor mehr als 7 Jahren hinzugefügt

  • ID 1f0148b45dcf2ba5835f35c74f77ccda5c1b3a67
  • Vorgänger 196cb3e0
  • Nachfolger ab144e10

shop_order.t - erster Test für SL::DB::ShopOrder

Unterschiede anzeigen:

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 Data::Dumper;
13

  
14
my ($shop, $shop_order, $shop_part, $part, $customer, $employee);
15

  
16
sub reset_state {
17
  my %params = @_;
18

  
19
  clear_up();
20

  
21
  $shop = SL::Dev::Shop::create_shop->save;
22
  $part = SL::Dev::Part::create_part->save;
23
  $shop_part = SL::Dev::Shop::create_shop_part(part => $part, shop => $shop)->save;
24

  
25
  $employee = SL::DB::Manager::Employee->current || croak "No employee";
26

  
27
  $customer = SL::Dev::CustomerVendor::create_customer(
28
    name    => 'Evil Inc',
29
    street  => 'Evil Street',
30
    zipcode => '66666',
31
    email   => 'evil@evilinc.com'
32
  )->save;
33
}
34

  
35
Support::TestSetup::login();
36

  
37
reset_state();
38

  
39
my $shop_trans_id = 1;
40

  
41
my $shop_order = SL::Dev::Shop::create_shop_order(
42
  shop              => $shop,
43
  shop_trans_id     => $shop_trans_id,
44
  amount            => 59.5,
45
  billing_lastname  => 'Schmidt',
46
  billing_firstname => 'Sven',
47
  billing_company   => 'Evil Inc',
48
  billing_street    => 'Evil Street',
49
  billing_zipcode   => $customer->zipcode,
50
  billing_email     => $customer->email,
51
);
52

  
53
my $shop_order_item = SL::DB::ShopOrderItem->new(
54
  partnumber    => $part->partnumber,
55
  position      => 1,
56
  quantity      => 5,
57
  price         => 10,
58
  shop_trans_id => $shop_trans_id,
59
);
60
$shop_order->shop_order_items( [ $shop_order_item ] );
61
$shop_order->save;
62

  
63
note('testing check_for_existing_customers');
64
my $fuzzy_customers = $shop_order->check_for_existing_customers;
65

  
66
is(scalar @{ $fuzzy_customers }, 1, 'found 1 matching customer');
67
is($fuzzy_customers->[0]->name, 'Evil Inc', 'matched customer Evil Inc');
68

  
69
note('adding a not-so-similar customer');
70
my $customer_different = SL::Dev::CustomerVendor::create_customer(
71
  name    => "Different Name",
72
  street  => 'Good Straet', # difference large enough from "Evil Street"
73
  zipcode => $customer->zipcode,
74
  email   => "foo",
75
)->save;
76
$fuzzy_customers = $shop_order->check_for_existing_customers;
77
is(scalar @{ $fuzzy_customers }, 1, 'still only found 1 matching customer (zipcode equal + street dissimilar');
78

  
79
note('adding a similar customer');
80
my $customer_similar = SL::Dev::CustomerVendor::create_customer(
81
  name    => "Different Name",
82
  street  => 'Good Street', # difference not large enough from "Evil Street", street matches
83
  zipcode => $customer->zipcode,
84
  email   => "foo",
85
)->save;
86
$fuzzy_customers = $shop_order->check_for_existing_customers;
87
is(scalar @{ $fuzzy_customers }, 2, 'found 2 matching customers (zipcode equal + street similar)');
88

  
89
is($shop->description   , 'testshop' , 'shop description ok');
90
is($shop_order->shop_id , $shop->id  , "shop_id ok");
91

  
92
note('testing convert_to_sales_order');
93
my $order = $shop_order->convert_to_sales_order(employee => $employee, customer => $customer);
94
$order->calculate_prices_and_taxes;
95
$order->save;
96

  
97
is(ref($order), 'SL::DB::Order', 'order ok');
98
is($order->amount,    59.5, 'order amount ok');
99
is($order->netamount, 50,   'order netamount ok');
100

  
101
done_testing;
102

  
103
clear_up();
104

  
105
1;
106

  
107
sub clear_up {
108
  "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(OrderItem Order ShopPart Part ShopOrderItem ShopOrder Shop Customer);
109
}

Auch abrufbar als: Unified diff