From d280156c4e517693d59fad72331b641552699a41 Mon Sep 17 00:00:00 2001 From: Quentin Monmert Date: Wed, 15 Jun 2022 19:53:34 +0200 Subject: [PATCH] Front part to generate Angular Health --- src/main/webapp/app/common/domain/Service.ts | 1 + .../domain/client/AngularService.ts | 1 + .../primary/generator/ServiceProjection.ts | 3 ++ .../AngularGenerator.component.ts | 10 ++++++ .../angular-generator/AngularGenerator.vue | 2 ++ .../secondary/client/AngularRepository.ts | 4 +++ .../cypress/integration/Generator.spec.ts | 1 + .../domain/SpringBootService.fixture.ts | 2 ++ .../domain/client/AngularService.fixture.ts | 2 ++ .../generator/ServiceProjection.spec.ts | 2 ++ .../AngularGenerator.spec.ts | 34 +++++++++++++++++++ .../client/AngularRepository.spec.ts | 17 ++++++++++ 12 files changed, 79 insertions(+) diff --git a/src/main/webapp/app/common/domain/Service.ts b/src/main/webapp/app/common/domain/Service.ts index fb873c33557..b32fcb29d09 100644 --- a/src/main/webapp/app/common/domain/Service.ts +++ b/src/main/webapp/app/common/domain/Service.ts @@ -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', diff --git a/src/main/webapp/app/springboot/domain/client/AngularService.ts b/src/main/webapp/app/springboot/domain/client/AngularService.ts index 194d66cf66b..77d9ea1d3f5 100644 --- a/src/main/webapp/app/springboot/domain/client/AngularService.ts +++ b/src/main/webapp/app/springboot/domain/client/AngularService.ts @@ -4,4 +4,5 @@ export interface AngularService { add(project: Project): Promise; addWithJWT(project: Project): Promise; addOauth2(project: Project): Promise; + addHealth(project: Project): Promise; } diff --git a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts index 3f5f8499cf6..16f960d8f02 100644 --- a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts +++ b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts @@ -5,6 +5,7 @@ export type ServiceProjection = | 'angular' | 'angular-with-jwt' | 'angular-oauth2' + | 'angular-health' | 'consul' | 'dev-tools' | 'dockerfile' @@ -59,6 +60,7 @@ const SERVICES_PROJECTION: Record = { [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', @@ -116,6 +118,7 @@ const SERVICES: Record = { 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, diff --git a/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.component.ts b/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.component.ts index afb2153de4a..910724c56fe 100644 --- a/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.component.ts +++ b/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.component.ts @@ -51,11 +51,21 @@ export default defineComponent({ } }; + const addHealth = async (): Promise => { + 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, }; }, diff --git a/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.vue b/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.vue index a28f5621549..0f4cea3d79a 100644 --- a/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.vue +++ b/src/main/webapp/app/springboot/primary/generator/angular-generator/AngularGenerator.vue @@ -8,7 +8,9 @@ @click.prevent="addAngularWithJWT" /> + +ngularRepository.spec.ts diff --git a/src/main/webapp/app/springboot/secondary/client/AngularRepository.ts b/src/main/webapp/app/springboot/secondary/client/AngularRepository.ts index cd3706a0ff2..2273a5c9a6b 100644 --- a/src/main/webapp/app/springboot/secondary/client/AngularRepository.ts +++ b/src/main/webapp/app/springboot/secondary/client/AngularRepository.ts @@ -22,4 +22,8 @@ export default class AngularRepository implements AngularService { async addOauth2(project: Project): Promise { await this.postAndGetHistory('/api/clients/angular/oauth2', toRestProject(project)); } + + async addHealth(project: Project): Promise { + await this.postAndGetHistory('/api/clients/angular/admin-pages/health', toRestProject(project)); + } } diff --git a/src/test/javascript/cypress/integration/Generator.spec.ts b/src/test/javascript/cypress/integration/Generator.spec.ts index 3bbe69ed04c..60ab2d84105 100644 --- a/src/test/javascript/cypress/integration/Generator.spec.ts +++ b/src/test/javascript/cypress/integration/Generator.spec.ts @@ -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', () => { diff --git a/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts b/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts index 5f34a4302b4..e2023dd5440 100644 --- a/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts +++ b/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts @@ -42,6 +42,7 @@ export interface SpringBootServiceFixture extends SpringBootService { addBasicAuthJWT: SinonStub; addOAuth2: SinonStub; addOAuth2Account: SinonStub; + addHealth: SinonStub; addSpringdocJWT: SinonStub; addPulsar: SinonStub; @@ -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(), diff --git a/src/test/javascript/spec/springboot/domain/client/AngularService.fixture.ts b/src/test/javascript/spec/springboot/domain/client/AngularService.fixture.ts index 46f6756b443..0bf064b6f98 100644 --- a/src/test/javascript/spec/springboot/domain/client/AngularService.fixture.ts +++ b/src/test/javascript/spec/springboot/domain/client/AngularService.fixture.ts @@ -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(), }); diff --git a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts index 5c63a9d6819..eefa8703b00 100644 --- a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts @@ -7,6 +7,7 @@ describe('ServiceProjection', () => { expect(toServiceProjection(Service.ANGULAR)).toEqual('angular'); expect(toServiceProjection(Service.ANGULAR_WITH_JWT)).toEqual('angular-with-jwt'); expect(toServiceProjection(Service.ANGULAR_OAUTH2)).toEqual('angular-oauth2'); + expect(toServiceProjection(Service.ANGULAR_HEALTH)).toEqual('angular-health'); expect(toServiceProjection(Service.CONSUL)).toEqual('consul'); expect(toServiceProjection(Service.DEV_TOOLS)).toEqual('dev-tools'); expect(toServiceProjection(Service.DOWNLOAD)).toEqual('download'); @@ -71,6 +72,7 @@ describe('ServiceProjection', () => { expect(fromServiceProjection('angular')).toEqual(Service.ANGULAR); expect(fromServiceProjection('angular-with-jwt')).toEqual(Service.ANGULAR_WITH_JWT); expect(fromServiceProjection('angular-oauth2')).toEqual(Service.ANGULAR_OAUTH2); + expect(fromServiceProjection('angular-health')).toEqual(Service.ANGULAR_HEALTH); expect(fromServiceProjection('consul')).toEqual(Service.CONSUL); expect(fromServiceProjection('dev-tools')).toEqual(Service.DEV_TOOLS); expect(fromServiceProjection('dockerfile')).toEqual(Service.DOCKERFILE); diff --git a/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts index 7f2357f3eac..b46c51de94e 100644 --- a/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts @@ -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'); + }); }); diff --git a/src/test/javascript/spec/springboot/secondary/client/AngularRepository.spec.ts b/src/test/javascript/spec/springboot/secondary/client/AngularRepository.spec.ts index a1235f1d0ac..82728d266e0 100644 --- a/src/test/javascript/spec/springboot/secondary/client/AngularRepository.spec.ts +++ b/src/test/javascript/spec/springboot/secondary/client/AngularRepository.spec.ts @@ -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(expectedRestProject); + const [projectFolder] = projectHistoryService.get.getCall(0).args; + expect(projectFolder).toBe(PROJECT_FOLDER); + }); });