Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Aug 29, 2024
1 parent d920b2a commit 842ec8f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ API.v1.addRoute(
async get() {
const { offset, count } = await getPaginationItems(this.queryParams);
const { sort } = await this.parseJsonQuery();
const { teamId, filter } = this.queryParams;
const { filter } = this.queryParams;

const team = await getTeamByIdOrName({ teamId });
const team = await getTeamByIdOrName(this.queryParams);
if (!team) {
return API.v1.notFound();
}
Expand Down
19 changes: 14 additions & 5 deletions apps/meteor/tests/data/teams.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import type { ITeam, TEAM_TYPE } from '@rocket.chat/core-typings';

import { api, request } from './api-data';

export const createTeam = async (credentials: Record<string, any>, teamName: string, type: TEAM_TYPE): Promise<ITeam> => {
const response = await request.post(api('teams.create')).set(credentials).send({
name: teamName,
type,
});
export const createTeam = async (
credentials: Record<string, any>,
teamName: string,
type: TEAM_TYPE,
members?: string[],
): Promise<ITeam> => {
const response = await request
.post(api('teams.create'))
.set(credentials)
.send({
name: teamName,
type,
...(members && { members }),
});

return response.body.team;
};
Expand Down
35 changes: 24 additions & 11 deletions apps/meteor/tests/end-to-end/api/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2237,16 +2237,8 @@ describe('[Teams]', () => {
testUser = await createUser();
testUserCredentials = await login(testUser.username, password);

testTeam = (
await request
.post(api('teams.create'))
.set(credentials)
.send({
name: teamName,
type: 0,
members: [testUser.username],
})
).body.team;
const members = testUser.username ? [testUser.username] : [];
testTeam = await createTeam(credentials, teamName, 0, members);
});

before('make user owner', async () => {
Expand Down Expand Up @@ -2330,6 +2322,7 @@ describe('[Teams]', () => {
deleteRoom({ type: 'c', roomId: discussionOnPublicRoom._id }),
deleteRoom({ type: 'c', roomId: discussionOnMainRoom._id }),
deleteTeam(credentials, teamName),
deleteUser({ _id: testUser._id }),
]);
});

Expand All @@ -2345,6 +2338,26 @@ describe('[Teams]', () => {
await request.get(api('teams.listRoomsAndDiscussions')).set(credentials).query({ teamId: 'invalid' }).expect(404);
});

it('should fail if teamId is empty', async () => {
await request.get(api('teams.listRoomsAndDiscussions')).set(credentials).query({ teamId: '' }).expect(404);
});

it('should fail if both properties are passed', async () => {
await request
.get(api('teams.listRoomsAndDiscussions'))
.set(credentials)
.query({ teamId: testTeam._id, teamName: testTeam.name })
.expect(400);
});

it('should fail if teamName is empty', async () => {
await request.get(api('teams.listRoomsAndDiscussions')).set(credentials).query({ teamName: '' }).expect(404);
});

it('should fail if teamName is invalid', async () => {
await request.get(api('teams.listRoomsAndDiscussions')).set(credentials).query({ teamName: 'invalid' }).expect(404);
});

it('should return a list of valid rooms for user', async () => {
const res = await request.get(api('teams.listRoomsAndDiscussions')).query({ teamId: testTeam._id }).set(credentials).expect(200);

Expand Down Expand Up @@ -2380,7 +2393,7 @@ describe('[Teams]', () => {
it('should return a valid list of rooms for non admin member too', async () => {
const res = await request
.get(api('teams.listRoomsAndDiscussions'))
.query({ teamId: testTeam._id })
.query({ teamName: testTeam.name })
.set(testUserCredentials)
.expect(200);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import type { ITeam } from '@rocket.chat/core-typings';
import type { PaginatedRequest } from '../../helpers/PaginatedRequest';
import { ajv } from '../Ajv';

export type TeamsListRoomsAndDiscussionsProps = PaginatedRequest<{
teamId: ITeam['_id'];
filter?: string;
}>;
export type TeamsListRoomsAndDiscussionsProps =
| PaginatedRequest<{
teamId: ITeam['_id'];
filter?: string;
}>
| PaginatedRequest<{ teamName: ITeam['name']; filter?: string }>;

const TeamsListRoomsAndDiscussionsPropsSchema = {
type: 'object',
properties: {
teamId: { type: 'string' },
teamName: { type: 'string' },
filter: { type: 'string' },
offset: { type: 'number' },
count: { type: 'number' },
sort: { type: 'string' },
},
required: ['teamId'],
additionalProperties: false,
oneOf: [{ required: ['teamId'] }, { required: ['teamName'] }],
};

export const isTeamsListRoomsAndDiscussionsProps = ajv.compile<TeamsListRoomsAndDiscussionsProps>(TeamsListRoomsAndDiscussionsPropsSchema);

0 comments on commit 842ec8f

Please sign in to comment.