Fixed: Dont store local memberships in nami
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2023-02-17 02:14:32 +01:00
parent 51ddefe30b
commit 2c0b9217ec
2 changed files with 64 additions and 12 deletions

View File

@ -25,25 +25,31 @@ class MembershipStoreAction
{
$from = now()->startOfDay();
try {
$namiId = $settings->login()->putMembership($member->nami_id, NamiMembership::from([
'startsAt' => $from,
'groupId' => $member->group->nami_id,
'activityId' => $activity->nami_id,
'subactivityId' => $subactivity ? $subactivity->nami_id : null,
]));
} catch (HttpException $e) {
throw ValidationException::withMessages(['nami' => htmlspecialchars($e->getMessage())]);
$subactivity = $subactivity ?: new Subactivity(['nami_id' => null, 'id' => null]);
if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) {
try {
$namiId = $settings->login()->putMembership($member->nami_id, NamiMembership::from([
'startsAt' => $from,
'groupId' => $member->group->nami_id,
'activityId' => $activity->nami_id,
'subactivityId' => $subactivity->nami_id,
]));
} catch (HttpException $e) {
throw ValidationException::withMessages(['nami' => htmlspecialchars($e->getMessage())]);
}
}
$membership = $member->memberships()->create([
'activity_id' => $activity->id,
'subactivity_id' => $subactivity ? $subactivity->id : null,
'subactivity_id' => $subactivity->id,
'promised_at' => $promisedAt,
...['nami_id' => $namiId, 'group_id' => $member->group->id, 'from' => $from],
...['nami_id' => $namiId ?? null, 'group_id' => $member->group->id, 'from' => $from],
]);
$member->syncVersion();
if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) {
$member->syncVersion();
}
return $membership;
}

View File

@ -63,6 +63,52 @@ class StoreTest extends TestCase
]);
}
public function testItDoesntFireNamiWhenMembershipIsLocal(): void
{
$this->withoutExceptionHandling();
$member = Member::factory()
->defaults()
->for(Group::factory()->inNami(1400))
->inNami(6)
->create();
$activity = Activity::factory()->hasAttached(Subactivity::factory())->create();
$this->from('/member')->post(
"/member/{$member->id}/membership",
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
);
$this->assertDatabaseHas('memberships', [
'member_id' => $member->id,
'activity_id' => $activity->id,
'subactivity_id' => $activity->subactivities->first()->id,
'nami_id' => null,
]);
}
public function testItDoesntFireNamiWhenSubactivityIsLocal(): void
{
$this->withoutExceptionHandling();
$member = Member::factory()
->defaults()
->for(Group::factory()->inNami(1400))
->inNami(6)
->create();
$activity = Activity::factory()->inNami(666)->hasAttached(Subactivity::factory())->create();
$this->from('/member')->post(
"/member/{$member->id}/membership",
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
);
$this->assertDatabaseHas('memberships', [
'member_id' => $member->id,
'activity_id' => $activity->id,
'subactivity_id' => $activity->subactivities->first()->id,
'nami_id' => null,
]);
}
public function testActivityIsRequired(): void
{
$member = Member::factory()