From 7cfc52b5f8f6d64c628c98e204fa284791d1bd73 Mon Sep 17 00:00:00 2001 From: Alice Gong Date: Mon, 3 Jun 2024 15:49:47 -0400 Subject: [PATCH] feat(project): add new endpoint --- src/resources/Projects/Project.ts | 18 +++++++++++++ src/resources/Projects/ProjectInterfaces.ts | 22 ++++++++++++++++ src/resources/Projects/tests/Project.spec.ts | 27 +++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/resources/Projects/Project.ts b/src/resources/Projects/Project.ts index 277720bb4..6df4480ea 100644 --- a/src/resources/Projects/Project.ts +++ b/src/resources/Projects/Project.ts @@ -8,6 +8,7 @@ import { BaseProjectModel, ProjectResourceType, ListAssociatedProjectsModel, + UpdatedProjectResourceAssociationsModel, } from './ProjectInterfaces.js'; export default class Project extends Resource { @@ -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} Returns a list of updated projects. + */ + updateProjectResourceAssociation( + resourceType: ProjectResourceType, + updatedProjectResourceAssociation: UpdatedProjectResourceAssociationsModel, + ): Promise { + return this.api.put( + this.buildPath(`${Project.baseUrl}/resources/modify`, {resourceType}), + updatedProjectResourceAssociation, + ); + } } diff --git a/src/resources/Projects/ProjectInterfaces.ts b/src/resources/Projects/ProjectInterfaces.ts index 85209bfd5..fcd9c330b 100644 --- a/src/resources/Projects/ProjectInterfaces.ts +++ b/src/resources/Projects/ProjectInterfaces.ts @@ -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[]; +} diff --git a/src/resources/Projects/tests/Project.spec.ts b/src/resources/Projects/tests/Project.spec.ts index 741e0802d..40a05de51 100644 --- a/src/resources/Projects/tests/Project.spec.ts +++ b/src/resources/Projects/tests/Project.spec.ts @@ -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'); @@ -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?resourceType=SOURCE`, + randomProjectResourceAssociation, + ); + }); + }); });