Fake initialize members
This commit is contained in:
parent
23e0a27f9a
commit
a50a43b9ab
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use App\Nami\HasNamiField;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Country extends Model
|
class Country extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use HasNamiField;
|
||||||
|
|
||||||
public $fillable = ['name', 'nami_id'];
|
public $fillable = ['name', 'nami_id'];
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,13 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use App\Nami\HasNamiField;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Gender extends Model
|
class Gender extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use HasNamiField;
|
||||||
|
|
||||||
public $fillable = ['name', 'nami_id'];
|
public $fillable = ['name', 'nami_id'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,17 @@ class InitializeActivities {
|
||||||
|
|
||||||
public function handle() {
|
public function handle() {
|
||||||
$this->bar->task('Synchronisiere Tätigkeiten', function() {
|
$this->bar->task('Synchronisiere Tätigkeiten', function() {
|
||||||
$this->api->group(auth()->user()->getNamiGroupId())->activities()->each(function($activity) {
|
$this->api->activities(auth()->user()->getNamiGroupId())->each(function($activity) {
|
||||||
$activity = \App\Activity::create([
|
$activity = \App\Activity::create([
|
||||||
'nami_id' => $activity->id,
|
'nami_id' => $activity->id,
|
||||||
'name' => $activity->name,
|
'name' => $activity->name,
|
||||||
'is_try' => in_array($group->name, $this->tries),
|
'is_try' => in_array($activity->name, $this->tries),
|
||||||
'is_member' => in_array($group->name, $this->members),
|
'is_member' => in_array($activity->name, $this->members),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$groups = [];
|
$groups = [];
|
||||||
$this->api->subactivitiesOf($activity->id)->each(function($group) use ($activity, &$groups) {
|
$this->api->subactivitiesOf($activity->nami_id)->each(function($group) use ($activity, &$groups) {
|
||||||
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
||||||
'nami_id' => $group->id,
|
'nami_id' => $group->id,
|
||||||
'name' => $group->name,
|
'name' => $group->name,
|
||||||
|
|
|
@ -14,7 +14,7 @@ class InitializeFees {
|
||||||
|
|
||||||
public function handle() {
|
public function handle() {
|
||||||
$this->bar->task('Synchronisiere Beiträge', function() {
|
$this->bar->task('Synchronisiere Beiträge', function() {
|
||||||
$this->api->group(auth()->user()->getNamiGroupId())->fees()->each(function($fee) {
|
$this->api->feesOf(auth()->user()->getNamiGroupId())->each(function($fee) {
|
||||||
\App\Fee::create(['nami_id' => $fee->id, 'name' => $fee->name])
|
\App\Fee::create(['nami_id' => $fee->id, 'name' => $fee->name])
|
||||||
->subscriptions()->create([
|
->subscriptions()->create([
|
||||||
'name' => $fee->name,
|
'name' => $fee->name,
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
namespace App\Initialize;
|
namespace App\Initialize;
|
||||||
|
|
||||||
use App\Member;
|
use App\Member;
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Aweos\Agnoster\Progress\HasProgress;
|
use Aweos\Agnoster\Progress\HasProgress;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Zoomyboy\LaravelNami\NamiUser;
|
use Zoomyboy\LaravelNami\NamiUser;
|
||||||
|
|
||||||
class InitializeJob implements ShouldQueue
|
class InitializeJob implements ShouldQueue
|
||||||
|
|
|
@ -2,15 +2,16 @@
|
||||||
|
|
||||||
namespace App\Initialize;
|
namespace App\Initialize;
|
||||||
|
|
||||||
use App\Gender;
|
use App\Activity;
|
||||||
use App\Confession;
|
use App\Confession;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Member\Member;
|
|
||||||
use App\Region;
|
|
||||||
use App\Nationality;
|
|
||||||
use App\Fee;
|
use App\Fee;
|
||||||
|
use App\Gender;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
use App\Activity;
|
use App\Member\Member;
|
||||||
|
use App\Nationality;
|
||||||
|
use App\Region;
|
||||||
|
use Zoomyboy\LaravelNami\Member as NamiMember;
|
||||||
|
|
||||||
class InitializeMembers {
|
class InitializeMembers {
|
||||||
|
|
||||||
|
@ -35,7 +36,8 @@ class InitializeMembers {
|
||||||
$allMembers = collect([]);
|
$allMembers = collect([]);
|
||||||
|
|
||||||
$this->bar->task('Synchronisiere Mitglieder', function() {
|
$this->bar->task('Synchronisiere Mitglieder', function() {
|
||||||
$this->api->group(auth()->user()->getNamiGroupId())->members()->each(function($member) {
|
$this->api->search([])->each(function($member) {
|
||||||
|
$member = NamiMember::fromNami($this->api->member($member->group_id, $member->id));
|
||||||
$m = Member::create([
|
$m = Member::create([
|
||||||
'firstname' => $member->firstname,
|
'firstname' => $member->firstname,
|
||||||
'lastname' => $member->lastname,
|
'lastname' => $member->lastname,
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Nami;
|
|
||||||
|
|
||||||
class InitializeService {
|
|
||||||
|
|
||||||
public $api;
|
|
||||||
|
|
||||||
public function __construct(Api $api) {
|
|
||||||
$this->api = $api;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle() {
|
|
||||||
dd(auth()->user()->getNamiService()->fees());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use App\Nami\HasNamiField;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Nationality extends Model
|
class Nationality extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use HasNamiField;
|
||||||
|
|
||||||
public $fillable = ['name','nami_id'];
|
public $fillable = ['name','nami_id'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 07595f681d282e6dc06bd57adbefdf04d6b8c1f5
|
Subproject commit a39c8513c9c1ac65f94e1010a45124054da5d0b0
|
|
@ -7,7 +7,7 @@ parameters:
|
||||||
- app
|
- app
|
||||||
|
|
||||||
# The level 8 is the highest level
|
# The level 8 is the highest level
|
||||||
level: 6
|
level: 8
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- '#Unsafe usage of new static#'
|
- '#Unsafe usage of new static#'
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Initialize;
|
||||||
|
|
||||||
|
use App\Activity;
|
||||||
|
use App\Country;
|
||||||
|
use App\Gender;
|
||||||
|
use App\Nationality;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||||
|
|
||||||
|
class InitializeTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function testItInitializesGenders(): void
|
||||||
|
{
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
app(FakeBackend::class)
|
||||||
|
->fakeLogin('123', [])
|
||||||
|
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000])
|
||||||
|
->fakeNationalities([['name' => 'deutsch', 'id' => 291]])
|
||||||
|
->fakeFees(1000, [['name' => 'Family', 'id' => 300]])
|
||||||
|
->fakeConfessions([['name' => 'Konf', 'id' => 301]])
|
||||||
|
->fakeCountries([['name' => 'Germany', 'id' => 302]])
|
||||||
|
->fakeGenders([['name' => 'Male', 'id' => 303]])
|
||||||
|
->fakeRegions([['name' => 'nrw', 'id' => 304]])
|
||||||
|
->fakeActivities(1000, [['name' => 'leiter', 'id' => 305]])
|
||||||
|
->fakeMember([
|
||||||
|
'vorname' => '::firstname::',
|
||||||
|
'nachname' => '::lastname::',
|
||||||
|
'beitragsartId' => 300,
|
||||||
|
'geburtsDatum' => '2014-07-11 00:00:00',
|
||||||
|
'gruppierungId' => 1000,
|
||||||
|
'geschlechtId' => 303,
|
||||||
|
'id' => 411,
|
||||||
|
'eintrittsdatum' => '2020-11-17 00:00:00',
|
||||||
|
'geschlechtId' => 303,
|
||||||
|
'landId' => 302,
|
||||||
|
'staatsangehoerigkeitId' => 291,
|
||||||
|
'zeitschriftenversand' => true,
|
||||||
|
'strasse' => '::street',
|
||||||
|
'plz' => '12345',
|
||||||
|
'ort' => '::location::',
|
||||||
|
'version' => 40,
|
||||||
|
])
|
||||||
|
->fakeSubactivities([
|
||||||
|
305 => [['name' => 'wö', 'id' => 306]]
|
||||||
|
]);
|
||||||
|
$this->post('/login', [
|
||||||
|
'mglnr' => 123,
|
||||||
|
'password' => 'secret',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->post('/initialize');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('regions', [
|
||||||
|
'name' => 'nrw',
|
||||||
|
'nami_id' => 304
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('genders', [
|
||||||
|
'name' => 'Male',
|
||||||
|
'nami_id' => 303
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('nationalities', [
|
||||||
|
'name' => 'deutsch',
|
||||||
|
'nami_id' => 291
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('fees', [
|
||||||
|
'name' => 'Family',
|
||||||
|
'nami_id' => 300
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('confessions', [
|
||||||
|
'name' => 'Konf',
|
||||||
|
'nami_id' => 301
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('countries', [
|
||||||
|
'name' => 'Germany',
|
||||||
|
'nami_id' => 302
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('activities', [
|
||||||
|
'name' => 'Leiter',
|
||||||
|
'nami_id' => 305
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('members', [
|
||||||
|
'nami_id' => 411,
|
||||||
|
'gender_id' => Gender::nami(303)->id,
|
||||||
|
'country_id' => Country::nami(302)->id,
|
||||||
|
'nationality_id' => Nationality::nami(291)->id,
|
||||||
|
'send_newspaper' => 1,
|
||||||
|
'address' => '::street',
|
||||||
|
'zip' => '12345',
|
||||||
|
'location' => '::location::',
|
||||||
|
'version' => 40,
|
||||||
|
]);
|
||||||
|
$this->assertEquals([306], Activity::firstWhere('nami_id', 305)->subactivities()->pluck('nami_id')->toArray());
|
||||||
|
|
||||||
|
Http::assertSentCount(13);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,9 @@ class LoginTest extends TestCase
|
||||||
public function testItCanLoginWithANamiAccount()
|
public function testItCanLoginWithANamiAccount()
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
|
app('nami.backend')
|
||||||
|
->fakeLogin(123, [], 'cookie-123')
|
||||||
|
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
|
||||||
|
|
||||||
$this->post('/login', [
|
$this->post('/login', [
|
||||||
'mglnr' => 123,
|
'mglnr' => 123,
|
||||||
|
@ -29,6 +31,9 @@ class LoginTest extends TestCase
|
||||||
$key = session()->get('auth_key');
|
$key = session()->get('auth_key');
|
||||||
$cache = Cache::get("namiauth-{$key}");
|
$cache = Cache::get("namiauth-{$key}");
|
||||||
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
|
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
|
||||||
|
$this->assertEquals('::firstname::', data_get($cache, 'firstname'));
|
||||||
|
$this->assertEquals('::lastname::', data_get($cache, 'lastname'));
|
||||||
|
$this->assertEquals(1000, data_get($cache, 'group_id'));
|
||||||
$this->assertEquals(123, data_get($cache, 'credentials.mglnr'));
|
$this->assertEquals(123, data_get($cache, 'credentials.mglnr'));
|
||||||
$this->assertTrue(auth()->check());
|
$this->assertTrue(auth()->check());
|
||||||
}
|
}
|
||||||
|
@ -36,7 +41,9 @@ class LoginTest extends TestCase
|
||||||
public function testItDoesntLoginTwoTimes()
|
public function testItDoesntLoginTwoTimes()
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
|
app('nami.backend')
|
||||||
|
->fakeLogin(123, [], 'cookie-123')
|
||||||
|
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
|
||||||
|
|
||||||
$this->post('/login', [
|
$this->post('/login', [
|
||||||
'mglnr' => 123,
|
'mglnr' => 123,
|
||||||
|
@ -50,13 +57,15 @@ class LoginTest extends TestCase
|
||||||
|
|
||||||
$this->assertTrue(auth()->check());
|
$this->assertTrue(auth()->check());
|
||||||
|
|
||||||
Http::assertSentCount(2);
|
Http::assertSentCount(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItResolvesTheLoginFromTheCache()
|
public function testItResolvesTheLoginFromTheCache()
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
app('nami.backend')->fakeLogin(123, [], 'cookie-123');
|
app('nami.backend')
|
||||||
|
->fakeLogin(123, [], 'cookie-123')
|
||||||
|
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
|
||||||
|
|
||||||
$this->post('/login', [
|
$this->post('/login', [
|
||||||
'mglnr' => 123,
|
'mglnr' => 123,
|
||||||
|
@ -70,7 +79,7 @@ class LoginTest extends TestCase
|
||||||
|
|
||||||
$this->assertTrue(auth()->check());
|
$this->assertTrue(auth()->check());
|
||||||
|
|
||||||
Http::assertSentCount(2);
|
Http::assertSentCount(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItThrowsExceptionWhenLoginFailed()
|
public function testItThrowsExceptionWhenLoginFailed()
|
||||||
|
|
Loading…
Reference in New Issue