Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into logs-remove-id-response
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrorodrigueszup authored Apr 30, 2021
2 parents 6ab316f + 80e0db0 commit cfeb755
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class V2ConfigurationController(
private val updateGitConfigurationInteractor: UpdateGitConfigurationInteractor,
private val gitStatusConfigurationInteractor: GitConnectionStatusConfigurationInteractor,
private val providerStatusConfigurationInteractor: ProviderConnectionStatusConfigurationInteractor,
private val createDeploymentConfigurationInteractor: CreateDeploymentConfigurationInteractor
private val createDeploymentConfigurationInteractor: CreateDeploymentConfigurationInteractor,
private val deleteDeploymentConfigurationByIdInteractor: DeleteDeploymentConfigurationByIdInteractor
) {

@ApiOperation(value = "Create git Configuration")
Expand Down Expand Up @@ -158,4 +159,21 @@ class V2ConfigurationController(
): DeploymentConfigurationResponse {
return this.createDeploymentConfigurationInteractor.execute(request, workspaceId, authorization)
}

@ApiOperation(value = "Delete Deployment Configuration By Id")
@ApiImplicitParam(
name = "id",
value = "Deployment Configuration Id",
required = true,
dataType = "string",
paramType = "path"
)
@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/deployment/{id}")
fun deleteDeploymentConfiguration(
@RequestHeader("x-workspace-id") workspaceId: String,
@PathVariable("id") id: String
) {
this.deleteDeploymentConfigurationByIdInteractor.execute(workspaceId, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class DeploymentConfigurationService(
}
}

fun delete(id: String) {
deploymentConfigurationRepository.delete(id)
}

fun checkIfDeploymentConfigurationExists(workspaceId: String, deploymentConfigurationId: String) {
if (!this.deploymentConfigurationRepository.exists(workspaceId, deploymentConfigurationId)) {
throw NotFoundException("deploymentConfigurationId", deploymentConfigurationId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.charlescd.moove.application.configuration

interface DeleteDeploymentConfigurationByIdInteractor {

fun execute(workspaceId: String, id: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.charlescd.moove.application.configuration.impl

import io.charlescd.moove.application.DeploymentConfigurationService
import io.charlescd.moove.application.configuration.DeleteDeploymentConfigurationByIdInteractor
import javax.inject.Inject
import javax.inject.Named

@Named
class DeleteDeploymentConfigurationByIdInteractorImpl @Inject constructor(
val deploymentConfigurationService: DeploymentConfigurationService
) : DeleteDeploymentConfigurationByIdInteractor {

override fun execute(workspaceId: String, id: String) {
deploymentConfigurationService.checkIfDeploymentConfigurationExists(workspaceId, id)
deploymentConfigurationService.delete(id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.charlescd.moove.application.configuration.impl

import io.charlescd.moove.application.DeploymentConfigurationService
import io.charlescd.moove.application.configuration.DeleteDeploymentConfigurationByIdInteractor
import io.charlescd.moove.domain.exceptions.NotFoundException
import io.charlescd.moove.domain.repository.DeploymentConfigurationRepository
import spock.lang.Specification

class DeleteDeploymentConfigurationByIdInteractorImplTest extends Specification {

private DeleteDeploymentConfigurationByIdInteractor interactor

private DeploymentConfigurationRepository deploymentConfigurationRepository = Mock(DeploymentConfigurationRepository)

def setup() {
this.interactor = new DeleteDeploymentConfigurationByIdInteractorImpl(new DeploymentConfigurationService(deploymentConfigurationRepository))
}

def 'when deployment configuration id does not exist should throw exception'() {
given:
def deploymentConfigurationId = "4e806b2a-557b-45c5-91be-1e1db909bef6"
def workspaceId = "00000000-557b-45c5-91be-1e1db909bef6"

when:
interactor.execute(workspaceId, deploymentConfigurationId)

then:
1 * deploymentConfigurationRepository.exists(workspaceId, deploymentConfigurationId) >> false

def ex = thrown(NotFoundException)
ex.resourceName == "deploymentConfigurationId"
ex.id == deploymentConfigurationId
}

def 'should delete git configuration id successfully'() {
given:
def deploymentConfigurationId = "4e806b2a-557b-45c5-91be-1e1db909bef6"
def workspaceId = "00000000-557b-45c5-91be-1e1db909bef6"

when:
interactor.execute(workspaceId, deploymentConfigurationId)

then:
1 * deploymentConfigurationRepository.exists(workspaceId, deploymentConfigurationId) >> true
1 * deploymentConfigurationRepository.delete(deploymentConfigurationId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ interface DeploymentConfigurationRepository {
fun exists(workspaceId: String, id: String): Boolean

fun existsAnyByWorkspaceId(workspaceId: String): Boolean

fun delete(id: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class JdbcDeploymentConfigurationRepository(
return checkIfAnyDeploymentConfigurationExistsByWorkspaceId(workspaceId)
}

override fun delete(id: String) {
deleteDeploymentConfigurationById(id)
}

private fun checkIfDeploymentConfigurationExistsByWorkspaceId(workspaceId: String, id: String): Boolean {
val countStatement = StringBuilder(BASE_COUNT_QUERY_STATEMENT)
.appendln("AND deployment_configurations.id = ?")
Expand All @@ -138,4 +142,14 @@ class JdbcDeploymentConfigurationRepository(
) { rs, _ -> rs.getInt(1) }
return count != null && count >= 1
}

private fun deleteDeploymentConfigurationById(id: String) {
val statement = """
DELETE
FROM deployment_configurations
WHERE id = ?
"""

this.jdbcTemplate.update(statement, id)
}
}
8 changes: 7 additions & 1 deletion ui/src/core/components/Card/Body/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@
* limitations under the License.
*/

import styled from 'styled-components';
import styled, { css } from 'styled-components';

const CardBody = styled.div`
margin-left: 17px;
margin-right: 17px;
word-wrap: break-word;
${({ onClick }) =>
onClick &&
css`
cursor: pointer;
`}
`;

export default {
Expand Down
32 changes: 30 additions & 2 deletions ui/src/core/components/Card/Config/__tests__/Config.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { render, waitFor } from 'unit-test/testUtils';
import userEvent from '@testing-library/user-event';
import CardConfig from '../';


const props = {
icon: 'git',
description: 'description'
}

test('render CardConfig default component', async () => {
const click = jest.fn();
const props = {
Expand All @@ -31,7 +37,8 @@ test('render CardConfig default component', async () => {
<CardConfig
icon={props.icon}
description={props.description}
onClose={click} />
onClose={click}
/>
);

const btnAction = queryByTestId('icon-cancel');
Expand All @@ -42,4 +49,25 @@ test('render CardConfig default component', async () => {
expect(btnAction).toBeInTheDocument();
userEvent.click(btnAction);
await waitFor(() => expect(click).toBeCalled());
});
});


test('render CardConfig default component with dropdown actions', async () => {
const click = jest.fn();

const { getByText, queryByTestId } = render(
<CardConfig
icon={props.icon}
description={props.description}
actions={<></>}
onClick={click}
/>
);

const btnAction = queryByTestId('icon-cancel');

expect(queryByTestId(`icon-${props.icon}`)).toBeInTheDocument();
expect(getByText(props.description)).toBeInTheDocument();

expect(btnAction).not.toBeInTheDocument();
});
11 changes: 6 additions & 5 deletions ui/src/core/components/Card/Config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import React from 'react';
import React, { ReactNode } from 'react';
import Card from 'core/components/Card';
import Icon from 'core/components/Icon';
import Text from 'core/components/Text';
Expand All @@ -25,16 +25,18 @@ export interface Props {
isDisabled?: boolean;
icon: string;
description: string;
actions?: ReactNode;
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
onClose?: (event: React.MouseEvent<unknown, MouseEvent>) => void;
canClose?: boolean;
children?: React.ReactNode;
children?: ReactNode;
className?: string;
}

const CardConfig = ({
icon,
description,
actions,
onClose,
canClose = true,
onClick,
Expand All @@ -60,11 +62,11 @@ const CardConfig = ({
);

const renderHeader = () => (
<Card.Header icon={headerIcon} action={headerAction} />
<Card.Header icon={headerIcon} action={actions || headerAction} />
);

const renderBody = () => (
<Styled.Body>
<Styled.Body onClick={onClick}>
<Text.h4 color="light">{description}</Text.h4>
{children}
</Styled.Body>
Expand All @@ -73,7 +75,6 @@ const CardConfig = ({
return (
<Styled.CardConfig
className={className}
onClick={onClick}
isDisabled={isDisabled}
>
{renderHeader()}
Expand Down
7 changes: 3 additions & 4 deletions ui/src/modules/Modules/Comparation/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { NEW_TAB } from 'core/components/TabPanel/constants';
import { Module } from '../interfaces/Module';
import { Component } from '../interfaces/Component';
import { useFindModule, useDeleteModule } from '../hooks/module';
import { resolveParams, pathModuleById } from './helpers';
import { resolveParams } from './helpers';
import FormModule from './Form';
import FormComponent from './Form/Component';
import ViewModule from './View';
Expand Down Expand Up @@ -109,8 +109,8 @@ const Tab = ({ param }: Props) => {
<Can I="read" a="modules" passThrough>
<Dropdown.Item
icon="copy"
name="Copy link"
onClick={() => copyToClipboard(pathModuleById(id))}
name="Copy ID"
onClick={() => copyToClipboard(id)}
/>
</Can>
</Dropdown>
Expand All @@ -122,7 +122,6 @@ const Tab = ({ param }: Props) => {
{mode === 'view' && isEmpty(component) && (
<ViewModule
module={module}
mode={mode}
onChange={updateModule}
onSelectComponent={(c: Component) => setComponent(c)}
/>
Expand Down
Loading

0 comments on commit cfeb755

Please sign in to comment.