Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 15 additions & 6 deletions tests/Feature/API/EventsAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading