Diff -- /var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_pricing_v3_smoke.pl
Diff

/var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_pricing_v3_smoke.pl

added on local at 2026-07-01 21:47:40

Added
+114
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 2d62c16c661a
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# RePricer pricing v3 smoke test.
4# Runs from the vhost root so it can use MODS:: modules.
5#
6# Steps:
7# 1) Create test user pricetest@ai.acme.com (plan_tier=pro,
8# trial_ends_at=NOW()+14d, trial_sku_cap=10)
9# 2) curl /pricing.cgi and grep for "Pro" / "Business" / "Scale"
10# + the new prices ($49 / $149 / $349)
11# 3) SELECT COUNT(*) from billing_plans WHERE is_active=1; expect 3
12# 4) grep "starter" / "studio" from a set of CGIs + .pm files
13# 5) Delete the test user
14#======================================================================
15use strict;
16use warnings;
17use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
18use MODS::DBConnect;
19use MODS::RePricer::Config;
20
21my $cfg = MODS::RePricer::Config->new;
22my $db = MODS::DBConnect->new;
23my $DB = $cfg->settings('database_name');
24my $dbh = $db->db_connect();
25die "no dbh" unless $dbh;
26
27my $TEST_EMAIL = 'pricetest@ai.acme.com';
28my $PASS = 0; my $FAIL = 0;
29sub ok { my $m = shift; print "PASS: $m\n"; $PASS++; }
30sub bad { my $m = shift; print "FAIL: $m\n"; $FAIL++; }
31
32# --- step 1: create test user ----------------------------------------
33$db->db_readwrite($dbh, "DELETE FROM ${DB}.users WHERE email='$TEST_EMAIL'",
34 $0, __LINE__);
35my $r = $db->db_readwrite($dbh, qq~
36 INSERT INTO ${DB}.users SET
37 email='$TEST_EMAIL',
38 password_hash='\$argon2id\$v=19\$placeholder',
39 display_name='Price Test',
40 plan_tier='pro',
41 trial_ends_at=DATE_ADD(NOW(), INTERVAL 14 DAY),
42 trial_sku_cap=10,
43 marketplaces_enabled='amazon',
44 account_status='active',
45 created_at=NOW()
46~, $0, __LINE__);
47my $uid = $r->{mysql_insertid} || 0;
48if ($uid) { ok("created test user uid=$uid") }
49else { bad("could not create test user") }
50
51# Verify trial fields
52my $u = $db->db_readwrite($dbh, qq~
53 SELECT plan_tier, trial_ends_at, trial_sku_cap, marketplaces_enabled
54 FROM ${DB}.users WHERE id='$uid'
55~, $0, __LINE__);
56if ($u && $u->{plan_tier} eq 'pro') { ok("plan_tier=pro confirmed") }
57else { bad("plan_tier mismatch: " . ($u->{plan_tier} || 'NULL')) }
58if ($u && $u->{trial_sku_cap} && $u->{trial_sku_cap} == 10) { ok("trial_sku_cap=10 confirmed") }
59else { bad("trial_sku_cap mismatch: " . ($u->{trial_sku_cap} || 'NULL')) }
60if ($u && $u->{trial_ends_at}) { ok("trial_ends_at set: $u->{trial_ends_at}") }
61else { bad("trial_ends_at not set") }
62if ($u && $u->{marketplaces_enabled} eq 'amazon') { ok("marketplaces_enabled=amazon") }
63else { bad("marketplaces_enabled mismatch: " . ($u->{marketplaces_enabled} || 'NULL')) }
64
65# --- step 2: curl pricing.cgi ----------------------------------------
66my $html = `curl -sk https://repricer.3dshawn.com/pricing.cgi 2>&1`;
67if ($html =~ /\bPro\b/) { ok("pricing.cgi contains 'Pro'") } else { bad("pricing.cgi missing 'Pro'") }
68if ($html =~ /\bBusiness\b/) { ok("pricing.cgi contains 'Business'") } else { bad("pricing.cgi missing 'Business'") }
69if ($html =~ /\bScale\b/) { ok("pricing.cgi contains 'Scale'") } else { bad("pricing.cgi missing 'Scale'") }
70if ($html =~ /\$49\b/) { ok("pricing.cgi contains \$49") } else { bad("pricing.cgi missing \$49") }
71if ($html =~ /\$149\b/) { ok("pricing.cgi contains \$149") } else { bad("pricing.cgi missing \$149") }
72if ($html =~ /\$349\b/) { ok("pricing.cgi contains \$349") } else { bad("pricing.cgi missing \$349") }
73if ($html =~ /14-day free trial/i) { ok("pricing.cgi has 14-day trial CTA") } else { bad("pricing.cgi missing trial CTA") }
74
75# --- step 3: billing_plans rows --------------------------------------
76my $bp = $db->db_readwrite($dbh, "SELECT COUNT(*) AS n FROM ${DB}.billing_plans WHERE is_active=1", $0, __LINE__);
77if ($bp && $bp->{n} == 3) { ok("billing_plans has exactly 3 active rows") }
78else { bad("billing_plans active count=" . ($bp->{n} || 0)) }
79
80my @rows = $db->db_readwrite_multiple($dbh, "SELECT tier FROM ${DB}.billing_plans WHERE is_active=1 ORDER BY sort_order", $0, __LINE__);
81my @tiers = map { $_->{tier} } @rows;
82my %got = map { $_ => 1 } @tiers;
83if ($got{pro} && $got{business} && $got{scale}) { ok("billing_plans tiers: pro+business+scale") }
84else { bad("billing_plans tiers: " . join(',', @tiers)) }
85
86# --- step 4: grep for legacy strings in code -------------------------
87my @files = qw(
88 pricing.cgi billing.cgi index.cgi signup.cgi admin_billing.cgi
89 MODS/RePricer/Billing.pm MODS/RePricer/Config.pm
90);
91my $vhost = '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
92foreach my $f (@files) {
93 my $path = "$vhost/$f";
94 my $starter_hits = `grep -ciE '\\bstarter\\b' $path 2>/dev/null`;
95 chomp $starter_hits;
96 my $studio_hits = `grep -ciE '\\bstudio\\b' $path 2>/dev/null`;
97 chomp $studio_hits;
98 # Allow zero hits. (Backstory comments referencing the old plan
99 # name are OK in /db_schema.sql comments but the spec asks for
100 # zero in these specific files.)
101 if (($starter_hits + 0) == 0) { ok("$f: no 'starter' tokens") }
102 else { bad("$f: $starter_hits 'starter' tokens") }
103 if (($studio_hits + 0) == 0) { ok("$f: no 'studio' tokens") }
104 else { bad("$f: $studio_hits 'studio' tokens") }
105}
106
107# --- step 5: cleanup -------------------------------------------------
108$db->db_readwrite($dbh, "DELETE FROM ${DB}.users WHERE email='$TEST_EMAIL'", $0, __LINE__);
109ok("cleaned up test user");
110
111$db->db_disconnect($dbh);
112print "\n=========================================\n";
113print "TOTAL PASS=$PASS FAIL=$FAIL\n";
114exit ($FAIL ? 1 : 0);
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help