Skip to content

Commit f28cbec

Browse files
committed
feat: add expenses.
1 parent ba671cb commit f28cbec

File tree

8 files changed

+185
-1
lines changed

8 files changed

+185
-1
lines changed

src/Expense.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace TeamWorkPm;
6+
7+
use TeamWorkPm\Rest\Resource\Model;
8+
use TeamWorkPm\Rest\Resource\Project\GetByTrait;
9+
10+
class Expense extends Model
11+
{
12+
use GetByTrait;
13+
14+
protected ?string $parent = 'expense';
15+
16+
protected ?string $action = 'expenses';
17+
18+
protected string|array $fields = 'expenses';
19+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": {
3+
"type": "string",
4+
"required": true
5+
},
6+
"project_id": {
7+
"type": "string",
8+
"transform": "dash",
9+
"required": true
10+
},
11+
"description": {
12+
"type": "string"
13+
},
14+
"date": {
15+
"type": "string",
16+
"required": true
17+
},
18+
"cost": {
19+
"type": "float",
20+
"required": true
21+
}
22+
}

tests/ExpenseTest.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace TeamWorkPm\Tests;
4+
5+
final class ExpenseTest extends TestCase
6+
{
7+
/**
8+
* @dataProvider provider
9+
*/
10+
public function testCreate(array $data): void
11+
{
12+
$this->assertEquals(TPM_TEST_ID, $this->factory('expense', [
13+
'POST /expenses' => fn($data) => $this->assertMatchesJsonSnapshot($data)
14+
])->create($data));
15+
}
16+
17+
public function testAll(): void
18+
{
19+
$this->assertGreaterThan(0, count($this->factory('expense', [
20+
'GET /expenses' => true
21+
])->all()));
22+
}
23+
24+
public function testGetByProject(): void
25+
{
26+
$this->assertGreaterThan(0, count($this->factory('expense', [
27+
'GET /projects/' . TPM_PROJECT_ID_1 . '/expenses' => true
28+
])->getByProject(TPM_PROJECT_ID_1)));
29+
}
30+
31+
public function testGet(): void
32+
{
33+
$this->assertEquals('test', $this->factory('expense', [
34+
'GET /expenses/' . TPM_EXPENSE_ID => true
35+
])->get(TPM_EXPENSE_ID)->name);
36+
}
37+
38+
/**
39+
* @dataProvider provider
40+
*/
41+
public function testUpdate(array $data): void
42+
{
43+
$data['id'] = TPM_EXPENSE_ID;
44+
$data['name'] = 'Updated Expense Name';
45+
$this->assertTrue($this->factory('expense', [
46+
'PUT /expenses/' . TPM_EXPENSE_ID => true
47+
])->update($data));
48+
}
49+
50+
public function testDelete(): void
51+
{
52+
$this->assertTrue($this->factory('expense', [
53+
'DELETE /expenses/' . TPM_EXPENSE_ID => true
54+
])->delete(TPM_EXPENSE_ID));
55+
}
56+
57+
public function provider()
58+
{
59+
return [
60+
[
61+
[
62+
'name' => 'Test expense',
63+
'description' => 'Bla, Bla, Bla',
64+
'cost' => 100,
65+
'project_id' => TPM_PROJECT_ID_1,
66+
'date' => '20250101'
67+
],
68+
],
69+
];
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expense": {
3+
"name": "Test expense",
4+
"project-id": "967489",
5+
"description": "Bla, Bla, Bla",
6+
"date": "20250101",
7+
"cost": 100
8+
}
9+
}

tests/bootstrap.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@
5656

5757
const TPM_PORTFOLIO_COLUMN_ID_2 = 121236;
5858

59-
const TPM_PORTFOLIO_CARD_ID = 121235;
59+
const TPM_PORTFOLIO_CARD_ID = 121235;
60+
61+
const TPM_EXPENSE_ID = 2757;

tests/fixtures/expenses.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"expenses": [
3+
{
4+
"project-name": "Colombia",
5+
"company-name": "Php's Company",
6+
"created-by-user-id": "391604",
7+
"invoice-id": "",
8+
"company-id": "1370007",
9+
"updated-date": "2025-01-11T14:28:44Z",
10+
"name": "test",
11+
"date": "20250101",
12+
"project-id": "967489",
13+
"created-by-user-firstname": "Php",
14+
"cost": "100.00",
15+
"description": "",
16+
"id": "2757",
17+
"created-by-user-lastname": "Api"
18+
}
19+
],
20+
"STATUS": "OK"
21+
}

tests/fixtures/expenses/2757.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"STATUS": "OK",
3+
"expense": {
4+
"project-name": "Colombia",
5+
"company-name": "Php's Company",
6+
"created-by-user-id": "391604",
7+
"invoice-id": "",
8+
"company-id": "1370007",
9+
"updated-date": "2025-01-11T14:28:44Z",
10+
"name": "test",
11+
"date": "20250101",
12+
"project-id": "967489",
13+
"created-by-user-firstname": "Php",
14+
"cost": "100.00",
15+
"description": "",
16+
"id": "2757",
17+
"created-by-user-lastname": "Api"
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"expenses": [
3+
{
4+
"project-name": "Colombia",
5+
"company-name": "Php's Company",
6+
"created-by-user-id": "391604",
7+
"invoice-id": "",
8+
"company-id": "1370007",
9+
"updated-date": "2025-01-11T14:28:44Z",
10+
"name": "test",
11+
"date": "20250101",
12+
"project-id": "967489",
13+
"created-by-user-firstname": "Php",
14+
"cost": "100.00",
15+
"description": "",
16+
"id": "2757",
17+
"created-by-user-lastname": "Api"
18+
}
19+
],
20+
"STATUS": "OK"
21+
}

0 commit comments

Comments
 (0)