Skip to content

Commit

Permalink
feat: #72 error when issue type not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 21, 2021
1 parent 39fc3aa commit ccb1f34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Commands/IssueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Coding\Issue;
use App\Coding\Iteration;
use App\Coding\Project;
use Exception;
use LaravelZero\Framework\Commands\Command;
use Rap2hpoutre\FastExcel\Facades\FastExcel;

Expand Down Expand Up @@ -57,7 +58,7 @@ public function handle(Issue $codingIssue, Project $codingProject, Iteration $it
foreach ($rows as $row) {
try {
$issueResult = $this->createIssueByRow($codingProject, $codingIssue, $iteration, $row);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->error('Error: ' . $e->getMessage());
return 1;
}
Expand All @@ -77,6 +78,9 @@ private function createIssueByRow(Project $codingProject, Issue $issue, Iteratio
$this->issueTypes[$item['Name']] = $item;
}
}
if (!isset($this->issueTypes[$row['事项类型']])) {
throw new Exception('' . $row['事项类型'] . '」类型不存在,请在项目设置中添加');
}
$data = [
'Type' => $this->issueTypes[$row['事项类型']]['IssueType'],
'IssueTypeId' => $this->issueTypes[$row['事项类型']]['Id'],
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/IssueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,15 @@ public function testImportSubTask()
->expectsOutput("https://$this->teamDomain.coding.net/p/$this->projectUri/all/issues/" . $subTask2['Code'])
->assertExitCode(0);
}

public function testImportFailedIssueTypeNotExists()
{
$mock = \Mockery::mock(Project::class, [])->makePartial();
$this->instance(Project::class, $mock);
$mock->shouldReceive('getIssueTypes')->times(1)->andReturn([]);

$this->artisan('issue:import', ['file' => $this->dataDir . 'coding/scrum-issues.csv'])
->expectsOutput('Error: 「史诗」类型不存在,请在项目设置中添加')
->assertExitCode(1);
}
}

0 comments on commit ccb1f34

Please sign in to comment.