Skip to content
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Main features:
- Exclusive Slack App to control and test changes.


- **JavaScript lib**: (https://github.com/switcherapi/switcher-client-master)
- **Java lib**: (https://github.com/switcherapi/switcher-client)
- **JS Client SDK**: (https://github.com/switcherapi/switcher-client-js)
- **Deno Client SDK**: (https://github.com/switcherapi/switcher-client-deno)
- **Java Client SDK**: (https://github.com/switcherapi/switcher-client-java)
- **Switcher Management**: (https://github.com/switcherapi/switcher-management)
- **Switcher Slack App**: (https://github.com/switcherapi/switcher-slack-app)

Expand Down
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import js from "@eslint/js";
import globals from "globals";
import js from '@eslint/js';
import globals from 'globals';

export default [
{
...js.configs.recommended,
files: ["src/**/*.js"]
files: ['src/**/*.js']
},
{
files: ["src/**/*.js"],
files: ['src/**/*.js'],
rules: {
quotes: ['error', 'single'],
semi: ['error', 'always'],
Expand Down
11 changes: 7 additions & 4 deletions src/routers/team.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import { auth } from '../middleware/auth.js';
import { check, query } from 'express-validator';
import { body, check, query } from 'express-validator';
import { ActionTypes, RouterTypes } from '../models/permission.js';
import { validate, verifyInputUpdateParameters } from '../middleware/validators.js';
import { verifyOwnership } from '../helpers/index.js';
Expand Down Expand Up @@ -148,7 +148,8 @@ router.delete('/team/member/invite/remove/:id/:request_id', auth, [
});

router.patch('/team/member/add/:id', auth, [
check('id').isMongoId()
check('id').isMongoId(),
body('member').isMongoId()
], validate, verifyInputUpdateParameters(['member']), async (req, res) => {
try {
const adminMember = await Services.addTeamMember(req.body.member, req.params.id, req.admin);
Expand All @@ -159,7 +160,8 @@ router.patch('/team/member/add/:id', auth, [
});

router.patch('/team/member/remove/:id', auth, [
check('id').isMongoId()
check('id').isMongoId(),
body('member').isMongoId()
], validate, verifyInputUpdateParameters(['member']), async (req, res) => {
try {
const adminMember = await Services.removeTeamMember(req.body.member, req.params.id, req.admin);
Expand All @@ -170,7 +172,8 @@ router.patch('/team/member/remove/:id', auth, [
});

router.patch('/team/permission/remove/:id', auth, [
check('id').isMongoId()
check('id').isMongoId(),
body('permission').isMongoId()
], validate, verifyInputUpdateParameters(['permission']), async (req, res) => {
try {
const team = await Services.removeTeamPermission(req.body.permission, req.params.id, req.admin);
Expand Down
37 changes: 32 additions & 5 deletions tests/team.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ describe('Updating team members tests', () => {
await request(app)
.patch(`/team/member/add/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(400);
.send().expect(422);
});

test('TEAM_SUITE - Should NOT add a team member - Member already joined', async () => {
Expand All @@ -461,12 +461,21 @@ describe('Updating team members tests', () => {
});

test('TEAM_SUITE - Should NOT add a team member - Invalid parameter', async () => {
// Test - invalid parameter key
await request(app)
.patch(`/team/member/add/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
admin: adminAccountId
}).expect(400);
}).expect(422);

// Test - invalid parameter value
await request(app)
.patch(`/team/member/add/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
member: 'INVALID_ID'
}).expect(422);
});

test('TEAM_SUITE - Should NOT remove a team member - Team not found', async () => {
Expand Down Expand Up @@ -509,16 +518,25 @@ describe('Updating team members tests', () => {
await request(app)
.patch(`/team/member/remove/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(400);
.send().expect(422);
});

test('TEAM_SUITE - Should NOT remove a team member - Invalid parameter', async () => {
// Test - invalid parameter key
await request(app)
.patch(`/team/member/remove/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
admin: adminAccountId
}).expect(400);
}).expect(422);

// Test - invalid parameter value
await request(app)
.patch(`/team/member/remove/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
member: 'INVALID_ID'
}).expect(422);
});

test('TEAM_SUITE - Should remove a team member', async () => {
Expand Down Expand Up @@ -650,12 +668,21 @@ describe('Updating team permissions tests', () => {
});

test('TEAM_SUITE - Should NOT remove a permission - Invalid parameter', async () => {
// Test - invalid parameter key
await request(app)
.patch(`/team/permission/remove/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
member: permission1Id
}).expect(400);
}).expect(422);

// Test - invalid parameter value
await request(app)
.patch(`/team/permission/remove/${team1Id}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
permission: 'INVALID_ID'
}).expect(422);
});

test('TEAM_SUITE - Should NOT remove a permission - Permission not found', async () => {
Expand Down