|
10 | 10 | use App\Application\Import\ImportActivities\Pipeline\ActivityImportPipeline; |
11 | 11 | use App\Application\Import\ImportActivities\SkipActivitiesRecordedBefore; |
12 | 12 | use App\Domain\Activity\ActivityId; |
| 13 | +use App\Domain\Activity\ActivityIds; |
13 | 14 | use App\Domain\Activity\ActivityRepository; |
14 | 15 | use App\Domain\Activity\ActivityVisibility; |
15 | 16 | use App\Domain\Activity\ActivityWithRawData; |
@@ -58,7 +59,17 @@ class ImportActivitiesCommandHandlerTest extends ContainerTestCase |
58 | 59 | private ImportActivitiesCommandHandler $importActivitiesCommandHandler; |
59 | 60 | private SpyStrava $strava; |
60 | 61 |
|
61 | | - public function testHandleWithTooManyRequests(): void |
| 62 | + public function testHandleWithTooManyRequestsWhileInitializing(): void |
| 63 | + { |
| 64 | + $output = new SpyOutput(); |
| 65 | + $this->strava->setMaxNumberOfCallsBeforeTriggering429(0); |
| 66 | + |
| 67 | + $this->importActivitiesCommandHandler->handle(new ImportActivities($output, null)); |
| 68 | + |
| 69 | + $this->assertMatchesTextSnapshot((string) $output); |
| 70 | + } |
| 71 | + |
| 72 | + public function testHandleWithTooManyRequestsWhileFetchingActivities(): void |
62 | 73 | { |
63 | 74 | $output = new SpyOutput(); |
64 | 75 | $this->strava->setMaxNumberOfCallsBeforeTriggering429(9); |
@@ -93,7 +104,17 @@ public function testHandleWithTooManyRequests(): void |
93 | 104 | )); |
94 | 105 | } |
95 | 106 |
|
96 | | - public function testHandleWithUnexpectedError(): void |
| 107 | + public function testHandleWithUnexpectedErrorWhileInitializing(): void |
| 108 | + { |
| 109 | + $output = new SpyOutput(); |
| 110 | + $this->strava->setMaxNumberOfCallsBeforeTriggering429(1000); |
| 111 | + $this->strava->triggerExceptionOnNextCall(); |
| 112 | + |
| 113 | + $this->importActivitiesCommandHandler->handle(new ImportActivities($output, null)); |
| 114 | + $this->assertMatchesTextSnapshot((string) $output); |
| 115 | + } |
| 116 | + |
| 117 | + public function testHandleWithUnexpectedErrorWhileFetchingActivities(): void |
97 | 118 | { |
98 | 119 | $output = new SpyOutput(); |
99 | 120 | $this->strava->setMaxNumberOfCallsBeforeTriggering429(1000); |
@@ -413,6 +434,58 @@ public function testHandleWithSportTypeIsNotIncluded(): void |
413 | 434 | $this->assertMatchesTextSnapshot($output); |
414 | 435 | } |
415 | 436 |
|
| 437 | + public function testHandlePartialImport(): void |
| 438 | + { |
| 439 | + $output = new SpyOutput(); |
| 440 | + $this->strava->setMaxNumberOfCallsBeforeTriggering429(1000); |
| 441 | + |
| 442 | + $this->getContainer()->get(ActivityWithRawDataRepository::class)->add(ActivityWithRawData::fromState( |
| 443 | + ActivityBuilder::fromDefaults() |
| 444 | + ->withActivityId(ActivityId::fromUnprefixed(4)) |
| 445 | + ->build(), |
| 446 | + [] |
| 447 | + )); |
| 448 | + |
| 449 | + $this->getContainer()->get(ActivityWithRawDataRepository::class)->add(ActivityWithRawData::fromState( |
| 450 | + ActivityBuilder::fromDefaults() |
| 451 | + ->withActivityId(ActivityId::fromUnprefixed(1000)) |
| 452 | + ->withStartingCoordinate(Coordinate::createFromLatAndLng( |
| 453 | + Latitude::fromString('51.2'), |
| 454 | + Longitude::fromString('3.18') |
| 455 | + )) |
| 456 | + ->withKudoCount(1) |
| 457 | + ->withName('Delete this one') |
| 458 | + ->build(), |
| 459 | + [ |
| 460 | + 'kudos_count' => 1, |
| 461 | + 'name' => 'Delete this one', |
| 462 | + ] |
| 463 | + )); |
| 464 | + |
| 465 | + $segmentEffortOne = SegmentEffortBuilder::fromDefaults() |
| 466 | + ->withActivityId(ActivityId::fromUnprefixed(1000)) |
| 467 | + ->build(); |
| 468 | + $this->getContainer()->get(SegmentEffortRepository::class)->add($segmentEffortOne); |
| 469 | + |
| 470 | + $stream = ActivityStreamBuilder::fromDefaults() |
| 471 | + ->withActivityId(ActivityId::fromUnprefixed(1000)) |
| 472 | + ->build(); |
| 473 | + $this->getContainer()->get(ActivityStreamRepository::class)->add($stream); |
| 474 | + |
| 475 | + $this->getContainer()->get(ActivityWithRawDataRepository::class)->add(ActivityWithRawData::fromState( |
| 476 | + ActivityBuilder::fromDefaults() |
| 477 | + ->withKudoCount(1) |
| 478 | + ->withName('Delete this one as well') |
| 479 | + ->withActivityId(ActivityId::fromUnprefixed(1001)) |
| 480 | + ->build(), |
| 481 | + [] |
| 482 | + )); |
| 483 | + |
| 484 | + $this->importActivitiesCommandHandler->handle(new ImportActivities($output, ActivityIds::fromArray([ActivityId::fromUnprefixed(4)]))); |
| 485 | + |
| 486 | + $this->assertMatchesTextSnapshot($output); |
| 487 | + } |
| 488 | + |
416 | 489 | #[\Override] |
417 | 490 | protected function setUp(): void |
418 | 491 | { |
|
0 commit comments