Add check for geolocation
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Philipp Lang 2023-08-15 15:11:12 +02:00
parent 0e023a06ec
commit 925754bd26
4 changed files with 73 additions and 20 deletions

View File

@ -120,7 +120,7 @@ class Member extends Model implements Geolocatable
// ----------------------------------- Getters -----------------------------------
public function getFullnameAttribute(): string
{
return $this->firstname.' '.$this->lastname;
return $this->firstname . ' ' . $this->lastname;
}
public function getPreferredPhoneAttribute(): ?string
@ -151,12 +151,12 @@ class Member extends Model implements Geolocatable
public function getEtagAttribute(): string
{
return $this->updated_at->timestamp.'_'.$this->version;
return $this->updated_at->timestamp . '_' . $this->version;
}
public function getFullAddressAttribute(): string
{
return $this->address.', '.$this->zip.' '.$this->location;
return $this->address . ', ' . $this->zip . ' ' . $this->location;
}
public function getEfzLink(): ?string
@ -412,7 +412,7 @@ class Member extends Model implements Geolocatable
$settings = app(NamiSettings::class);
$card = Reader::read($data);
[$lastname, $firstname] = $card->N->getParts();
[$deprecated1, $deprecated2 , $address, $location, $region, $zip, $country] = $card->ADR->getParts();
[$deprecated1, $deprecated2, $address, $location, $region, $zip, $country] = $card->ADR->getParts();
return new static([
'joined_at' => now(),
@ -482,8 +482,8 @@ class Member extends Model implements Geolocatable
return Sender::from([
'name' => $this->fullname,
'address' => $this->address,
'zipLocation' => $this->zip.' '.$this->location,
'mglnr' => Lazy::create(fn () => 'Mglnr.: '.$this->nami_id),
'zipLocation' => $this->zip . ' ' . $this->location,
'mglnr' => Lazy::create(fn () => 'Mglnr.: ' . $this->nami_id),
]);
}
@ -525,4 +525,11 @@ class Member extends Model implements Geolocatable
'lon' => null,
]);
}
public function needsGeolocationUpdate(): bool
{
return $this->getOriginal('address') !== $this->address
|| $this->getOriginal('zip') !== $this->zip
|| $this->getOriginal('location') !== $this->location;
}
}

View File

@ -49,7 +49,7 @@
"spatie/laravel-settings": "^2.2",
"worksome/request-factories": "^2.5",
"zoomyboy/laravel-nami": "dev-master",
"zoomyboy/osm": "^1.0",
"zoomyboy/osm": "1.0.3",
"zoomyboy/phone": "^1.0",
"zoomyboy/tex": "dev-main as 1.0"
},

19
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f2cf2548c5e063cf19556d09a5cf2af7",
"content-hash": "62586d4169459f71189b880d8a86e1ec",
"packages": [
{
"name": "beyondcode/laravel-dump-server",
@ -10642,11 +10642,11 @@
},
{
"name": "zoomyboy/osm",
"version": "1.0.1",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://git.zoomyboy.de/zoomyboy/osm.git",
"reference": "255a7819f54b204c4da10f534a4bbb8b9fb3776c"
"reference": "132d15f36885ba06f0ea2d1715f2e7e148f37df1"
},
"type": "library",
"autoload": {
@ -10662,7 +10662,7 @@
}
],
"description": "OSM Helper",
"time": "2023-05-16T14:19:14+00:00"
"time": "2023-08-15T11:24:07+00:00"
},
{
"name": "zoomyboy/phone",
@ -10700,7 +10700,7 @@
"dist": {
"type": "path",
"url": "./packages/tex",
"reference": "6f162102ef7ceca41822d18c3e694abd926f550b"
"reference": "48251272de62e3fea044a7ad31e1a411c15eb4c6"
},
"type": "library",
"extra": {
@ -13463,14 +13463,7 @@
"time": "2023-05-30T22:51:52+00:00"
}
],
"aliases": [
{
"package": "zoomyboy/tex",
"version": "dev-main",
"alias": "1.0",
"alias_normalized": "1.0.0.0"
}
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"zoomyboy/laravel-nami": 20,

View File

@ -0,0 +1,53 @@
<?php
namespace Tests\Feature\Member;
use App\Member\Member;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Zoomyboy\Osm\FillCoordsJob;
class GeolocationTest extends TestCase
{
public function testItFiresGeolocationJob(): void
{
Queue::fake();
Member::enableGeolocation();
$member = Member::factory()->defaults()->create();
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->is($member));
}
public function testItDoesntFireJobWhenUpdateNotNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['nickname' => 'test']);
Queue::assertNotPushed(FillCoordsJob::class);
}
public function testItFiresJobWhenAddressUpdateNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['address' => 'abcdef']);
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->address === 'abcdef');
}
public function testItFiresJobWhenZipUpdateNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['zip' => '33445']);
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->zip === '33445');
}
}