Fix subscriber api. Closes #2112

This commit is contained in:
James Brooks
2016-09-28 20:19:33 +01:00
parent 1bdb2d6a0b
commit 86013db148
2 changed files with 7 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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()