Skip to content

Commit

Permalink
Retrieve commands history from API
Browse files Browse the repository at this point in the history
  • Loading branch information
Franceq34 authored and Quentin France committed Mar 14, 2022
1 parent 6466df0 commit bdf63c9
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/main/webapp/app/common/domain/History.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Service } from '@/common/domain/Service';

export interface History {
services: Service[];
}
6 changes: 6 additions & 0 deletions src/main/webapp/app/common/domain/ProjectHistoryService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Folder } from '@/springboot/domain/Folder';
import { History } from '@/common/domain/History';

export interface ProjectHistoryService {
get(folder: Folder): Promise<History>;
}
12 changes: 12 additions & 0 deletions src/main/webapp/app/common/domain/Service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum Service {
INITIALIZATION = 'INITIALIZATION',
MAVEN = 'MAVEN',
JAVA_BASE = 'JAVA_BASE',
SPRINGBOOT = 'SPRINGBOOT',
SPRINGBOOT_MVC_WITH_TOMCAT = 'SPRINGBOOT_MVC_WITH_TOMCAT',
ANGULAR = 'ANGULAR',
REACT = 'REACT',
VUE = 'VUE',
FRONTEND_MAVEN_PLUGIN = 'FRONTEND_MAVEN_PLUGIN',
UNKNOWN = 'UNKNOWN',
}
13 changes: 13 additions & 0 deletions src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Folder } from '@/springboot/domain/Folder';
import { RestHistory, toHistory } from '@/common/secondary/RestHistory';
import { History } from '@/common/domain/History';
import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService';
import { AxiosHttp } from '@/http/AxiosHttp';

export default class ProjectHistoryRepository implements ProjectHistoryService {
constructor(private axiosHttp: AxiosHttp) {}

async get(folder: Folder): Promise<History> {
return this.axiosHttp.get<RestHistory>(`api/projects/history?folder=${folder}`).then(response => toHistory(response.data));
}
}
10 changes: 10 additions & 0 deletions src/main/webapp/app/common/secondary/RestHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RestServiceId, toService } from '@/common/secondary/RestServiceId';
import { History } from '@/common/domain/History';

export interface RestHistory {
serviceIds: RestServiceId[];
}

export const toHistory = (restHistory: RestHistory): History => ({
services: restHistory.serviceIds.map(toService),
});
28 changes: 28 additions & 0 deletions src/main/webapp/app/common/secondary/RestServiceId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Service } from '@/common/domain/Service';

export type RestServiceId = string;

