diff --git a/app/Event.php b/app/Event.php index 93adc2562..2c4060212 100644 --- a/app/Event.php +++ b/app/Event.php @@ -259,9 +259,24 @@ public function path() public function imported() { + // Central codeweek.de export (api:germany-central). + if (Str::startsWith((string) $this->source_ref, 'codeweek-de:')) { + return true; + } + + if ((string) $this->mass_added_for === 'API codeweek_de') { + return true; + } + + $code = (string) $this->codeweek_for_all_participation_code; + if ($code !== '' && Str::contains($code, 'codeweek-de')) { + return true; + } + + // Legacy per-city feeds used codes like cw22-bonn / cw-hamburg. $germanCities = ImporterHelper::getGermanCities(); - return Str::contains($this->codeweek_for_all_participation_code, $germanCities); + return $code !== '' && Str::contains($code, $germanCities); } public function picture_path() diff --git a/tests/Feature/API/EventsAPITest.php b/tests/Feature/API/EventsAPITest.php index 4b282ad51..ffea887e7 100644 --- a/tests/Feature/API/EventsAPITest.php +++ b/tests/Feature/API/EventsAPITest.php @@ -250,20 +250,29 @@ public function it_should_return_german_events(): void 'end_date' => Carbon::now()->setYear(2022), ]); + $centralFeedEvent = \App\Event::factory()->create([ + 'title' => 'Central Feed Event', + 'status' => 'APPROVED', + 'country_iso' => 'DE', + 'codeweek_for_all_participation_code' => 'cw-codeweek-de', + 'source_ref' => 'codeweek-de:11461', + 'mass_added_for' => 'API codeweek_de', + 'end_date' => Carbon::now()->setYear(2022), + ]); + $response = $this->json( 'GET', '/api/events/germany?year=2022', ); $data = $response->decodeResponseJson()['data']; + $byTitle = collect($data)->keyBy('title'); - $this->assertCount(2, $data); - - $this->assertEquals('Good Event', $data[0]['title']); - $this->assertEquals('Imported Event', $data[1]['title']); + $this->assertCount(3, $data); - $this->assertFalse($data[0]['imported_from_german_feeds']); - $this->assertTrue($data[1]['imported_from_german_feeds']); + $this->assertFalse($byTitle['Good Event']['imported_from_german_feeds']); + $this->assertTrue($byTitle['Imported Event']['imported_from_german_feeds']); + $this->assertTrue($byTitle['Central Feed Event']['imported_from_german_feeds']); } #[Test]