public function testGet() { $client = \Mockery::mock(GuzzleClient::class); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/contacts/1/notes.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery())->andReturn($this->getResponse(200, ' [ { "note": { "created_at": "2011-08-19T15:54:16Z", "updated_at": "2011-08-19T15:54:16Z", "contact_id": 579, "username": "******", "id": 89, "content": "Some note", "deal_id": 0 } } ] ')); $baseCrm = new BaseCrm('', $client); /** @var Contact $contact */ $contact = $baseCrm->getContacts()->get(1); $notes = $contact->getNotes(); $this->assertCount(1, $notes); $note = $notes[0]; $this->assertInstanceOf(Note::class, $note); $this->assertEquals('2011-08-19T15:54:16Z', $note->created_at); $this->assertEquals('2011-08-19T15:54:16Z', $note->updated_at); $this->assertEquals(579, $note->contact_id); $this->assertEquals('User 1', $note->username); $this->assertEquals(89, $note->id); $this->assertEquals("Some note", $note->content); $this->assertEquals(0, $note->deal_id); }
public function testChangingToken() { $accountResponse = ' { "account": { "id": 123, "name": "myaccount", "timezone": "UTC", "currency_name": "US Dollar" } } '; $client = \Mockery::mock(GuzzleClient::class); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => '', Transport::TOKEN_FUTUERSIMPLE_NAME => '']])->andReturn($this->getResponse(200, $accountResponse)); $baseCrm = new BaseCrm('', $client); $baseCrm->getAccount()->get(); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => 'astalavista', Transport::TOKEN_FUTUERSIMPLE_NAME => 'astalavista']])->andReturn($this->getResponse(200, $accountResponse)); $baseCrm->setToken('astalavista'); $this->assertEquals('astalavista', $baseCrm->getToken()); $account = $baseCrm->getAccount()->get(); $client->shouldReceive('request')->once()->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => 'baby', Transport::TOKEN_FUTUERSIMPLE_NAME => 'baby'], 'query' => ['account' => ['name' => 'new_name']]])->andReturn($this->getResponse(200, $accountResponse)); $account->name = 'new_name'; $account->getTransport()->setToken('baby'); $this->assertEquals('baby', $account->getTransport()->getToken()); $account->save(['name']); }
public function testSubResources() { $expectedSubResources = ['account' => Account::class, 'deals' => Deals::class, 'contacts' => Contacts::class, 'sources' => Sources::class, 'leads' => Leads::class, 'tags' => Tags::class]; $baseCrm = new BaseCrm('', \Mockery::mock(GuzzleClient::class)); $subResources = $baseCrm->getSubResources(); $this->assertEquals(array_keys($expectedSubResources), array_keys($subResources)); foreach ($expectedSubResources as $resouceName => $resourceClass) { $this->assertInstanceOf($resourceClass, $subResources[$resouceName]); } }
public function testCurrencyAlteration() { $client = \Mockery::mock(GuzzleClient::class); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery())->andReturn($this->getResponse(200, ' { "account": { "id": 123, "name": "myaccount", "timezone": "UTC", "currency_name": "US Dollar" } } ')); $baseCrm = new BaseCrm('', $client); $account = $baseCrm->getAccount(); $this->assertEquals(123, $account->id); $this->assertEquals('myaccount', $account->name); $this->assertEquals('UTC', $account->timezone); $this->assertEquals(Currency::USD(), $account->currency); $client->shouldReceive('request')->once()->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery(['query' => ['account' => ['name' => 'newname', 'currency_id' => Currency::PLN, 'timezone' => 'new_timezone']]]))->andReturn($this->getResponse(200, ' { "account": { "id": 123, "name": "newname", "timezone": "new_timezone", "currency_name": "Polish złoty" } } ')); $account->name = 'newname'; $account->timezone = 'new_timezone'; $account->currency = Currency::PLN(); $account->save(); $this->assertEquals(123, $account->id); $this->assertEquals('newname', $account->name); $this->assertEquals('new_timezone', $account->timezone); $this->assertEquals(Currency::PLN(), $account->currency); }
public function testTaggings() { $client = \Mockery::mock(GuzzleClient::class); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/leads/1.json', Resource::ENDPOINT_LEADS, Resource::PREFIX), $this->getQuery())->andReturn($this->getResponse(200, ' { "success": true, "lead": { "id": 1, "user_id": 2, "account_id": 3, "owner_id": 2, "first_name": "Lead", "last_name": "One", "company_name": null, "created_at": "2013-04-10T15:04:24+00:00", "state": null, "display_name": "Lead One", "conversion_name": "Lead One", "added_on": "2013-04-10T15:04:24+00:00" }, "metadata": { } } ')); $baseCrm = new BaseCrm('', $client); /** @var Lead $lead */ $lead = $baseCrm->getLeads()->get(1); $this->assertInstanceOf(Lead::class, $lead); $this->assertEquals(1, $lead->id); $client->shouldReceive('request')->once()->with('POST', sprintf('%s/%s/taggings.json', Resource::ENDPOINT_TAGS, Resource::PREFIX), $this->getQuery(['query' => ['app_id' => 5, 'taggable_type' => 'Lead', 'taggable_id' => 1, 'tag_list' => 'tag1,tag2']]))->andReturn($this->getResponse(200, ' [ { "tag": { "id": 1, "name": "tag1", "permissions_holder_id": 20 } }, { "tag": { "id": 2, "name": "tag2", "permissions_holder_id": 20 } } ] ')); $tags = $lead->saveTags(['tag1', 'tag2']); $this->assertInstanceOf(ResourceCollection::class, $tags); $this->assertCount(2, $tags); }
public function testSavingCustomFields() { $client = \Mockery::mock(GuzzleClient::class); $baseCrm = new BaseCrm('', $client); /** @var Source $source */ $source = $baseCrm->getSources()->get(123); $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/sources/123.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery())->andReturn($this->getResponse(200, ' { "source": { "name": "test", "id": 123, "custom_fields": { "custom1": { "id": null }, "custom2": { "id": 12345, "value": "some value" } } } } ')); $source->setCustomField('custom1', 'new_value1'); $source->setCustomField('custom2', 'new_value2'); $client->shouldReceive('request')->once()->with('PUT', sprintf('%s/%s/sources/123.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery(['query' => ['source' => ['name' => 'test', 'custom_field_values' => ['custom1' => 'new_value1', 'custom2' => 'new_value2']]]]))->andReturn($this->getResponse(200, ' { "source": { "name": "test", "id": 123, "custom_fields": { "custom1": { "id": 123, "value": "new_value1" }, "custom2": { "id": 456, "value": "new_value2" } } } } ')); $source->save(); }