Skip to content

Commit

Permalink
feat: teams api new methods (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ authored Jul 13, 2024
1 parent 7313b03 commit 515a01d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,35 @@ import {
ResponseList,
ResponseObject,
} from '../core';
import { ProjectsGroupsModel } from '../projectsGroups';

//TODO add missing endpoints
export class Teams extends CrowdinApi {
/**
* @param teamId team identifier
* @param options request options
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.teams.projects.permissions.getMany
*/
listTeamProjectPermissions(
teamId: number,
options?: PaginationOptions,
): Promise<ResponseList<TeamsModel.ProjectPermissions>> {
const url = `${this.url}/teams/${teamId}/projects/permissions`;
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param teamId team identifier
* @param request request body
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.teams.projects.permissions.patch
*/
editTeamProjectPermissions(
teamId: number,
request: PatchRequest[],
): Promise<ResponseList<TeamsModel.ProjectPermissions>> {
const url = `${this.url}/teams/${teamId}/projects/permissions`;
return this.patch(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param request request body
Expand Down Expand Up @@ -145,19 +171,25 @@ export class Teams extends CrowdinApi {
}

export namespace TeamsModel {
export interface ProjectPermissions {
id: number;
roles: ProjectRole[];
project: ProjectsGroupsModel.Project | ProjectsGroupsModel.ProjectSettings;
}

export interface AddTeamToProjectRequest {
teamId: number;
managerAccess?: boolean;
developerAccess?: boolean;
roles?: ProjectRole[];
/**
* @deprecated
*/
accessToAllWorkflowSteps?: boolean;
managerAccess?: boolean;
developerAccess?: boolean;
/**
* @deprecated
*/
permissions?: Permissions;
roles?: ProjectRole[];
}

export interface ProjectTeamResources {
Expand Down
65 changes: 65 additions & 0 deletions tests/teams/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,57 @@ describe('Tasks API', () => {
const teamId = 3;
const userId = 4;
const name = 'Test team';
const permissionId = 1213;

const limit = 25;

beforeAll(() => {
scope = nock(api.url)
.get(`/teams/${teamId}/projects/permissions`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: permissionId,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.patch(
`/teams/${teamId}/projects/permissions`,
[
{
op: 'remove',
path: `/${permissionId}`,
},
],
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: [
{
data: {
id: permissionId,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.post(
`/projects/${projectId}/teams`,
{
Expand Down Expand Up @@ -159,6 +205,25 @@ describe('Tasks API', () => {
scope.done();
});

it('List Team Projects Permissions', async () => {
const permissions = await api.listTeamProjectPermissions(teamId);
expect(permissions.data.length).toBe(1);
expect(permissions.data[0].data.id).toBe(permissionId);
expect(permissions.pagination.limit).toBe(limit);
});

it('Permissions Batch Operations', async () => {
const permissions = await api.editTeamProjectPermissions(teamId, [
{
op: 'remove',
path: `/${permissionId}`,
},
]);
expect(permissions.data.length).toBe(1);
expect(permissions.data[0].data.id).toBe(permissionId);
expect(permissions.pagination.limit).toBe(limit);
});

it('Add team to project', async () => {
const teams = await api.addTeamToProject(projectId, {
teamId: teamId,
Expand Down

0 comments on commit 515a01d

Please sign in to comment.