Skip to content

Commit

Permalink
Merge pull request #2120 from qmonmert/angular/health
Browse files Browse the repository at this point in the history
Front part to generate Angular Health
  • Loading branch information
pascalgrimaud committed Jun 15, 2022
2 parents daf5225 + d280156 commit 18edadf
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/app/common/domain/Service.ts
Expand Up @@ -3,6 +3,7 @@ export enum Service {
ANGULAR = 'ANGULAR',
ANGULAR_WITH_JWT = 'ANGULAR_WITH_JWT',
ANGULAR_OAUTH2 = 'ANGULAR_OAUTH2',
ANGULAR_HEALTH = 'ANGULAR_HEALTH',
CONSUL = 'CONSUL',
DEV_TOOLS = 'DEV_TOOLS',
DOCKERFILE = 'DOCKERFILE',
Expand Down
Expand Up @@ -4,4 +4,5 @@ export interface AngularService {
add(project: Project): Promise<void>;
addWithJWT(project: Project): Promise<void>;
addOauth2(project: Project): Promise<void>;
addHealth(project: Project): Promise<void>;
}
Expand Up @@ -5,6 +5,7 @@ export type ServiceProjection =
| 'angular'
| 'angular-with-jwt'
| 'angular-oauth2'
| 'angular-health'
| 'consul'
| 'dev-tools'
| 'dockerfile'
Expand Down Expand Up @@ -59,6 +60,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[Service.ANGULAR]: 'angular',
[Service.ANGULAR_WITH_JWT]: 'angular-with-jwt',
[Service.ANGULAR_OAUTH2]: 'angular-oauth2',
[Service.ANGULAR_HEALTH]: 'angular-health',
[Service.CONSUL]: 'consul',
[Service.DEV_TOOLS]: 'dev-tools',
[Service.DOCKERFILE]: 'dockerfile',
Expand Down Expand Up @@ -116,6 +118,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
angular: Service.ANGULAR,
'angular-with-jwt': Service.ANGULAR_WITH_JWT,
'angular-oauth2': Service.ANGULAR_OAUTH2,
'angular-health': Service.ANGULAR_HEALTH,
consul: Service.CONSUL,
'dev-tools': Service.DEV_TOOLS,
dockerfile: Service.DOCKERFILE,
Expand Down
Expand Up @@ -51,11 +51,21 @@ export default defineComponent({
}
};

const addHealth = async (): Promise<void> => {
if (props.project.folder !== '') {
await angularService
.addHealth(toProject(props.project as ProjectToUpdate))
.then(() => alertBus.success('Health successfully added'))
.catch(error => alertBus.error(`Adding Health to project failed ${error}`));
}
};

return {
selectorPrefix,
addAngular,
addAngularWithJWT,
addOauth2,
addHealth,
props,
};
},
Expand Down
Expand Up @@ -8,7 +8,9 @@
@click.prevent="addAngularWithJWT"
/>
<GeneratorButtonVue :label="'Add OAuth2'" :service="'angular-oauth2'" :selector-prefix="selectorPrefix" @click.prevent="addOauth2" />
<GeneratorButtonVue :label="'Add Health'" :service="'angular-health'" :selector-prefix="selectorPrefix" @click.prevent="addHealth" />
</div>
</template>

<script lang="ts" src="./AngularGenerator.component.ts"></script>
ngularRepository.spec.ts
Expand Up @@ -22,4 +22,8 @@ export default class AngularRepository implements AngularService {
async addOauth2(project: Project): Promise<void> {
await this.postAndGetHistory('/api/clients/angular/oauth2', toRestProject(project));
}

async addHealth(project: Project): Promise<void> {
await this.postAndGetHistory('/api/clients/angular/admin-pages/health', toRestProject(project));
}
}
1 change: 1 addition & 0 deletions src/test/javascript/cypress/integration/Generator.spec.ts
Expand Up @@ -85,6 +85,7 @@ describe('Generator', () => {
cy.get(angularGeneratorSelector('add-angular-button')).contains('Angular');
cy.get(angularGeneratorSelector('add-angular-with-jwt-button')).contains('Add JWT');
cy.get(angularGeneratorSelector('add-angular-oauth2-button')).contains('Add OAuth2');
cy.get(angularGeneratorSelector('add-angular-health-button')).contains('Add Health');
});

