Fix subscriber api. Closes #2112
This commit is contained in:
@@ -44,17 +44,17 @@ class SubscribeSubscriberCommandHandler
|
||||
|
||||
// Decide what to subscribe the subscriber to.
|
||||
if ($subscriptions = $command->subscriptions) {
|
||||
$subscriptions = Component::whereIn('id', $subscriptions);
|
||||
$components = Component::whereIn('id', $subscriptions)->get();
|
||||
} else {
|
||||
$subscriptions = Component::all();
|
||||
$components = Component::all();
|
||||
}
|
||||
|
||||
foreach ($subscriptions as $component) {
|
||||
$components->map(function ($component) use ($subscriber) {
|
||||
Subscription::create([
|
||||
'subscriber_id' => $subscriber->id,
|
||||
'component_id' => $component->id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
if ($command->verified) {
|
||||
dispatch(new VerifySubscriberCommand($subscriber));
|
||||
@@ -62,6 +62,8 @@ class SubscribeSubscriberCommandHandler
|
||||
event(new SubscriberHasSubscribedEvent($subscriber));
|
||||
}
|
||||
|
||||
$subscriber->load('subscriptions');
|
||||
|
||||
return $subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ class SubscriberTest extends AbstractApiTestCase
|
||||
$this->assertResponseOk();
|
||||
$this->seeHeader('Content-Type', 'application/json');
|
||||
$this->seeJson(['email' => 'support@alt-three.com']);
|
||||
$this->seeJsonStructure(['data' => ['subscriptions' => []]]);
|
||||
}
|
||||
|
||||
public function testDeleteSubscriber()
|
||||
|
||||
Reference in New Issue
Block a user