export const toService = (restServiceId: RestServiceId): Service => {
switch (restServiceId) {
case 'init':
return Service.INITIALIZATION;
case 'maven':
return Service.MAVEN;
case 'java-base':
return Service.JAVA_BASE;
case 'springboot':
return Service.SPRINGBOOT;
case 'springboot-tomcat':
return Service.SPRINGBOOT_MVC_WITH_TOMCAT;
case 'angular':
return Service.ANGULAR;
case 'react':
return Service.REACT;
case 'vue':
return Service.VUE;
case 'frontend-maven-plugin':
return Service.FRONTEND_MAVEN_PLUGIN;
default:
return Service.UNKNOWN;
}
};
6 changes: 3 additions & 3 deletions src/main/webapp/app/springboot/secondary/ProjectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export default class ProjectRepository implements ProjectService {

async addJavaBase(project: Project): Promise<void> {
const restProject: RestProject = toRestProject(project);
await this.axiosHttp.post('/api/servers/java/base', restProject);
await this.axiosHttp.post('api/servers/java/base', restProject);
}

async addSpringBoot(project: Project): Promise<void> {
const restProject: RestProject = toRestProject(project);
await this.axiosHttp.post('/api/servers/spring-boot', restProject);
await this.axiosHttp.post('api/servers/spring-boot', restProject);
}

async addSpringBootMvcTomcat(project: Project): Promise<void> {
const restProject: RestProject = toRestProject(project);
await this.axiosHttp.post('/api/servers/spring-boot/mvc/web/tomcat', restProject);
await this.axiosHttp.post('api/servers/spring-boot/mvc/web/tomcat', restProject);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sinon, { SinonStub } from 'sinon';
import { ProjectHistoryService } from '../../../../../main/webapp/app/common/domain/ProjectHistoryService';

export interface ProjectHistoryServiceFixture extends ProjectHistoryService {
get: SinonStub;
}

export const stubProjectService = (): ProjectHistoryServiceFixture => ({
get: sinon.stub(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { stubAxiosHttp } from '../../http/AxiosHttpStub';
import { createRestHistory } from './RestHistory.fixture';
import ProjectHistoryRepository from '@/common/secondary/ProjectHistoryRepository';
import { History } from '@/common/domain/History';
import { Service } from '@/common/domain/Service';

describe('ProjectRepository', () => {
it('should get project history', async () => {
const axiosHttpStub = stubAxiosHttp();
axiosHttpStub.get.resolves({ data: createRestHistory() });
const projectHistoryRepository = new ProjectHistoryRepository(axiosHttpStub);

const history: History = await projectHistoryRepository.get('folder/path');

const [uri] = axiosHttpStub.get.getCall(0).args;
expect(uri).toBe('api/projects/history?folder=folder/path');
expect(history).toEqual<History>({
services: [Service.INITIALIZATION, Service.JAVA_BASE, Service.MAVEN],
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { RestHistory } from '../../../../../main/webapp/app/common/secondary/RestHistory';

export const createRestHistory = (restHistory?: Partial<RestHistory>): RestHistory => ({
serviceIds: ['init', 'java-base', 'maven'],
...restHistory,
});
14 changes: 14 additions & 0 deletions src/test/javascript/spec/common/secondary/RestHistory.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { RestHistory, toHistory } from '../../../../../main/webapp/app/common/secondary/RestHistory';
import { History } from '../../../../../main/webapp/app/common/domain/History';
import { toService } from '../../../../../main/webapp/app/common/secondary/RestServiceId';
import { createRestHistory } from './RestHistory.fixture';

describe('RestHistory', () => {
it('should convert to History', () => {
const restHistory: RestHistory = createRestHistory();

expect(toHistory(restHistory)).toEqual<History>({
services: restHistory.serviceIds.map(toService),
});
});
});
17 changes: 17 additions & 0 deletions src/test/javascript/spec/common/secondary/RestServiceId.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Service } from '../../../../../main/webapp/app/common/domain/Service';
import { toService } from '../../../../../main/webapp/app/common/secondary/RestServiceId';

describe('RestServiceId', () => {
it('should convert to Service', () => {
expect(toService('init')).toEqual<Service>(Service.INITIALIZATION);
expect(toService('maven')).toEqual<Service>(Service.MAVEN);
expect(toService('java-base')).toEqual<Service>(Service.JAVA_BASE);
expect(toService('springboot')).toEqual<Service>(Service.SPRINGBOOT);
expect(toService('springboot-tomcat')).toEqual<Service>(Service.SPRINGBOOT_MVC_WITH_TOMCAT);
expect(toService('angular')).toEqual<Service>(Service.ANGULAR);
expect(toService('react')).toEqual<Service>(Service.REACT);
expect(toService('vue')).toEqual<Service>(Service.VUE);
expect(toService('frontend-maven-plugin')).toEqual<Service>(Service.FRONTEND_MAVEN_PLUGIN);
expect(toService('beer')).toEqual<Service>(Service.UNKNOWN);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ProjectRepository from '@/springboot/secondary/ProjectRepository';
import { stubAxiosHttp } from '../../http/AxiosHttpStub';
import { RestProject, toRestProject } from '@/springboot/secondary/RestProject';
import { createProject } from '../domain/Project.fixture';
import { createRestHistory } from '../../common/secondary/RestHistory.fixture';

describe('ProjectRepository', () => {
it('should init project', () => {
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('ProjectRepository', () => {

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('/api/servers/java/base');
expect(uri).toBe('api/servers/java/base');
expect(payload).toEqual<RestProject>(expectedRestProject);
});

Expand All @@ -57,7 +58,7 @@ describe('ProjectRepository', () => {

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('/api/servers/spring-boot');
expect(uri).toBe('api/servers/spring-boot');
expect(payload).toEqual<RestProject>(expectedRestProject);
});

Expand All @@ -71,7 +72,7 @@ describe('ProjectRepository', () => {

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('/api/servers/spring-boot/mvc/web/tomcat');
expect(uri).toBe('api/servers/spring-boot/mvc/web/tomcat');
expect(payload).toEqual<RestProject>(expectedRestProject);
});

Expand Down

0 comments on commit bdf63c9

Please sign in to comment.