-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
], | ||
], | ||
]; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/__snapshots__/ExpenseTest__testCreate with data set 0__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |