public function test_Should_ConvertMessageToText()
 {
     $deployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'status' => null, 'task' => 'deploy', 'user_id' => 1, 'message' => 'Message', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon(), 'user' => new App\Models\User()]);
     $converter = new AnsiToHtmlConverter();
     $deploymentPresenter = new DeploymentPresenter($deployment, $converter);
     $html = $deploymentPresenter->messageText();
     $this->assertEquals('Message', $html);
 }
Example #2
0
 public function test_Should_DeleteExistingServer()
 {
     $arrangedServer = Factory::create('App\\Models\\Server', ['name' => 'Server 1', 'description' => '', 'body' => '']);
     $serverRepository = new EloquentServer(new App\Models\Server());
     $serverRepository->delete($arrangedServer->id);
     $server = new App\Models\Server();
     $deletedServer = $server->find($arrangedServer->id);
     $this->assertNull($deletedServer);
 }
Example #3
0
 public function test_Should_DeleteExistingRole()
 {
     $arrangedRole = Factory::create('Kodeine\\Acl\\Models\\Eloquent\\Role', ['name' => 'Role 1', 'slug' => 'role_1', 'description' => '']);
     $serverRepository = new EloquentRole(new Kodeine\Acl\Models\Eloquent\Role());
     $serverRepository->delete($arrangedRole->id);
     $server = new Kodeine\Acl\Models\Eloquent\Role();
     $deletedRole = $server->find($arrangedRole->id);
     $this->assertNull($deletedRole);
 }
Example #4
0
 public function test_Should_DeleteExistingRecipe()
 {
     $arrangedRecipe = Factory::create('App\\Models\\Recipe', ['name' => 'Recipe 1', 'description' => '', 'body' => '']);
     $recipeRepository = new EloquentRecipe(new App\Models\Recipe());
     $recipeRepository->delete($arrangedRecipe->id);
     $recipe = new App\Models\Recipe();
     $deletedRecipe = $recipe->find($arrangedRecipe->id);
     $this->assertNull($deletedRecipe);
 }
 public function test_Should_DisplayShowPage_When_ShowPageIsRequestedAndResourceIsFound()
 {
     $deployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'task' => 'deploy', 'user_id' => 1, 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon(), 'user' => new App\Models\User()]);
     $project = $this->mockProjectModel->shouldReceive('getDeploymentByNumber')->once()->andReturn($deployment)->mock();
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->get('projects/1/deployments/1');
     $this->assertResponseOk();
     $this->assertViewHas('deployment');
 }
 public function test_Should_ReturnStatusCode400_When_StoreProcessFails()
 {
     $project = Factory::build('App\\Models\\Project', ['id' => 1, 'name' => 'Project 1', 'github_webhook_user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon()]);
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->mockDeploymentForm->shouldReceive('save')->once()->andReturn(false);
     $this->mockDeploymentForm->shouldReceive('errors')->once()->andReturn(new \Illuminate\Support\MessageBag());
     $this->post('webhook/github/v1/projects/1/deployments');
     $this->assertResponseStatus(400);
 }
 public function test_Should_PassToValidate_When_NameFieldAndRecipeIdFieldAndServerIdFieldAndRepositoryFieldAndStageFieldAreValid()
 {
     Factory::create('App\\Models\\Recipe', ['name' => 'Recipe 1', 'description' => '', 'body' => '']);
     Factory::create('App\\Models\\Server', ['name' => 'Server 1', 'description' => '', 'body' => '']);
     $input = ['name' => 'Project 1', 'recipe_id' => [1], 'server_id' => 1, 'repository' => 'http://example.com', 'stage' => 'staging'];
     $form = new ProjectFormLaravelValidator($this->app['validator']);
     $result = $form->with($input)->passes();
     $errors = $form->errors();
     $this->assertTrue($result, 'Expected validation to succeed.');
     $this->assertEmpty($errors);
 }
Example #8
0
 public function test_Should_GetDeploymentsWhereNumberBefore()
 {
     $arrangedServer = Factory::create('App\\Models\\Server');
     $arrangedProject = Factory::create('App\\Models\\Project', ['server_id' => $arrangedServer->id]);
     $arrangedDeployments1 = Factory::create('App\\Models\\Deployment', ['project_id' => $arrangedProject->id, 'number' => 1]);
     $arrangedDeployments2 = Factory::create('App\\Models\\Deployment', ['project_id' => $arrangedProject->id, 'number' => 2]);
     $arrangedDeployments3 = Factory::create('App\\Models\\Deployment', ['project_id' => $arrangedProject->id, 'number' => 3]);
     $arrangedDeployments4 = Factory::create('App\\Models\\Deployment', ['project_id' => $arrangedProject->id, 'number' => 4]);
     $foundDeployments = $arrangedProject->getDeploymentsWhereNumberBefore(3);
     $this->assertEquals($arrangedDeployments2, $foundDeployments[0]);
     $this->assertEquals($arrangedDeployments1, $foundDeployments[1]);
 }
Example #9
0
 public function test_Should_FailToSave_When_ValidationPassesAndSaveToDatabaseFails()
 {
     $this->mockValidator->shouldReceive('with')->once()->andReturn($this->mockValidator);
     $this->mockValidator->shouldReceive('passes')->once()->andReturn(true);
     $project = $this->mockProjectModel;
     $maxDeployment = Factory::build('App\\Models\\MaxDeployment', ['id' => 1, 'project_id' => $project->id, 'number' => 1, 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $project->shouldReceive('getMaxDeployment')->once()->andReturn($maxDeployment)->shouldReceive('addDeployment')->once()->shouldReceive('updateMaxDeployment')->once()->shouldReceive('getDeploymentByNumber')->once()->andReturn(false)->mock();
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $form = new DeploymentForm($this->mockValidator, $this->mockProjectRepository, $this->mockDeployCommander);
     $result = $form->save(['project_id' => $project->id, 'task' => 'deploy']);
     $this->assertFalse($result, 'Expected save to fail.');
 }
 public function test_Should_PassToValidate_When_ProjectIdFieldAndTaskFieldAndUserIdFieldAreValid()
 {
     $arrangedServer = Factory::create('App\\Models\\Server', ['name' => 'Server 1', 'description' => '', 'body' => '']);
     Factory::create('App\\Models\\Project', ['name' => 'Project 1', 'server_id' => $arrangedServer->id, 'stage' => 'staging']);
     Factory::create('App\\Models\\User', ['email' => '*****@*****.**', 'password' => '0123456789', 'api_token' => '0123456789']);
     $input = ['project_id' => 1, 'task' => 'deploy', 'user_id' => 1];
     $form = new DeploymentFormLaravelValidator($this->app['validator']);
     $result = $form->with($input)->passes();
     $errors = $form->errors();
     $this->assertTrue($result, 'Expected validation to succeed.');
     $this->assertEmpty($errors);
 }
Example #11
0
 public function test_Should_DeleteExistingProject()
 {
     $arrangedRecipe = Factory::create('App\\Models\\Recipe', ['name' => 'Recipe 1', 'description' => '', 'body' => '']);
     $arrangedServer = Factory::create('App\\Models\\Server', ['name' => 'Recipe 1', 'description' => '', 'body' => '']);
     $arrangedProject = Factory::create('App\\Models\\Project', ['name' => 'Project 1', 'server_id' => $arrangedServer->id, 'stage' => 'staging']);
     $arrangedProject->recipes()->sync([$arrangedRecipe->id => ['recipe_order' => 1]]);
     $projectRepository = new EloquentProject(new App\Models\Project(), new App\Models\MaxDeployment());
     $projectRepository->delete($arrangedProject->id);
     $project = new App\Models\Project();
     $deletedProject = $project->find($arrangedProject->id);
     $this->assertNull($deletedProject);
     $updatedProjectRecipes = $arrangedProject->recipes;
     $this->assertEmpty($updatedProjectRecipes);
 }
Example #12
0
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $user = Factory::build('App\\Models\\User', ['id' => 1, 'name' => 'User 1', 'email' => '*****@*****.**', 'password' => '12345678', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockUserRepository->shouldReceive('byId')->once()->andReturn($user);
     $this->mockUserRepository->shouldReceive('delete')->once();
     $this->delete('users/1');
     $this->assertRedirectedToRoute('users.index');
 }
 public function test_Should_PassToValidate_When_EmailFieldIsNotUniqueAndIdFieldIsSpecified()
 {
     $arrangedUser = Factory::create('App\\Models\\User', ['email' => '*****@*****.**']);
     $input = ['id' => $arrangedUser->id, 'email' => '*****@*****.**'];
     $form = new UserFormLaravelValidator($this->app['validator']);
     $result = $form->with($input)->passes();
     $errors = $form->errors();
     $this->assertTrue($result, 'Expected validation to succeed.');
     $this->assertEmpty($errors);
 }
Example #14
0
 public function test_Should_DeleteExistingUser()
 {
     $arrangedUser = Factory::create('App\\Models\\User', ['name' => 'User 1', 'email' => '*****@*****.**', 'password' => '12345678', 'api_token' => '12345678']);
     $userRepository = new EloquentUser(new App\Models\User());
     $userRepository->delete($arrangedUser->id);
     $user = new App\Models\User();
     $deletedUser = $user->find($arrangedUser->id);
     $this->assertNull($deletedUser);
 }
Example #15
0
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $project = Factory::build('App\\Models\\Project', ['id' => 1, 'name' => 'Project 1', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->mockProjectRepository->shouldReceive('delete')->once();
     $this->delete('projects/1');
     $this->assertRedirectedToRoute('projects.index');
 }
Example #16
0
 public function test_Should_WorkAndSendNotification_When_DeployerIsAbnormalEndAndEmailNotificationRecipientIsSet()
 {
     $deployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'task' => 'deploy', 'user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon(), 'user' => new \App\Models\User()]);
     $updatedDeployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'task' => 'deploy', 'user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon(), 'user' => new \App\Models\User(), 'stauts' => 1]);
     $recipe = Factory::build('App\\Models\\Recipe', ['id' => 1, 'name' => 'Recipe 1', 'desctiption' => '', 'body' => '']);
     $project = $this->mockProjectModel->shouldReceive('updateDeployment')->once()->shouldReceive('getDeploymentByNumber')->once()->andReturn($updatedDeployment)->mock();
     $project = $this->mockProjectModel->shouldReceive('getRecipes')->once()->andReturn([$recipe])->mock();
     $project->email_notification_recipient = '*****@*****.**';
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->mockServerRepository->shouldReceive('byId')->once()->andReturn($this->mockServerModel);
     $mockDeployerFile = $this->mock('App\\Services\\Deployment\\DeployerFile')->shouldReceive('getFullPath')->once()->mock();
     $this->mockDeployerFileDirector->shouldReceive('construct')->andReturn($mockDeployerFile)->times(3);
     $this->mockProcess->shouldReceive('run')->once();
     $this->mockProcess->shouldReceive('isSuccessful')->twice()->andReturn(false);
     $this->mockProcess->shouldReceive('getErrorOutput')->once();
     $this->mockProcess->shouldReceive('getExitCode')->once();
     $this->mockProcessBuilder->shouldReceive('add')->times(7)->andReturn($this->mockProcessBuilder);
     $this->mockProcessBuilder->shouldReceive('getProcess')->once()->andReturn($this->mockProcess);
     $this->mockNotifier->shouldReceive('to')->once()->andReturn($this->mockNotifier);
     $this->mockNotifier->shouldReceive('notify')->once();
     $this->mockMailSettingEntity->shouldReceive('getDriver')->once()->shouldReceive('getFrom')->twice()->shouldReceive('getSmtpHost')->once()->shouldReceive('getSmtpPort')->once()->shouldReceive('getSmtpEncryption')->once()->shouldReceive('getSmtpUsername')->once()->shouldReceive('getSmtpPassword')->once()->shouldReceive('getSendmailPath')->once();
     $this->mockSettingModel->shouldReceive('getAttribute')->with('attributes')->andReturn($this->mockMailSettingEntity);
     $this->mockSettingRepositroy->shouldReceive('byType')->once()->andReturn($this->mockSettingModel);
     $this->mockServerListFileBuilder->shouldReceive('setServer')->once()->andReturn($this->mockServerListFileBuilder);
     $this->mockServerListFileBuilder->shouldReceive('setProject')->once()->andReturn($this->mockServerListFileBuilder);
     $this->mockRecipeFileBuilder->shouldReceive('setRecipe')->once();
     $this->mockDeploymentFileBuilder->shouldReceive('setProject')->once()->andReturn($this->mockDeploymentFileBuilder);
     $this->mockDeploymentFileBuilder->shouldReceive('setServerListFile')->once()->andReturn($this->mockDeploymentFileBuilder);
     $this->mockDeploymentFileBuilder->shouldReceive('setRecipeFile')->once()->andReturn($this->mockDeploymentFileBuilder);
     $job = new Deploy($deployment);
     $job->handle($this->mockProjectRepository, $this->mockServerRepository, $this->mockProcessBuilder, $this->mockNotifier, $this->mockSettingRepositroy);
 }
Example #17
0
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $recipe = Factory::build('App\\Models\\Recipe', ['id' => 1, 'name' => 'Recipe 1', 'description' => '', 'body' => '', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockRecipeRepository->shouldReceive('byId')->once()->andReturn($recipe);
     $this->mockRecipeRepository->shouldReceive('delete')->once();
     $this->delete('recipes/1');
     $this->assertRedirectedToRoute('recipes.index');
 }