Fixed: Dont store local memberships in nami
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
51ddefe30b
commit
2c0b9217ec
|
@ -25,25 +25,31 @@ class MembershipStoreAction
|
||||||
{
|
{
|
||||||
$from = now()->startOfDay();
|
$from = now()->startOfDay();
|
||||||
|
|
||||||
|
$subactivity = $subactivity ?: new Subactivity(['nami_id' => null, 'id' => null]);
|
||||||
|
|
||||||
|
if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) {
|
||||||
try {
|
try {
|
||||||
$namiId = $settings->login()->putMembership($member->nami_id, NamiMembership::from([
|
$namiId = $settings->login()->putMembership($member->nami_id, NamiMembership::from([
|
||||||
'startsAt' => $from,
|
'startsAt' => $from,
|
||||||
'groupId' => $member->group->nami_id,
|
'groupId' => $member->group->nami_id,
|
||||||
'activityId' => $activity->nami_id,
|
'activityId' => $activity->nami_id,
|
||||||
'subactivityId' => $subactivity ? $subactivity->nami_id : null,
|
'subactivityId' => $subactivity->nami_id,
|
||||||
]));
|
]));
|
||||||
} catch (HttpException $e) {
|
} catch (HttpException $e) {
|
||||||
throw ValidationException::withMessages(['nami' => htmlspecialchars($e->getMessage())]);
|
throw ValidationException::withMessages(['nami' => htmlspecialchars($e->getMessage())]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$membership = $member->memberships()->create([
|
$membership = $member->memberships()->create([
|
||||||
'activity_id' => $activity->id,
|
'activity_id' => $activity->id,
|
||||||
'subactivity_id' => $subactivity ? $subactivity->id : null,
|
'subactivity_id' => $subactivity->id,
|
||||||
'promised_at' => $promisedAt,
|
'promised_at' => $promisedAt,
|
||||||
...['nami_id' => $namiId, 'group_id' => $member->group->id, 'from' => $from],
|
...['nami_id' => $namiId ?? null, 'group_id' => $member->group->id, 'from' => $from],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) {
|
||||||
$member->syncVersion();
|
$member->syncVersion();
|
||||||
|
}
|
||||||
|
|
||||||
return $membership;
|
return $membership;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
public function testActivityIsRequired(): void
|
||||||
{
|
{
|
||||||
$member = Member::factory()
|
$member = Member::factory()
|
||||||
|
|
Loading…
Reference in New Issue