Skip to content

Commit

Permalink
feat: add expenses.
Browse files Browse the repository at this point in the history
  • Loading branch information
loduis committed Jan 11, 2025
1 parent ba671cb commit f28cbec
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Expense.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types = 1);

namespace TeamWorkPm;

use TeamWorkPm\Rest\Resource\Model;
use TeamWorkPm\Rest\Resource\Project\GetByTrait;

class Expense extends Model
{
use GetByTrait;

protected ?string $parent = 'expense';

protected ?string $action = 'expenses';

protected string|array $fields = 'expenses';
}
22 changes: 22 additions & 0 deletions src/Rest/Resource/schemas/expenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": {
"type": "string",
"required": true
},
"project_id": {
"type": "string",
"transform": "dash",
"required": true
},
"description": {
"type": "string"
},
"date": {
"type": "string",
"required": true
},
"cost": {
"type": "float",
"required": true
}
}
71 changes: 71 additions & 0 deletions tests/ExpenseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace TeamWorkPm\Tests;

final class ExpenseTest extends TestCase
{
/**
* @dataProvider provider
*/
public function testCreate(array $data): void
{
$this->assertEquals(TPM_TEST_ID, $this->factory('expense', [
'POST /expenses' => fn($data) => $this->assertMatchesJsonSnapshot($data)
])->create($data));
}

public function testAll(): void
{
$this->assertGreaterThan(0, count($this->factory('expense', [
'GET /expenses' => true
])->all()));
}

public function testGetByProject(): void
{
$this->assertGreaterThan(0, count($this->factory('expense', [
'GET /projects/' . TPM_PROJECT_ID_1 . '/expenses' => true
])->getByProject(TPM_PROJECT_ID_1)));
}

public function testGet(): void
{
$this->assertEquals('test', $this->factory('expense', [
'GET /expenses/' . TPM_EXPENSE_ID => true
])->get(TPM_EXPENSE_ID)->name);
}

/**
* @dataProvider provider
*/
public function testUpdate(array $data): void
{
$data['id'] = TPM_EXPENSE_ID;
$data['name'] = 'Updated Expense Name';
$this->assertTrue($this->factory('expense', [
'PUT /expenses/' . TPM_EXPENSE_ID => true
])->update($data));
}

public function testDelete(): void
{
$this->assertTrue($this->factory('expense', [
'DELETE /expenses/' . TPM_EXPENSE_ID => true
])->delete(TPM_EXPENSE_ID));
}

public function provider()
{
return [
[
[
'name' => 'Test expense',
'description' => 'Bla, Bla, Bla',
'cost' => 100,
'project_id' => TPM_PROJECT_ID_1,
'date' => '20250101'
],
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"expense": {
"name": "Test expense",
"project-id": "967489",
"description": "Bla, Bla, Bla",
"date": "20250101",
"cost": 100
}
}
4 changes: 3 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@

const TPM_PORTFOLIO_COLUMN_ID_2 = 121236;

const TPM_PORTFOLIO_CARD_ID = 121235;
const TPM_PORTFOLIO_CARD_ID = 121235;

const TPM_EXPENSE_ID = 2757;
21 changes: 21 additions & 0 deletions tests/fixtures/expenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"expenses": [
{
"project-name": "Colombia",
"company-name": "Php's Company",
"created-by-user-id": "391604",
"invoice-id": "",
"company-id": "1370007",
"updated-date": "2025-01-11T14:28:44Z",
"name": "test",
"date": "20250101",
"project-id": "967489",
"created-by-user-firstname": "Php",
"cost": "100.00",
"description": "",
"id": "2757",
"created-by-user-lastname": "Api"
}
],
"STATUS": "OK"
}
19 changes: 19 additions & 0 deletions tests/fixtures/expenses/2757.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"STATUS": "OK",
"expense": {
"project-name": "Colombia",
"company-name": "Php's Company",
"created-by-user-id": "391604",
"invoice-id": "",
"company-id": "1370007",
"updated-date": "2025-01-11T14:28:44Z",
"name": "test",
"date": "20250101",
"project-id": "967489",
"created-by-user-firstname": "Php",
"cost": "100.00",
"description": "",
"id": "2757",
"created-by-user-lastname": "Api"
}
}
21 changes: 21 additions & 0 deletions tests/fixtures/projects/967489/expenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"expenses": [
{
"project-name": "Colombia",
"company-name": "Php's Company",
"created-by-user-id": "391604",
"invoice-id": "",
"company-id": "1370007",
"updated-date": "2025-01-11T14:28:44Z",
"name": "test",
"date": "20250101",
"project-id": "967489",
"created-by-user-firstname": "Php",
"cost": "100.00",
"description": "",
"id": "2757",
"created-by-user-lastname": "Api"
}
],
"STATUS": "OK"
}

0 comments on commit f28cbec

Please sign in to comment.