33namespace Tests \Feature ;
44
55use App \Coding \Issue ;
6+ use App \Coding \Iteration ;
67use App \Coding \Project ;
78use Tests \TestCase ;
89
910class IssueImportCommandTest extends TestCase
1011{
12+ private string $ codingToken ;
1113 private string $ codingTeamDomain ;
1214 private string $ codingProjectUri ;
1315
1416 protected function setUp (): void
1517 {
1618 parent ::setUp ();
17- $ codingToken = $ this ->faker ->md5 ;
18- config (['coding.token ' => $ codingToken ]);
19+ $ this -> codingToken = $ this ->faker ->md5 ;
20+ config (['coding.token ' => $ this -> codingToken ]);
1921 $ this ->codingTeamDomain = $ this ->faker ->domainWord ;
2022 config (['coding.team_domain ' => $ this ->codingTeamDomain ]);
2123 $ this ->codingProjectUri = $ this ->faker ->slug ;
@@ -34,6 +36,8 @@ public function testImportSuccess()
3436
3537 $ issueMock = \Mockery::mock (Issue::class, [])->makePartial ();
3638 $ this ->instance (Issue::class, $ issueMock );
39+ $ iterationMock = \Mockery::mock (Iteration::class, [])->makePartial ();
40+ $ this ->instance (Iteration::class, $ iterationMock );
3741
3842 $ response = json_decode (
3943 file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIssueResponse.json ' ),
@@ -44,6 +48,11 @@ public function testImportSuccess()
4448 $ response ['Code ' ] = $ i ;
4549 $ results [] = $ response ;
4650 }
51+ $ iterationMock ->shouldReceive ('create ' )->times (2 )->andReturn (json_decode (
52+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIterationResponse.json ' ),
53+ true
54+ )['Response ' ]['Iteration ' ]);
55+
4756 $ issueMock ->shouldReceive ('create ' )->times (21 )->andReturn (...$ results );
4857
4958 $ this ->artisan ('issue:import ' , ['file ' => $ this ->dataDir . 'coding/scrum-issues.csv ' ])
@@ -54,4 +63,48 @@ public function testImportSuccess()
5463 ->expectsOutput ("https:// $ this ->codingTeamDomain .coding.net/p/ $ this ->codingProjectUri /all/issues/21 " )
5564 ->assertExitCode (0 );
5665 }
66+
67+ public function testImportUserStorySuccess ()
68+ {
69+ $ mock = \Mockery::mock (Project::class, [])->makePartial ();
70+ $ this ->instance (Project::class, $ mock );
71+
72+ $ mock ->shouldReceive ('getIssueTypes ' )->times (1 )->andReturn (json_decode (
73+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'DescribeProjectIssueTypeListResponse.json ' ),
74+ true
75+ )['Response ' ]['IssueTypes ' ]);
76+
77+ $ issueMock = \Mockery::mock (Issue::class, [])->makePartial ();
78+ $ this ->instance (Issue::class, $ issueMock );
79+ $ iterationMock = \Mockery::mock (Iteration::class, [])->makePartial ();
80+ $ this ->instance (Iteration::class, $ iterationMock );
81+
82+ $ response = json_decode (
83+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIssueResponse.json ' ),
84+ true
85+ )['Response ' ]['Issue ' ];
86+ $ response ['Code ' ] = $ this ->faker ->randomNumber ();
87+ $ result = $ response ;
88+ $ iterationMock ->shouldReceive ('create ' )->times (1 )->andReturn (json_decode (
89+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIterationResponse.json ' ),
90+ true
91+ )['Response ' ]['Iteration ' ]);
92+
93+ $ issueMock ->shouldReceive ('create ' )->times (1 )->withArgs ([
94+ $ this ->codingToken ,
95+ $ this ->codingProjectUri ,
96+ [
97+ 'Type ' => 'REQUIREMENT ' ,
98+ 'IssueTypeId ' => 213218 ,
99+ 'Name ' => '用户可通过手机号注册账户 ' ,
100+ 'Priority ' => "1 " ,
101+ 'IterationCode ' => 2746 ,
102+ ]
103+ ])->andReturn ($ result );
104+
105+ $ this ->artisan ('issue:import ' , ['file ' => $ this ->dataDir . 'coding/scrum-issue-5.csv ' ])
106+ ->expectsOutput ("https:// $ this ->codingTeamDomain .coding.net/p/ $ this ->codingProjectUri /all/issues/ " .
107+ $ result ['Code ' ])
108+ ->assertExitCode (0 );
109+ }
57110}
0 commit comments