Skip to content

Commit

Permalink
progress on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Train committed Nov 6, 2019
1 parent 19168d8 commit f6ee567
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function contacts()
*
* @return Note
*/
public function listNotes()
public function notes()
{
$line = new Note($this->_client);
$line->setEndpointBase($this->getEndpoint());
Expand Down
76 changes: 75 additions & 1 deletion tests/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public static function setUpBeforeClass()
new Response(200, [], '{"id":"123","unit_cost":500}'),
new Response(200, ['X-Total-Count' => 10, 'Link' => '<https://api.invoiced.com/customers/123/line_items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/customers/123/line_items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/customers/123/line_items?per_page=25&page=1>; rel="last"'], '[{"id":123,"unit_cost":500}]'),
new Response(201, [], '{"id":456,"total":500}'),
new Response(201, [], '[{"id":5678,"message":"test"}]'),
new Response(201, [], '[{"id":6789,"state":"queued"}]'),
new Response(201, [], '{"id":1212,"notes":"test"}'),
new Response(200, [], '{"id":"1212","notes":"test"}'),
new Response(200, ['X-Total-Count' => 15, 'Link' => '<https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="last"'], '[{"id":1212,"notes":"test"}]'),
new Response(201, [], '{"id":123456,"total":1000}'),
]);

self::$invoiced = new Client('API_KEY', false, false, $mock);
Expand Down Expand Up @@ -210,4 +216,72 @@ public function testInvoice()
$this->assertEquals(456, $invoice->id);
$this->assertEquals(500, $invoice->total);
}
}

public function testSendStatementSMS()
{
$customer = new Customer(self::$invoiced, 123);
$textMessages = $customer->sendStatementSMS();

$this->assertTrue(is_array($textMessages));
$this->assertCount(1, $textMessages);
$this->assertInstanceOf('Invoiced\\TextMessage', $textMessages[0]);
$this->assertEquals(5678, $textMessages[0]->id);
}

public function testSendStatementLetter()
{
$customer = new Customer(self::$invoiced, 123);
$letters = $customer->sendStatementLetter();

$this->assertTrue(is_array($letters));
$this->assertCount(1, $letters);
$this->assertInstanceOf('Invoiced\\Letter', $letters[0]);
$this->assertEquals(6789, $letters[0]->id);
}

public function testCreateNote()
{
$customer = new Customer(self::$invoiced, 456);
$note = $customer->notes()->create(['notes' => 'test']);

$this->assertInstanceOf('Invoiced\\Note', $note);
$this->assertEquals(1212, $note->id);
$this->assertEquals('test', $note->notes);
$this->assertEquals('/customers/456/notes/1212', $note->getEndpoint());
}

public function testRetrieveNote()
{
$customer = new Customer(self::$invoiced, 456);
$note = $customer->notes()->retrieve(1212);

$this->assertInstanceOf('Invoiced\\Note', $note);
$this->assertEquals(1212, $note->id);
$this->assertEquals('test', $note->notes);
$this->assertEquals('/customers/456/notes/1212', $note->getEndpoint());
}

public function testAllNotes()
{
$customer = new Customer(self::$invoiced, 456);
list($notes, $metadata) = $customer->notes()->all();

$this->assertTrue(is_array($notes));
$this->assertCount(1, $notes);
$this->assertEquals(1212, $notes[0]->id);
$this->assertEquals('/customers/456/notes/1212', $notes[0]->getEndpoint());

$this->assertInstanceOf('Invoiced\\Collection', $metadata);
$this->assertEquals(15, $metadata->total_count);
}

public function testConsolidateInvoices()
{
$customer = new Customer(self::$invoiced, 123);
$invoice = $customer->consolidateInvoices();

$this->assertInstanceOf('Invoiced\\Invoice', $invoice);
$this->assertEquals(123456, $invoice->id);
$this->assertEquals(1000, $invoice->total);
}
}
76 changes: 75 additions & 1 deletion tests/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public static function setUpBeforeClass()
new Response(200, ['X-Total-Count' => 10, 'Link' => '<https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="last"'], '[{"file":{"id":456}}]'),
new Response(201, [], '{"id":123,"status":"active"}'),
new Response(200, [], '{"id":"123","status":"active"}'),
new Response(201, [], '[{"id":5678,"message":"test"}]'),
new Response(201, [], '[{"id":6789,"state":"queued"}]'),
new Response(201, [], '{"id":1212,"notes":"test"}'),
new Response(200, [], '{"id":"1212","notes":"test"}'),
new Response(200, ['X-Total-Count' => 15, 'Link' => '<https://api.invoiced.com/invoices/456/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/456/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/456/notes?per_page=25&page=1>; rel="last"'], '[{"id":1212,"notes":"test"}]'),
new Response(200, [], '{"id":"1234","status":"voided"}'),
]);