it('should display react', () => {
Expand Down
Expand Up @@ -42,6 +42,7 @@ export interface SpringBootServiceFixture extends SpringBootService {
addBasicAuthJWT: SinonStub;
addOAuth2: SinonStub;
addOAuth2Account: SinonStub;
addHealth: SinonStub;
addSpringdocJWT: SinonStub;

addPulsar: SinonStub;
Expand Down Expand Up @@ -95,6 +96,7 @@ export const stubSpringBootService = (): SpringBootServiceFixture => ({
addBasicAuthJWT: sinon.stub(),
addOAuth2: sinon.stub(),
addOAuth2Account: sinon.stub(),
addHealth: sinon.stub(),
addSpringdocJWT: sinon.stub(),

addPulsar: sinon.stub(),
Expand Down
Expand Up @@ -5,10 +5,12 @@ export interface AngularServiceFixture extends AngularService {
add: SinonStub;
addWithJWT: SinonStub;
addOauth2: SinonStub;
addHealth: SinonStub;
}

export const stubAngularService = (): AngularServiceFixture => ({
add: sinon.stub(),
addWithJWT: sinon.stub(),
addOauth2: sinon.stub(),
addHealth: sinon.stub(),
});
Expand Up @@ -7,6 +7,7 @@ describe('ServiceProjection', () => {
expect(toServiceProjection(Service.ANGULAR)).toEqual<ServiceProjection>('angular');
expect(toServiceProjection(Service.ANGULAR_WITH_JWT)).toEqual<ServiceProjection>('angular-with-jwt');
expect(toServiceProjection(Service.ANGULAR_OAUTH2)).toEqual<ServiceProjection>('angular-oauth2');
expect(toServiceProjection(Service.ANGULAR_HEALTH)).toEqual<ServiceProjection>('angular-health');
expect(toServiceProjection(Service.CONSUL)).toEqual<ServiceProjection>('consul');
expect(toServiceProjection(Service.DEV_TOOLS)).toEqual<ServiceProjection>('dev-tools');
expect(toServiceProjection(Service.DOWNLOAD)).toEqual<ServiceProjection>('download');
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('ServiceProjection', () => {
expect(fromServiceProjection('angular')).toEqual<Service>(Service.ANGULAR);
expect(fromServiceProjection('angular-with-jwt')).toEqual<Service>(Service.ANGULAR_WITH_JWT);
expect(fromServiceProjection('angular-oauth2')).toEqual<Service>(Service.ANGULAR_OAUTH2);
expect(fromServiceProjection('angular-health')).toEqual<Service>(Service.ANGULAR_HEALTH);
expect(fromServiceProjection('consul')).toEqual<Service>(Service.CONSUL);
expect(fromServiceProjection('dev-tools')).toEqual<Service>(Service.DEV_TOOLS);
expect(fromServiceProjection('dockerfile')).toEqual<Service>(Service.DOCKERFILE);
Expand Down
Expand Up @@ -156,4 +156,38 @@ describe('AngularGenerator', () => {

expectAlertErrorToBe(alertBus, 'Adding Oauth2 to project failed error');
});

it('should not add Health when project path is not filled', async () => {
const angularService = stubAngularService();
angularService.addHealth.resolves({});
await wrap({ angularService, project: createProjectToUpdate({ folder: '' }) });

await component.addHealth();

expect(angularService.addHealth.called).toBe(false);
});

it('should add Health when project path is filled', async () => {
const angularService = stubAngularService();
angularService.addHealth.resolves({});
const alertBus = stubAlertBus();
await wrap({ angularService, project: createProjectToUpdate({ folder: 'project/path' }), alertBus });

await component.addHealth();

const args = angularService.addHealth.getCall(0).args[0];
expect(args).toEqual(projectJson);
expectAlertSuccessToBe(alertBus, 'Health successfully added');
});

it('should handle error on adding Health failure', async () => {
const angularService = stubAngularService();
const alertBus = stubAlertBus();
angularService.addHealth.rejects('error');
await wrap({ angularService, project: createProjectToUpdate({ folder: 'path' }), alertBus });

await component.addHealth();

expectAlertErrorToBe(alertBus, 'Adding Health to project failed error');
});
});
Expand Up @@ -58,4 +58,21 @@ describe('AngularRepository', () => {
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});

it('should add Health', async () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
axiosHttpStub.post.resolves();
const angularRepository = new AngularRepository(axiosHttpStub, projectHistoryService);
const project: Project = createProject({ folder: PROJECT_FOLDER });

await angularRepository.addHealth(project);

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('/api/clients/angular/admin-pages/health');
expect(payload).toEqual<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});
});

0 comments on commit 18edadf

Please sign in to comment.