Skip to content

Commit

Permalink
Front part to generate Angular Health
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Jun 15, 2022
1 parent daf5225 commit b1fb2b4
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
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>;
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@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>

Expand Down
Original file line number Diff line number Diff line change
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));
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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(),
});
Original file line number Diff line number Diff line change
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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,21 @@ describe('AngularRepository', () => {
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});

it('should add Oauth2', 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 b1fb2b4

Please sign in to comment.