1010use Tests \TestCase ;
1111
1212use function env ;
13+ use function json_encode ;
1314use function now ;
1415
1516class DeployCommandTest extends TestCase
@@ -33,7 +34,7 @@ public function test_it_can_run_the_deploy_command(): void
3334 ]);
3435
3536 $ this ->artisan ('nightwatch:deploy ' )
36- ->expectsOutput ('Deployment successful ' )
37+ ->expectsOutputToContain ('Deployment sent to Nightwatch successfully. ' )
3738 ->assertExitCode (0 );
3839 }
3940
@@ -55,7 +56,7 @@ public function test_it_can_run_the_deploy_command_without_a_version(): void
5556 ]);
5657
5758 $ this ->artisan ('nightwatch:deploy ' )
58- ->expectsOutput ('Deployment successful ' )
59+ ->expectsOutputToContain ('Deployment sent to Nightwatch successfully. ' )
5960 ->assertExitCode (0 );
6061 }
6162
@@ -64,7 +65,19 @@ public function test_it_fails_when_the_deploy_command_is_run_without_a_token():
6465 $ this ->app ->singleton (DeployCommand::class, fn () => new DeployCommand (token: null ));
6566
6667 $ this ->artisan ('nightwatch:deploy ' )
67- ->expectsOutput ('No NIGHTWATCH_TOKEN environment variable configured. ' )
68+ ->expectsOutputToContain ('Please configure the [NIGHTWATCH_TOKEN] environment variable. ' )
69+ ->assertExitCode (1 );
70+ }
71+
72+ #[WithEnv('NIGHTWATCH_TOKEN ' , 'test-token ' )]
73+ public function test_it_handles_error_responses (): void
74+ {
75+ Http::fake ([
76+ '*/api/deployments ' => Http::response (json_encode (['message ' => 'Invalid environment token. ' ]), 403 ),
77+ ]);
78+
79+ $ this ->artisan ('nightwatch:deploy ' )
80+ ->expectsOutputToContain ('Deployment could not be sent to Nightwatch: Invalid environment token. ' )
6881 ->assertExitCode (1 );
6982 }
7083
@@ -76,7 +89,7 @@ public function test_it_handles_http_errors(): void
7689 ]);
7790
7891 $ this ->artisan ('nightwatch:deploy ' )
79- ->expectsOutput ('Deployment failed: 500 [ Whoops!] ' )
92+ ->expectsOutputToContain ('Deployment could not be sent to Nightwatch: [ 500] Whoops! ' )
8093 ->assertExitCode (1 );
8194 }
8295
@@ -88,7 +101,7 @@ public function test_it_handles_connection_errors(): void
88101 ]);
89102
90103 $ this ->artisan ('nightwatch:deploy ' )
91- ->expectsOutput ('Deployment failed: [ Whoops!] ' )
104+ ->expectsOutputToContain ('Deployment could not be sent to Nightwatch: Whoops! ' )
92105 ->assertExitCode (1 );
93106 }
94107}
0 commit comments