|
@@ -11,137 +11,53 @@ beforeEach(function () {
|
11
|
11
|
|
12
|
12
|
it('creates a basic invoice with line items and calculates totals correctly', function () {
|
13
|
13
|
$invoice = Invoice::factory()
|
14
|
|
- ->withLineItems(2)
|
|
14
|
+ ->withLineItems()
|
15
|
15
|
->create();
|
16
|
16
|
|
17
|
17
|
$invoice->refresh();
|
18
|
18
|
|
19
|
19
|
expect($invoice)
|
20
|
20
|
->hasLineItems()->toBeTrue()
|
21
|
|
- ->lineItems->count()->toBe(2)
|
|
21
|
+ ->lineItems->count()->toBe(3)
|
22
|
22
|
->subtotal->toBeGreaterThan(0)
|
23
|
23
|
->total->toBeGreaterThan(0)
|
24
|
24
|
->amount_due->toBe($invoice->total);
|
25
|
25
|
});
|
26
|
26
|
|
27
|
|
-describe('invoice approval', function () {
|
28
|
|
- beforeEach(function () {
|
29
|
|
- $this->invoice = Invoice::factory()
|
30
|
|
- ->withLineItems()
|
31
|
|
- ->approved()
|
32
|
|
- ->create();
|
33
|
|
- });
|
34
|
|
-
|
35
|
|
- test('approved invoices are marked as Unsent when not Overdue', function () {
|
36
|
|
- $this->invoice->update(['due_date' => now()->addDays(30)]);
|
37
|
|
-
|
38
|
|
- $this->invoice->refresh();
|
39
|
|
-
|
40
|
|
- expect($this->invoice)
|
41
|
|
- ->hasLineItems()->toBeTrue()
|
42
|
|
- ->status->toBe(InvoiceStatus::Unsent)
|
43
|
|
- ->wasApproved()->toBeTrue()
|
44
|
|
- ->approvalTransaction->not->toBeNull();
|
45
|
|
- });
|
46
|
|
-});
|
47
|
|
-
|
48
|
|
-it('creates sent invoices with line items and approval automatically', function () {
|
49
|
|
- $invoice = Invoice::factory()
|
50
|
|
- ->withLineItems()
|
51
|
|
- ->sent()
|
52
|
|
- ->create();
|
53
|
|
-
|
54
|
|
- $invoice->refresh();
|
55
|
|
-
|
56
|
|
- expect($invoice)
|
57
|
|
- ->hasLineItems()->toBeTrue()
|
58
|
|
- ->lineItems->count()->toBeGreaterThan(0)
|
59
|
|
- ->wasApproved()->toBeTrue()
|
60
|
|
- ->hasBeenSent()->toBeTrue()
|
61
|
|
- ->status->toBe(InvoiceStatus::Sent);
|
62
|
|
-});
|
63
|
|
-
|
64
|
|
-it('creates paid invoices with line items, approval, and payments automatically', function () {
|
|
27
|
+test('approved invoices are marked as Unsent when not Overdue', function () {
|
65
|
28
|
$invoice = Invoice::factory()
|
66
|
29
|
->withLineItems()
|
67
|
|
- ->paid()
|
|
30
|
+ ->state([
|
|
31
|
+ 'due_date' => now()->addDays(30),
|
|
32
|
+ ])
|
68
|
33
|
->create();
|
69
|
34
|
|
70
|
35
|
$invoice->refresh();
|
71
|
36
|
|
72
|
|
- expect($invoice)
|
73
|
|
- ->hasLineItems()->toBeTrue()
|
74
|
|
- ->lineItems->count()->toBeGreaterThan(0)
|
75
|
|
- ->wasApproved()->toBeTrue()
|
76
|
|
- ->hasBeenSent()->toBeTrue()
|
77
|
|
- ->hasPayments()->toBeTrue()
|
78
|
|
- ->isPaid()->toBeTrue()
|
79
|
|
- ->status->toBe(InvoiceStatus::Paid);
|
80
|
|
-});
|
81
|
|
-
|
82
|
|
-it('creates partial invoices with line items and partial payments automatically', function () {
|
83
|
|
- $invoice = Invoice::factory()
|
84
|
|
- ->withLineItems()
|
85
|
|
- ->partial()
|
86
|
|
- ->create();
|
87
|
|
-
|
88
|
|
- $invoice->refresh();
|
|
37
|
+ $invoice->approveDraft();
|
89
|
38
|
|
90
|
39
|
expect($invoice)
|
91
|
40
|
->hasLineItems()->toBeTrue()
|
92
|
|
- ->lineItems->count()->toBeGreaterThan(0)
|
|
41
|
+ ->status->toBe(InvoiceStatus::Unsent)
|
93
|
42
|
->wasApproved()->toBeTrue()
|
94
|
|
- ->hasBeenSent()->toBeTrue()
|
95
|
|
- ->hasPayments()->toBeTrue()
|
96
|
|
- ->status->toBeIn([InvoiceStatus::Partial, InvoiceStatus::Overdue])
|
97
|
|
- ->amount_paid->toBeGreaterThan(0)
|
98
|
|
- ->amount_paid->toBeLessThan($invoice->total);
|
|
43
|
+ ->approvalTransaction->not->toBeNull();
|
99
|
44
|
});
|
100
|
45
|
|
101
|
|
-it('creates overpaid invoices with line items and overpayments automatically', function () {
|
|
46
|
+test('approved invoices are marked as Overdue when Overdue', function () {
|
102
|
47
|
$invoice = Invoice::factory()
|
103
|
48
|
->withLineItems()
|
104
|
|
- ->overpaid()
|
|
49
|
+ ->state([
|
|
50
|
+ 'due_date' => now()->subDays(30),
|
|
51
|
+ ])
|
105
|
52
|
->create();
|
106
|
53
|
|
107
|
54
|
$invoice->refresh();
|
108
|
55
|
|
109
|
|
- expect($invoice)
|
110
|
|
- ->hasLineItems()->toBeTrue()
|
111
|
|
- ->lineItems->count()->toBeGreaterThan(0)
|
112
|
|
- ->wasApproved()->toBeTrue()
|
113
|
|
- ->hasBeenSent()->toBeTrue()
|
114
|
|
- ->hasPayments()->toBeTrue()
|
115
|
|
- ->status->toBe(InvoiceStatus::Overpaid)
|
116
|
|
- ->amount_paid->toBeGreaterThan($invoice->total);
|
117
|
|
-});
|
118
|
|
-
|
119
|
|
-it('creates overdue invoices with line items and approval automatically', function () {
|
120
|
|
- $invoice = Invoice::factory()
|
121
|
|
- ->withLineItems()
|
122
|
|
- ->overdue()
|
123
|
|
- ->create();
|
124
|
|
-
|
125
|
|
- $invoice->refresh();
|
|
56
|
+ $invoice->approveDraft();
|
126
|
57
|
|
127
|
58
|
expect($invoice)
|
128
|
59
|
->hasLineItems()->toBeTrue()
|
129
|
|
- ->lineItems->count()->toBeGreaterThan(0)
|
130
|
|
- ->wasApproved()->toBeTrue()
|
131
|
60
|
->status->toBe(InvoiceStatus::Overdue)
|
132
|
|
- ->due_date->toBeLessThan(now());
|
133
|
|
-});
|
134
|
|
-
|
135
|
|
-it('handles factory configure method without duplicate line items', function () {
|
136
|
|
- $invoice = Invoice::factory()
|
137
|
|
- ->withLineItems(2)
|
138
|
|
- ->create();
|
139
|
|
-
|
140
|
|
- $invoice->refresh();
|
141
|
|
-
|
142
|
|
- expect($invoice)
|
143
|
|
- ->hasLineItems()->toBeTrue()
|
144
|
|
- ->lineItems->count()->toBe(2)
|
145
|
|
- ->invoice_number->toStartWith('INV-')
|
146
|
|
- ->order_number->toStartWith('ORD-');
|
|
61
|
+ ->wasApproved()->toBeTrue()
|
|
62
|
+ ->approvalTransaction->not->toBeNull();
|
147
|
63
|
});
|