/**
  * Execute the job.
  *
  * @param SubscriptionActions $mailChimp
  */
 public function handle(SubscriptionActions $mailChimp)
 {
     if ($this->model->getMailingListOptedOut()) {
         return;
     }
     $mailChimp->subscribe($this->model);
 }
 /** @test
  * @group  */
 public function check()
 {
     $sa = new SubscriptionActions(new Client());
     $mc = $sa->subscribe($this->model);
     $this->assertEquals('d7858eaa2088ffd13a2c5e687ee68437', $mc->id);
     $this->assertEquals('0a12b6a14e', $mc->unique_email_id);
 }
 /**
  * @test
  * @group  */
 public function it_subscribes_to_mailChimp()
 {
     $apiKey = getenv('MAILCHIMP_API');
     $response = m::mock(\Psr\Http\Message\ResponseInterface::class);
     $this->guzzle->shouldReceive('request')->with('PUT', $this->endpoint . "/3.0/lists/{$this->model->getMailingListId()}/members/" . md5(strtolower($email = $this->model->getMailingListEmail())), ['headers' => ['Authorization' => 'OAuth ' . $apiKey], 'json' => array_merge($this->model->getMailingListProfile(), ['status' => 'subscribed', 'email_address' => $email])])->andReturn($response);
     $response->shouldReceive('getBody')->andReturn(json_encode(['id' => 'aaa', 'unique_email_id' => 'bbb']));
     $sa = new SubscriptionActions($this->guzzle);
     $mc = $sa->subscribe($this->model);
     $this->assertEquals('aaa', $mc->id);
     $this->assertEquals('bbb', $mc->unique_email_id);
 }