self::$invoiced = new Client('API_KEY', false, false, $mock);
Expand Down Expand Up @@ -150,4 +156,72 @@ public function testRetrievePaymentPlan()
$this->assertEquals('active', $paymentPlan->status);
$this->assertEquals('/invoices/456/payment_plan', $paymentPlan->getEndpoint());
}
}

public function testSendSMS()
{
$invoice = new Invoice(self::$invoiced, 123);
$textMessages = $invoice->sendSMS();

$this->assertTrue(is_array($textMessages));
$this->assertCount(1, $textMessages);
$this->assertInstanceOf('Invoiced\\TextMessage', $textMessages[0]);
$this->assertEquals(5678, $textMessages[0]->id);
}

public function testSendLetter()
{
$invoice = new Invoice(self::$invoiced, 123);
$letters = $invoice->sendLetter();

$this->assertTrue(is_array($letters));
$this->assertCount(1, $letters);
$this->assertInstanceOf('Invoiced\\Letter', $letters[0]);
$this->assertEquals(6789, $letters[0]->id);
}

public function testCreateNote()
{
$invoice = new Invoice(self::$invoiced, 456);
$note = $invoice->notes()->create(['notes' => 'test']);

$this->assertInstanceOf('Invoiced\\Note', $note);
$this->assertEquals(1212, $note->id);
$this->assertEquals('test', $note->notes);
$this->assertEquals('/invoices/456/notes/1212', $note->getEndpoint());
}

public function testRetrieveNote()
{
$invoice = new Invoice(self::$invoiced, 456);
$note = $invoice->notes()->retrieve(1212);

$this->assertInstanceOf('Invoiced\\Note', $note);
$this->assertEquals(1212, $note->id);
$this->assertEquals('test', $note->notes);
$this->assertEquals('/invoices/456/notes/1212', $note->getEndpoint());
}

public function testAllNotes()
{
$invoice = new Invoice(self::$invoiced, 456);
list($notes, $metadata) = $invoice->notes()->all();

$this->assertTrue(is_array($notes));
$this->assertCount(1, $notes);
$this->assertEquals(1212, $notes[0]->id);
$this->assertEquals('/invoices/456/notes/1212', $notes[0]->getEndpoint());

$this->assertInstanceOf('Invoiced\\Collection', $metadata);
$this->assertEquals(15, $metadata->total_count);
}

public function testVoid()
{
$invoice = new Invoice(self::$invoiced, 1234);
$invoice->void();

$this->assertInstanceOf('Invoiced\\Invoice', $invoice);
$this->assertEquals(1234, $invoice->id);
$this->assertEquals('voided', $invoice->status);
}
}
12 changes: 11 additions & 1 deletion tests/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static function setUpBeforeClass()
new Response(401),
new Response(200, ['X-Total-Count' => 15, 'Link' => '<https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="self", <https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="first", <https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="last"'], '[{"id":123,"plan":"pro"}]'),
new Response(200, [], '{"id":123,"plan":"pro","status":"canceled"}'),
new Response(200, [], '{"first_invoice":{"id":false},"mrr":9}')
]);

self::$invoiced = new Client('API_KEY', false, false, $mock);
Expand Down Expand Up @@ -89,4 +90,13 @@ public function testCancel()
$this->assertTrue($subscription->cancel());
$this->assertEquals('canceled', $subscription->status);
}
}

public function testPreview()
{
$subscription = new Subscription(self::$invoiced, 123);
$subscription = $subscription->preview();

$this->assertInstanceOf('Invoiced\\Subscription', $subscription);
$this->assertEquals($subscription->mrr, 9);
}
}

0 comments on commit f6ee567

Please sign in to comment.