@@ -16,8 +16,7 @@ class JobTest extends HypernodeClientTestCase
1616 protected function setUp (): void
1717 {
1818 parent ::setUp ();
19- $ this ->jobUrl = "https://api.hypernode.com/logbook/v1/jobs/abcd/ " ;
20- $ this ->job = new Job ($ this ->client , $ this ->jobUrl );
19+ $ this ->job = new Job ($ this ->client , 'johndoe ' , 'abcd ' );
2120 }
2221
2322 public function testIsInstanceOfAbstractResource ()
@@ -29,17 +28,100 @@ public function testRefresh()
2928 {
3029 $ this ->responses ->append (
3130 new Response (404 , [], json_encode ([])),
31+ new Response (200 , [], json_encode (['count ' => 0 , 'results ' => []])),
3232 new Response (200 , [], json_encode ([
33- 'result ' => 'pending ' ,
34- 'flow_name ' => 'update_node ' ,
35- 'app_name ' => 'johndoe '
33+ 'count ' => 1 ,
34+ 'results ' => [
35+ [
36+ 'uuid ' => 'abcd ' ,
37+ 'state ' => NULL ,
38+ 'name ' => 'update_node '
39+ ]
40+ ]
3641 ])),
3742 new Response (200 , [], json_encode ([
38- 'result ' => 'running ' ,
39- 'flow_name ' => 'update_node ' ,
40- 'app_name ' => 'johndoe '
43+ 'count ' => 1 ,
44+ 'results ' => [
45+ [
46+ 'uuid ' => 'abcd ' ,
47+ 'state ' => 'running ' ,
48+ 'name ' => 'update_node '
49+ ]
50+ ]
51+ ])),
52+ new Response (200 , [], json_encode ([
53+ 'count ' => 1 ,
54+ 'results ' => [
55+ [
56+ 'uuid ' => 'abcd ' ,
57+ 'state ' => 'success ' ,
58+ 'name ' => 'update_node '
59+ ]
60+ ]
61+ ])),
62+ );
63+
64+ $ this ->job ->refresh ();
65+
66+ $ this ->assertFalse ($ this ->job ->exists ());
67+ $ this ->assertFalse ($ this ->job ->completed ());
68+
69+ $ this ->job ->refresh ();
70+
71+ $ this ->assertFalse ($ this ->job ->exists ());
72+ $ this ->assertFalse ($ this ->job ->completed ());
73+
74+ $ this ->job ->refresh ();
75+
76+ $ this ->assertTrue ($ this ->job ->exists ());
77+ $ this ->assertFalse ($ this ->job ->completed ());
78+
79+ $ this ->job ->refresh ();
80+
81+ $ this ->assertTrue ($ this ->job ->exists ());
82+ $ this ->assertFalse ($ this ->job ->completed ());
83+
84+ $ this ->job ->refresh ();
85+
86+ $ this ->assertTrue ($ this ->job ->exists ());
87+ $ this ->assertTrue ($ this ->job ->completed ());
88+ $ this ->assertTrue ($ this ->job ->success ());
89+ }
90+
91+ public function testRefreshFailedJob ()
92+ {
93+ $ this ->responses ->append (
94+ new Response (404 , [], json_encode ([])),
95+ new Response (200 , [], json_encode ([
96+ 'count ' => 1 ,
97+ 'results ' => [
98+ [
99+ 'uuid ' => 'abcd ' ,
100+ 'state ' => NULL ,
101+ 'name ' => 'update_node '
102+ ]
103+ ]
104+ ])),
105+ new Response (200 , [], json_encode ([
106+ 'count ' => 1 ,
107+ 'results ' => [
108+ [
109+ 'uuid ' => 'abcd ' ,
110+ 'state ' => 'running ' ,
111+ 'name ' => 'update_node '
112+ ]
113+ ]
114+ ])),
115+ new Response (200 , [], json_encode ([
116+ 'count ' => 1 ,
117+ 'results ' => [
118+ [
119+ 'uuid ' => 'abcd ' ,
120+ 'state ' => 'reverted ' ,
121+ 'name ' => 'update_node '
122+ ]
123+ ]
41124 ])),
42- new Response (303 , [], json_encode ([])),
43125 );
44126
45127 $ this ->job ->refresh ();
@@ -61,6 +143,7 @@ public function testRefresh()
61143
62144 $ this ->assertTrue ($ this ->job ->exists ());
63145 $ this ->assertTrue ($ this ->job ->completed ());
146+ $ this ->assertFalse ($ this ->job ->success ());
64147 }
65148
66149 public function testExistsReturnsFalseByDefault ()
0 commit comments