mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-15 01:03:16 +01:00
Add tests for billable rate restriction in importers and API edge cases
This commit is contained in:
@@ -157,4 +157,26 @@ class ClockifyProjectsImporterTest extends ImporterTestAbstract
|
||||
Task::query()->where('project_id', $project->id)->pluck('name')->all(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new ClockifyProjectsImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('clockify_projects_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$projects = Project::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $projects);
|
||||
foreach ($projects as $project) {
|
||||
$this->assertFalse($project->is_billable);
|
||||
$this->assertNull($project->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,4 +256,26 @@ class ClockifyTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
}
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new ClockifyTimeEntriesImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('clockify_time_entries_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$timeEntries = TimeEntry::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $timeEntries);
|
||||
foreach ($timeEntries as $timeEntry) {
|
||||
$this->assertFalse($timeEntry->billable);
|
||||
$this->assertNull($timeEntry->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,26 @@ class GenericProjectsImporterTest extends ImporterTestAbstract
|
||||
$this->assertSame(3, $report->projectsCreated);
|
||||
$this->assertSame(2, $report->clientsCreated);
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new GenericProjectsImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('generic_projects_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$projects = Project::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(3, $projects);
|
||||
foreach ($projects as $project) {
|
||||
$this->assertFalse($project->is_billable);
|
||||
$this->assertNull($project->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,4 +113,26 @@ class GenericTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
}
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new GenericTimeEntriesImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('generic_time_entries_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$timeEntries = TimeEntry::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $timeEntries);
|
||||
foreach ($timeEntries as $timeEntry) {
|
||||
$this->assertFalse($timeEntry->billable);
|
||||
$this->assertNull($timeEntry->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,26 @@ class HarvestProjectsImporterTest extends ImporterTestAbstract
|
||||
$this->assertSame(null, $project2->estimated_time);
|
||||
$this->assertSame(false, $project2->is_billable);
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new HarvestProjectsImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('harvest_projects_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$projects = Project::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $projects);
|
||||
foreach ($projects as $project) {
|
||||
$this->assertFalse($project->is_billable);
|
||||
$this->assertNull($project->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +128,32 @@ class HarvestTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
}
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new HarvestTimeEntriesImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('harvest_time_entries_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$timeEntries = TimeEntry::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $timeEntries);
|
||||
foreach ($timeEntries as $timeEntry) {
|
||||
$this->assertFalse($timeEntry->billable);
|
||||
$this->assertNull($timeEntry->billable_rate);
|
||||
}
|
||||
$projects = Project::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $projects);
|
||||
foreach ($projects as $project) {
|
||||
$this->assertFalse($project->is_billable);
|
||||
$this->assertNull($project->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Tests\Unit\Service\Import\Importers;
|
||||
use App\Enums\TimeEntryType;
|
||||
use App\Jobs\RecalculateSpentTimeForProject;
|
||||
use App\Jobs\RecalculateSpentTimeForTask;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
@@ -111,6 +112,13 @@ class SolidtimeImporterTest extends ImporterTestAbstract
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$zipPath = $this->createTestZip('solidtime_import_test_1');
|
||||
// Note: The member of the test file has no billable rate, so one is added to the zip
|
||||
$zip = new ZipArchive;
|
||||
$zip->open($zipPath);
|
||||
$members = str_replace(',ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,admin,', ',ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,10003,admin,', $zip->getFromName('members.csv'), $replacements);
|
||||
$this->assertSame(1, $replacements);
|
||||
$zip->addFromString('members.csv', $members);
|
||||
$zip->close();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$organization = Organization::factory()->create();
|
||||
$importer = new SolidtimeImporter;
|
||||
@@ -127,6 +135,9 @@ class SolidtimeImporterTest extends ImporterTestAbstract
|
||||
// Assert
|
||||
$this->assertSame(3, Project::query()->whereBelongsTo($organization, 'organization')->whereNull('billable_rate')->where('is_billable', '=', false)->count());
|
||||
$this->assertSame(1, ProjectMember::query()->whereBelongsToOrganization($organization)->whereNull('billable_rate')->count());
|
||||
$members = Member::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(1, $members);
|
||||
$this->assertNull($members->first()->billable_rate);
|
||||
$timeEntries = TimeEntry::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $timeEntries);
|
||||
foreach ($timeEntries as $timeEntry) {
|
||||
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Service\Import\Importers;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\User;
|
||||
use App\Service\Import\Importers\DefaultImporter;
|
||||
use App\Service\Import\Importers\ImportException;
|
||||
@@ -216,4 +218,30 @@ class TogglDataImporterTest extends ImporterTestAbstract
|
||||
$this->assertSame('UTC', $user->timezone);
|
||||
$this->assertTrue($user->is_placeholder);
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$zipPath = $this->createTestZip('toggl_data_import_test_1');
|
||||
$timezone = 'Europe/Vienna';
|
||||
$organization = Organization::factory()->create();
|
||||
$importer = new TogglDataImporter;
|
||||
$importer->init($organization);
|
||||
$data = file_get_contents($zipPath);
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$projects = Project::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(3, $projects);
|
||||
foreach ($projects as $project) {
|
||||
$this->assertFalse($project->is_billable);
|
||||
$this->assertNull($project->billable_rate);
|
||||
}
|
||||
$projectMembers = ProjectMember::query()->whereBelongsToOrganization($organization)->get();
|
||||
$this->assertCount(1, $projectMembers);
|
||||
$this->assertNull($projectMembers->first()->billable_rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,4 +143,26 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
||||
}
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
public function test_import_drops_billable_flags_and_rates_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new TogglTimeEntriesImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_1.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$timeEntries = TimeEntry::query()->whereBelongsTo($organization, 'organization')->get();
|
||||
$this->assertCount(2, $timeEntries);
|
||||
foreach ($timeEntries as $timeEntry) {
|
||||
$this->assertFalse($timeEntry->billable);
|
||||
$this->assertNull($timeEntry->billable_rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user