Skip to content

Commit

Permalink
Add test to recheck new contributor status
Browse files Browse the repository at this point in the history
  • Loading branch information
trymebytes committed Dec 3, 2024
1 parent abdd77d commit 3d743f6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
6 changes: 3 additions & 3 deletions includes/attendee/attendee-repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Wporg\TranslationEvents\Attendee\Attendee_Adder;
use Wporg\TranslationEvents\Event\Event_Repository;
use Wporg\TranslationEvents\Translation_Events;
use DateTimeImmutable;
use DateTimeZone;

Expand Down Expand Up @@ -313,10 +314,9 @@ function ( Attendee $attendee ) {
return;
}

$now = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) );
$now = Translation_Events::now();
$attendee_adder = new Attendee_Adder( $this );
$event = ( new Event_Repository( $now, new Attendee_Repository() ) )->get_event( $event_id );

$event = ( new Event_Repository( $now, $this ) )->get_event( $event_id );
if ( ! $event ) {
return;
}
Expand Down
43 changes: 41 additions & 2 deletions tests/attendee/attendee-repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
use Wporg\TranslationEvents\Attendee\Attendee;
use Wporg\TranslationEvents\Attendee\Attendee_Repository;
use Wporg\TranslationEvents\Tests\Stats_Factory;
use Wporg\TranslationEvents\Tests\Event_Factory;
use Wporg\TranslationEvents\Tests\Translation_Factory;

class Attendee_Repository_Test extends Base_Test {
private Attendee_Repository $repository;
private Stats_Factory $stats_factory;
private Event_Factory $event_factory;
private Translation_Factory $translation_factory;


public function setUp(): void {
parent::setUp();
$this->repository = new Attendee_Repository();
$this->stats_factory = new Stats_Factory();
$this->repository = new Attendee_Repository();
$this->stats_factory = new Stats_Factory();
$this->event_factory = new Event_Factory();
$this->translation_factory = new Translation_Factory( $this->factory );
}

public function test_add_attendee_invalid_event_id() {
Expand Down Expand Up @@ -261,6 +268,38 @@ public function test_get_attendees_not_contributing() {
$this->assertFalse( $attendees[ $user3_id ]->is_host() );
}

public function test_recheck_new_contributor_status() {
$user1_id = 42;
$user2_id = 43;

$event1_id = $this->event_factory->create_inactive_future( $this->now );

// Attendee, new contributor.
$attendee11 = new Attendee( $event1_id, $user1_id, true, true );
$this->repository->insert_attendee( $attendee11 );

// Attendee, existing contributor.
$attendee12 = new Attendee( $event1_id, $user2_id, false, false, array( 'aa' ) );
$this->stats_factory->create( $event1_id, $user2_id, 1, 'create' );
$this->repository->insert_attendee( $attendee12 );

$attendees = $this->repository->get_attendees( $event1_id );
$this->assertCount( 2, $attendees );
$this->assertEquals( $attendee11, $attendees[ $user1_id ] );
$this->assertEquals( $attendee12, $attendees[ $user2_id ] );
$this->assertTrue( $attendees[ $user1_id ]->is_new_contributor() );
$this->assertFalse( $attendees[ $user2_id ]->is_new_contributor() );

for ( $i = 1; $i < 12; $i++ ) {
$this->translation_factory->create( $user1_id );
}
$this->repository->recheck_new_contributor_status( $event1_id );
$attendees = $this->repository->get_attendees( $event1_id );

$this->assertFalse( $attendees[ $user1_id ]->is_new_contributor() );
$this->assertFalse( $attendees[ $user2_id ]->is_new_contributor() );
}

private function all_table_rows(): array {
global $wpdb, $gp_table_prefix;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
Expand Down

0 comments on commit 3d743f6

Please sign in to comment.