Skip to content

Commit

Permalink
fix: parsing map details when none present
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Feb 28, 2024
1 parent 85bcc3c commit de1431b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/Parsers/Files/GPXParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,25 @@ public function parseMapDetailsFromFile(string $filepath): array
$mapDetails = $array['metadata'];
}

$mapTitle = null;
$mapDescription = null;

// Depending what is isset, we will return the name and desc of the map
if (isset($mapDetails['name'])) {
$mapTitle = $mapDetails['name'];
} elseif (isset($array['name'])) {
$mapTitle = (string) $array['name'];
}

if (isset($mapDetails['desc'])) {
$mapDescription = $mapDetails['desc'];
} elseif (isset($array['desc'])) {
$mapDescription = (string) $array['desc'];
}

return [
'title' => $mapDetails['name'] ?? (string) $array['name'] ?? null,
'description' => $mapDetails['desc'] ?? (string) $array['desc'] ?? null,
'title' => $mapTitle,
'description' => $mapDescription,
];
}

Expand Down
39 changes: 39 additions & 0 deletions tests/Unit/MarkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,45 @@ public function testCreateMarkerInBulkWithGpxFile()
$this->assertEquals(59, $map->markers()->orderBy('id', 'desc')->first()->locations()->count());
}

/**
* Test creating markers in bulk by uploading a GPX file
*
* @return void
*/
public function testCreateMarkerInBulkWithSecondGpxFile()
{
$this->withoutExceptionHandling();

// Skip any dispatched jobs
$this->expectsJobs([
FillMissingMarkerElevation::class,
FillMissingLocationGeocodes::class,
]);

// We need to clean up the database before we start
DB::table('markers')->delete();
DB::table('marker_locations')->delete();

$map = new \App\Models\Map();
$map->users_can_create_markers = 'yes';
$map->options = ['links' => 'optional'];
$map->save();

$user = User::factory()->create();

/**
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
$user = $user->givePermissionTo('create markers in bulk');

$this->actingAs($user, 'api');

$file = new UploadedFile(base_path('tests/fixtures/fells_loop.gpx'), 'fells_loop.gpx', 'application/gpx+xml', null, true);

$response = $this->postJson('/api/maps/' . $map->uuid . '/markers/file', ['file' => $file]);
$response->assertStatus(200);
}

public function testCreateMarkerInBulkWithGeoJSONFile()
{
$this->withoutExceptionHandling();
Expand Down

0 comments on commit de1431b

Please sign in to comment.