Repository navigation
Expand file tree
/
Copy pathMailBrandingTest.php
More file actions
191 lines (170 loc) · 7.42 KB
/
Copy pathMailBrandingTest.php
File metadata and controls
191 lines (170 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
namespace Tests\Feature;
use App\Mail\InvoicePaymentAcknowledgmentClientMail;
use App\Mail\NotificationBrandingPreviewMail;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\InvoiceDelivery;
use App\Models\InvoicePayment;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Tests\TestCase;
class MailBrandingTest extends TestCase
{
use RefreshDatabase;
public function test_payment_acknowledgment_mail_uses_cryptozing_shared_branding(): void
{
$owner = User::factory()->create([
'name' => 'Antonina Owner',
'email' => 'antonina12@nospam.site',
]);
$client = Client::create([
'user_id' => $owner->id,
'name' => 'Phase 3 QA Client',
'email' => 'ms16-phase3-qa@nospam.site',
]);
$invoice = Invoice::create([
'user_id' => $owner->id,
'client_id' => $client->id,
'number' => 'INV-MAIL-BRAND',
'description' => 'Branding proof',
'amount_usd' => 80,
'btc_rate' => 40_000,
'amount_btc' => 0.002,
'payment_address' => 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080',
'status' => 'paid',
'public_enabled' => true,
'public_token' => 'mail-branding-proof',
'public_expires_at' => Carbon::now()->addDay(),
'invoice_date' => Carbon::now()->toDateString(),
'due_date' => Carbon::now()->addWeek()->toDateString(),
]);
$payment = InvoicePayment::create([
'invoice_id' => $invoice->id,
'accounting_invoice_id' => $invoice->id,
'txid' => 'mail-branding-proof-tx',
'sats_received' => 200_000,
'detected_at' => Carbon::now(),
'confirmed_at' => Carbon::now(),
'usd_rate' => 40_000,
'fiat_amount' => 80.00,
]);
$delivery = InvoiceDelivery::create([
'invoice_id' => $invoice->id,
'user_id' => $owner->id,
'type' => 'payment_acknowledgment_client',
'context_key' => $payment->txid,
'status' => 'sent',
'recipient' => $client->email,
'dispatched_at' => Carbon::now(),
'sent_at' => Carbon::now(),
]);
$html = (new InvoicePaymentAcknowledgmentClientMail(
$invoice->fresh(['client', 'user']),
$delivery,
$payment
));
$html = $html->render();
$this->assertStringContainsString('CryptoZing', $html);
$this->assertStringContainsString('Non-custodial bitcoin invoicing', $html);
$this->assertStringContainsString('Create bitcoin invoices, monitor incoming payments, and send receipts with CryptoZing.', $html);
$this->assertStringContainsString('Bitcoin payment detected', $html);
$this->assertStringContainsString('A Bitcoin payment of', $html);
$this->assertStringNotContainsString('for Invoice ' . $invoice->number, $html);
$this->assertStringNotContainsString('for this invoice', $html);
$this->assertTrue(
str_contains($html, 'cid:')
|| str_contains($html, 'data:image/png;base64,'),
'Expected inline email logo markup.'
);
$this->assertStringNotContainsString('https://cryptozing.app/images/CZ.png', $html);
$this->assertStringNotContainsString('notification-logo.png', $html);
$this->assertStringNotContainsString('Laravel Logo', $html);
$this->assertSame('Bitcoin payment detected', (new InvoicePaymentAcknowledgmentClientMail(
$invoice->fresh(['client', 'user']),
$delivery,
$payment
))->envelope()->subject);
}
public function test_payment_acknowledgment_mail_uses_owner_mail_branding_overrides(): void
{
$owner = User::factory()->create([
'name' => 'Antonina Owner',
'email' => 'antonina12@nospam.site',
'mail_brand_name' => 'Phase 3 Mail',
'mail_brand_tagline' => 'Owner-reviewed bitcoin receipts',
'mail_footer_blurb' => 'Phase 3 custom footer blurb.',
]);
$client = Client::create([
'user_id' => $owner->id,
'name' => 'Phase 3 QA Client',
'email' => 'ms16-phase3-qa@nospam.site',
]);
$invoice = Invoice::create([
'user_id' => $owner->id,
'client_id' => $client->id,
'number' => 'INV-MAIL-BRAND-CUSTOM',
'description' => 'Branding proof',
'amount_usd' => 80,
'btc_rate' => 40_000,
'amount_btc' => 0.002,
'payment_address' => 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080',
'status' => 'paid',
'public_enabled' => true,
'public_token' => 'mail-branding-proof-custom',
'public_expires_at' => Carbon::now()->addDay(),
'invoice_date' => Carbon::now()->toDateString(),
'due_date' => Carbon::now()->addWeek()->toDateString(),
]);
$payment = InvoicePayment::create([
'invoice_id' => $invoice->id,
'accounting_invoice_id' => $invoice->id,
'txid' => 'mail-branding-proof-custom-tx',
'sats_received' => 200_000,
'detected_at' => Carbon::now(),
'confirmed_at' => Carbon::now(),
'usd_rate' => 40_000,
'fiat_amount' => 80.00,
]);
$delivery = InvoiceDelivery::create([
'invoice_id' => $invoice->id,
'user_id' => $owner->id,
'type' => 'payment_acknowledgment_client',
'context_key' => $payment->txid,
'status' => 'sent',
'recipient' => $client->email,
'dispatched_at' => Carbon::now(),
'sent_at' => Carbon::now(),
]);
$html = (new InvoicePaymentAcknowledgmentClientMail(
$invoice->fresh(['client', 'user']),
$delivery,
$payment
))->render();
$this->assertStringContainsString('Phase 3 Mail', $html);
$this->assertStringContainsString('Owner-reviewed bitcoin receipts', $html);
$this->assertStringContainsString('Phase 3 custom footer blurb.', $html);
$this->assertStringNotContainsString('Non-custodial bitcoin invoicing', $html);
}
public function test_notification_branding_preview_mail_uses_saved_branding_and_can_hide_logo(): void
{
$owner = User::factory()->create([
'name' => 'Antonina Owner',
'email' => 'antonina12@nospam.site',
'mail_brand_name' => 'Phase 3 Mail',
'mail_brand_tagline' => 'Owner-reviewed bitcoin receipts',
'mail_footer_blurb' => 'Phase 3 custom footer blurb.',
'show_mail_logo' => false,
]);
$html = (new NotificationBrandingPreviewMail($owner))->render();
$this->assertStringContainsString('Test email', $html);
$this->assertStringContainsString('Phase 3 Mail', $html);
$this->assertStringContainsString('Owner-reviewed bitcoin receipts', $html);
$this->assertStringContainsString('Phase 3 custom footer blurb.', $html);
$this->assertStringNotContainsString('cid:', $html);
$this->assertStringNotContainsString('data:image/png;base64,', $html);
$this->assertStringNotContainsString(' RC', $html);
$this->assertStringNotContainsString('MS16', $html);
}
}