Skip to content

Commit

Permalink
feat(project): add new endpoint (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
agong-coveo authored Jun 4, 2024
1 parent d40c4ff commit 82c82ff
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
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,
);
});
});
});

0 comments on commit 82c82ff

Please sign in to comment.