Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
marioneyraud committed Jun 20, 2022
1 parent fa04180 commit c54b9ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/webapp/app/springboot/secondary/SetupRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { SetupService } from '@/springboot/domain/SetupService';
import { AxiosHttp } from '@/http/AxiosHttp';
import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService';
import { RestProject, toRestProject } from '@/springboot/secondary/RestProject';
import { Project } from '@/springboot/domain/Project';

export default class SetupRepository implements SetupService {
constructor(private axiosHttp: AxiosHttp, private projectHistoryService: ProjectHistoryService) {}
private async postAndGetHistory(url: string, restProject: RestProject): Promise<void> {
await this.axiosHttp.post(url, restProject).then(() => this.projectHistoryService.get(restProject.folder));
}
async addGithubActions(project: Project): Promise<void> {
await this.postAndGetHistory('api/developer-tools/github-actions', toRestProject(project));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { stubProjectHistoryService } from '../../common/domain/ProjectHistoryService.fixture';
import { stubAxiosHttp } from '../../http/AxiosHttpStub';
import { Project } from '../../../../../main/webapp/app/springboot/domain/Project';
import { createProject } from '../domain/Project.fixture';
import { RestProject, toRestProject } from '../../../../../main/webapp/app/springboot/secondary/RestProject';
import SetupRepository from '../../../../../main/webapp/app/springboot/secondary/SetupRepository';

const PROJECT_FOLDER = 'folder/path';

describe('SetupRepository', () => {
it('should add Github actions', async () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
axiosHttpStub.post.resolves();
const setupRepository = new SetupRepository(axiosHttpStub, projectHistoryService);
const project: Project = createProject({ folder: PROJECT_FOLDER });

await setupRepository.addGithubActions(project);

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('api/developer-tools/github-actions');
expect(payload).toEqual<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});
});

0 comments on commit c54b9ab

Please sign in to comment.