Skip to content

Commit

Permalink
Merge pull request #1247 from matthieulapatate/SecondaryZip
Browse files Browse the repository at this point in the history
Add secondary for project download
  • Loading branch information
pascalgrimaud authored Apr 11, 2022
2 parents 9ceca29 + f41173a commit 97b479b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/webapp/app/http/AxiosHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class AxiosHttp {
return this.axiosInstance.put<Result>(uri, data);
}

async post<Result, Payload = never>(uri: string, data?: Payload): Promise<AxiosResponse<Result>> {
return this.axiosInstance.post<Result>(uri, data);
async post<Result, Payload = never>(uri: string, data?: Payload, config?: AxiosRequestConfig): Promise<AxiosResponse<Result>> {
return this.axiosInstance.post<Result>(uri, data, config);
}

async delete<Result>(uri: string): Promise<AxiosResponse<Result>> {
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/springboot/domain/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface ProjectService {
addMaven(project: Project): Promise<void>;
addFrontendMavenPlugin(project: Project): Promise<void>;
addJavaBase(project: Project): Promise<void>;
download(project: Project): Promise<BlobPart>;
}
12 changes: 12 additions & 0 deletions src/main/webapp/app/springboot/secondary/ProjectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ export default class ProjectRepository implements ProjectService {
const restProject: RestProject = toRestProject(project);
await this.axiosHttp.post('api/servers/java/base', restProject);
}

async download(project: Project): Promise<BlobPart> {
const restProject: RestProject = toRestProject(project);
return this.axiosHttp
.post<BlobPart, RestProject>('api/projects/download', restProject, {
responseType: 'blob',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
})
.then(response => response.data);
}
}
9 changes: 9 additions & 0 deletions src/test/javascript/spec/springboot/domain/Project.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Project } from '@/springboot/domain/Project';
import ProjectRepository from '@/springboot/secondary/ProjectRepository';
import { stubAxiosHttp } from '../../http/AxiosHttpStub';

export const createProject = (project?: Partial<Project>): Project => ({
folder: 'folder/path',
Expand All @@ -8,3 +10,10 @@ export const createProject = (project?: Partial<Project>): Project => ({
serverPort: 8080,
...project,
});

export const createStubedProjectRepository = (resolve?: any): [ProjectRepository, any] => {
const axiosHttpStub = stubAxiosHttp();
axiosHttpStub.post.resolves(resolve);
const projectRepository = new ProjectRepository(axiosHttpStub);
return [projectRepository, axiosHttpStub];
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export interface ProjectServiceFixture extends ProjectService {
addMaven: SinonStub;
addFrontendMavenPlugin: SinonStub;
addJavaBase: SinonStub;
download: SinonStub;
}

export const stubProjectService = (): ProjectServiceFixture => ({
init: sinon.stub(),
addMaven: sinon.stub(),
addFrontendMavenPlugin: sinon.stub(),
addJavaBase: sinon.stub(),
download: sinon.stub(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Project } from '@/springboot/domain/Project';
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 { createProject, createStubedProjectRepository } from '../domain/Project.fixture';

describe('ProjectRepository', () => {
it('should init project', () => {
Expand Down Expand Up @@ -60,4 +60,17 @@ describe('ProjectRepository', () => {
expect(uri).toBe('api/developer-tools/frontend-maven-plugin');
expect(payload).toEqual<RestProject>(expectedRestProject);
});

it('should download the project', async () => {
const [projectRepository, axiosHttpStub] = createStubedProjectRepository({ data: [1, 2, 3] });
const project: Project = createProject({ folder: 'folder/path' });
const expectedRestProject: RestProject = toRestProject(project);

const datas = await projectRepository.download(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;

expect(datas).toEqual([1, 2, 3]);
expect(uri).toBe('api/projects/download');
expect(payload).toEqual<RestProject>(expectedRestProject);
});
});

0 comments on commit 97b479b

Please sign in to comment.