added on local at 2026-07-01 21:47:40
| 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 | #====================================================================== | |
| 15 | use strict; | |
| 16 | use warnings; | |
| 17 | use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com'; | |
| 18 | use MODS::DBConnect; | |
| 19 | use MODS::RePricer::Config; | |
| 20 | ||
| 21 | my $cfg = MODS::RePricer::Config->new; | |
| 22 | my $db = MODS::DBConnect->new; | |
| 23 | my $DB = $cfg->settings('database_name'); | |
| 24 | my $dbh = $db->db_connect(); | |
| 25 | die "no dbh" unless $dbh; | |
| 26 | ||
| 27 | my $TEST_EMAIL = 'pricetest@ai.acme.com'; | |
| 28 | my $PASS = 0; my $FAIL = 0; | |
| 29 | sub ok { my $m = shift; print "PASS: $m\n"; $PASS++; } | |
| 30 | sub 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__); | |
| 35 | my $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__); | |
| 47 | my $uid = $r->{mysql_insertid} || 0; | |
| 48 | if ($uid) { ok("created test user uid=$uid") } | |
| 49 | else { bad("could not create test user") } | |
| 50 | ||
| 51 | # Verify trial fields | |
| 52 | my $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__); | |
| 56 | if ($u && $u->{plan_tier} eq 'pro') { ok("plan_tier=pro confirmed") } | |
| 57 | else { bad("plan_tier mismatch: " . ($u->{plan_tier} || 'NULL')) } | |
| 58 | if ($u && $u->{trial_sku_cap} && $u->{trial_sku_cap} == 10) { ok("trial_sku_cap=10 confirmed") } | |
| 59 | else { bad("trial_sku_cap mismatch: " . ($u->{trial_sku_cap} || 'NULL')) } | |
| 60 | if ($u && $u->{trial_ends_at}) { ok("trial_ends_at set: $u->{trial_ends_at}") } | |
| 61 | else { bad("trial_ends_at not set") } | |
| 62 | if ($u && $u->{marketplaces_enabled} eq 'amazon') { ok("marketplaces_enabled=amazon") } | |
| 63 | else { bad("marketplaces_enabled mismatch: " . ($u->{marketplaces_enabled} || 'NULL')) } | |
| 64 | ||
| 65 | # --- step 2: curl pricing.cgi ---------------------------------------- | |
| 66 | my $html = `curl -sk https://repricer.3dshawn.com/pricing.cgi 2>&1`; | |
| 67 | if ($html =~ /\bPro\b/) { ok("pricing.cgi contains 'Pro'") } else { bad("pricing.cgi missing 'Pro'") } | |
| 68 | if ($html =~ /\bBusiness\b/) { ok("pricing.cgi contains 'Business'") } else { bad("pricing.cgi missing 'Business'") } | |
| 69 | if ($html =~ /\bScale\b/) { ok("pricing.cgi contains 'Scale'") } else { bad("pricing.cgi missing 'Scale'") } | |
| 70 | if ($html =~ /\$49\b/) { ok("pricing.cgi contains \$49") } else { bad("pricing.cgi missing \$49") } | |
| 71 | if ($html =~ /\$149\b/) { ok("pricing.cgi contains \$149") } else { bad("pricing.cgi missing \$149") } | |
| 72 | if ($html =~ /\$349\b/) { ok("pricing.cgi contains \$349") } else { bad("pricing.cgi missing \$349") } | |
| 73 | if ($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 -------------------------------------- | |
| 76 | my $bp = $db->db_readwrite($dbh, "SELECT COUNT(*) AS n FROM ${DB}.billing_plans WHERE is_active=1", $0, __LINE__); | |
| 77 | if ($bp && $bp->{n} == 3) { ok("billing_plans has exactly 3 active rows") } | |
| 78 | else { bad("billing_plans active count=" . ($bp->{n} || 0)) } | |
| 79 | ||
| 80 | my @rows = $db->db_readwrite_multiple($dbh, "SELECT tier FROM ${DB}.billing_plans WHERE is_active=1 ORDER BY sort_order", $0, __LINE__); | |
| 81 | my @tiers = map { $_->{tier} } @rows; | |
| 82 | my %got = map { $_ => 1 } @tiers; | |
| 83 | if ($got{pro} && $got{business} && $got{scale}) { ok("billing_plans tiers: pro+business+scale") } | |
| 84 | else { bad("billing_plans tiers: " . join(',', @tiers)) } | |
| 85 | ||
| 86 | # --- step 4: grep for legacy strings in code ------------------------- | |
| 87 | my @files = qw( | |
| 88 | pricing.cgi billing.cgi index.cgi signup.cgi admin_billing.cgi | |
| 89 | MODS/RePricer/Billing.pm MODS/RePricer/Config.pm | |
| 90 | ); | |
| 91 | my $vhost = '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com'; | |
| 92 | foreach 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__); | |
| 109 | ok("cleaned up test user"); | |
| 110 | ||
| 111 | $db->db_disconnect($dbh); | |
| 112 | print "\n=========================================\n"; | |
| 113 | print "TOTAL PASS=$PASS FAIL=$FAIL\n"; | |
| 114 | exit ($FAIL ? 1 : 0); |