Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(project): add new endpoint #830

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/resources/Projects/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BaseProjectModel,
ProjectResourceType,
ListAssociatedProjectsModel,
UpdatedProjectResourceAssociationsModel,
} from './ProjectInterfaces.js';

export default class Project extends Resource {
Expand Down Expand Up @@ -109,4 +110,21 @@ export default class Project extends Resource {
resourceIds,
);
}

/**
* Modifies project-resource associations and returns a list of updated projects.
*
* @param {ProjectResourceType} resourceType
* @param {UpdatedProjectResourceAssociationsModel} updatedProjectResourceAssociation
* @returns {Promise<ProjectModel[]>} Returns a list of updated projects.
*/
updateProjectResourceAssociation(
resourceType: ProjectResourceType,
updatedProjectResourceAssociation: UpdatedProjectResourceAssociationsModel,
): Promise<ProjectModel[]> {
return this.api.put<ProjectModel[]>(
this.buildPath(`${Project.baseUrl}/resources/modify/${resourceType}`),
updatedProjectResourceAssociation,
);
}
}
22 changes: 22 additions & 0 deletions src/resources/Projects/ProjectInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,25 @@ export interface ListAssociatedProjectsModel {
*/
projectIds: string[];
}

export interface UpdatedProjectAssociationsModel {
/**
* IDs of projects that are to be updated
*/
projectIds: string[];
/**
* IDs of resources whose association with the precised project IDs is to be updated
*/
resourceIds: string[];
}

export interface UpdatedProjectResourceAssociationsModel {
/**
* Project-resource associations to be added
*/
additions: UpdatedProjectAssociationsModel[];
/**
* Project-resource associations to be removed
*/
removals: UpdatedProjectAssociationsModel[];
}
27 changes: 26 additions & 1 deletion src/resources/Projects/tests/Project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import API from '../../../APICore.js';
import Project from '../Project.js';
import {BaseProjectModel, ProjectModel, ProjectType} from '../ProjectInterfaces.js';
import {
BaseProjectModel,
ProjectModel,
ProjectType,
UpdatedProjectResourceAssociationsModel,
} from '../ProjectInterfaces.js';

jest.mock('../../../APICore.js');

Expand Down Expand Up @@ -131,4 +136,24 @@ describe('Project', () => {
]);
});
});

describe('updateProjectResourceAssociation', () => {
it('should make a PUT call to the correct Project URL', () => {
const randomProjectResourceAssociation: UpdatedProjectResourceAssociationsModel = {
additions: [
{
projectIds: ['random-project-id'],
resourceIds: ['random-source-id'],
},
],
removals: [],
};
project.updateProjectResourceAssociation('SOURCE', randomProjectResourceAssociation);
expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(
`${Project.baseUrl}/resources/modify/SOURCE`,
randomProjectResourceAssociation,
);
});
});
});