mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand test coverage.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\ImportJob;
|
||||
use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -41,6 +42,37 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param int $steps
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function addStepsDone(ImportJob $job, int $steps = 1): ImportJob
|
||||
{
|
||||
$job->addStepsDone($steps);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of imported rows with this hash value.
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByHash(string $hash): int
|
||||
{
|
||||
$json = json_encode($hash);
|
||||
$count = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
->where('data', $json)
|
||||
->where('name', 'importHash')
|
||||
->count();
|
||||
|
||||
return intval($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
@@ -112,6 +144,23 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extended status of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtendedStatus(ImportJob $job): array
|
||||
{
|
||||
$status = $job->extended_status;
|
||||
if (is_array($status)) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param UploadedFile $file
|
||||
@@ -204,6 +253,24 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $array
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setExtendedStatus(ImportJob $job, array $array): ImportJob
|
||||
{
|
||||
Log::debug(sprintf('Incoming extended status for job "%s" is: ', $job->key), $array);
|
||||
$currentStatus = $job->extended_status;
|
||||
$newStatus = array_merge($currentStatus, $array);
|
||||
$job->extended_status = $newStatus;
|
||||
$job->save();
|
||||
Log::debug(sprintf('Set extended status of job "%s" to: ', $job->key), $newStatus);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
|
@@ -31,6 +31,23 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
*/
|
||||
interface ImportJobRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param int $steps
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function addStepsDone(ImportJob $job, int $steps = 1): ImportJob;
|
||||
|
||||
/**
|
||||
* Return number of imported rows with this hash value.
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByHash(string $hash): int;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
@@ -38,15 +55,6 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function create(string $type): ImportJob;
|
||||
|
||||
/**
|
||||
* Return import file content.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function uploadFileContents(ImportJob $job): string;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
@@ -63,6 +71,15 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function getConfiguration(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* Return extended status of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtendedStatus(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param UploadedFile $file
|
||||
@@ -87,6 +104,14 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function setConfiguration(ImportJob $job, array $configuration): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExtendedStatus(ImportJob $job, array $array): ImportJob;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@@ -99,4 +124,13 @@ interface ImportJobRepositoryInterface
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function updateStatus(ImportJob $job, string $status): ImportJob;
|
||||
|
||||
/**
|
||||
* Return import file content.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function uploadFileContents(ImportJob $job): string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user