Make bonus rules visible: highlighted BONUS line on the alerts overlay, streamgoals_bonus action
Test and Release / test (push) Successful in 1m14s
Test and Release / release (push) Successful in 4s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 12:07:06 -08:00
1 parent 1e2ca96eed
commit c7f2dcffeb
9 files changed
+187 -3

No files matched your search

+37
View File
@@ -96,6 +96,41 @@ final class OverlayPayloadsTest extends TestCase {
$this->assertSame( Payloads::etag( $g ), Payloads::etag( $g ) );
}
public function test_alert_bonuses_humanized_and_empty_when_none(): void {
$out = Payloads::alerts( array( $this->don( 1, array( 'bonuses' => array( 'big_donation', 'mega-win' ) ) ), $this->don( 2 ) ), 0 );
$this->assertSame( array( 'Big donation', 'Mega win' ), $out['alerts'][0]['bonuses'] );
$this->assertSame( array(), $out['alerts'][1]['bonuses'] );
}
public function test_alert_bonuses_sanitize_hostile_event(): void {
$out = Payloads::alerts( array( $this->don( 1, array( 'bonuses' => array( '<img src=x onerror=alert(1)>', '"><script>', '<>', 42, 'big_donation', 'BIG_DONATION' ) ) ) ), 0 );
$b = $out['alerts'][0]['bonuses'];
$this->assertSame( 'Imgsrcxonerroralert1', $b[0] );
foreach ( $b as $label ) {
$this->assertMatchesRegularExpression( '/^[A-Za-z0-9 ]+$/', $label );
}
$this->assertSame( 1, count( array_keys( $b, 'Big donation', true ) ) ); // deduped
}
public function test_bonuses_do_not_affect_masking_moderation_or_since(): void {
$rows = array(
$this->don( 1, array( 'bonuses' => array( 'big_donation' ) ) ),
$this->don( 2, array( 'is_anonymous' => 1, 'donor_name' => 'Secret Sam', 'bonuses' => array( 'big_donation' ) ) ),
$this->don( 3, array( 'moderation' => 'pending', 'bonuses' => array( 'big_donation' ) ) ),
);
$out = Payloads::alerts( $rows, 1 );
$this->assertSame( array( 2 ), array_column( $out['alerts'], 'id' ) );
$this->assertSame( 'Anonymous', $out['alerts'][0]['name'] );
$this->assertStringNotContainsString( 'Secret Sam', json_encode( $out ) );
$this->assertSame( array(), Payloads::alerts( $rows, null )['alerts'] );
}
public function test_etag_changes_when_bonus_added(): void {
$plain = Payloads::alerts( array( $this->don( 5 ) ), 0 );
$bonus = Payloads::alerts( array( $this->don( 5, array( 'bonuses' => array( 'big_donation' ) ) ) ), 0 );
$this->assertNotSame( Payloads::etag( $plain ), Payloads::etag( $bonus ) );
}
public function test_style_sanitizes(): void {
$s = Style::fromQuery( array( 'theme' => 'bogus', 'accent' => '#FF00AA', 'color' => 'red;}</style>', 'bg' => '11223344',
'font' => 'x;}body{', 'scale' => '99' ) );
@@ -114,6 +149,7 @@ final class OverlayPayloadsTest extends TestCase {
public function raisedMinor( array $goal ): int { return 250; }
public function stateValue( int $goalId, string $key ): ?string { return 'timer_ends_at' === $key ? '2000' : null; }
public function counter( int $goalId ): array { return array( 'label' => 'Pies', 'value' => 4 ); }
public function bonusesFor( array $donationIds ): array { return array( 3 => array( 'big_donation' ) ); }
public function donations( ?int $sinceId, int $limit ): array { return array( array( 'id' => 3, 'base_minor' => 100, 'currency' => 'USD', 'donor_name' => 'Z', 'is_anonymous' => 1, 'message' => '', 'status' => 'completed', 'moderation' => 'approved' ) ); }
};
$svc = new OverlayService( $src );
@@ -121,6 +157,7 @@ final class OverlayPayloadsTest extends TestCase {
$this->assertSame( 2000, $svc->payload( 'timer', 1500 )['ends_at'] );
$this->assertSame( 4, $svc->payload( 'counter', 1 )['value'] );
$this->assertSame( 'Anonymous', $svc->payload( 'alerts', 1, 0 )['alerts'][0]['name'] );
$this->assertSame( array( 'Big donation' ), $svc->payload( 'alerts', 1, 0 )['alerts'][0]['bonuses'] );
$this->assertNull( $svc->payload( 'nope', 1 ) );
}
}