Best JavaScript code snippet using qawolf
teams.test.js
Source:teams.test.js
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3import fs from 'fs';4import assert from 'assert';5import nock from 'nock';6import * as Actions from 'mattermost-redux/actions/teams';7import {login} from 'mattermost-redux/actions/users';8import {Client4} from 'mattermost-redux/client';9import {General, RequestStatus} from '../constants';10import {GeneralTypes} from 'mattermost-redux/action_types';11import TestHelper from 'mattermost-redux/test/test_helper';12import configureStore from 'mattermost-redux/test/test_store';13const OK_RESPONSE = {status: 'OK'};14describe('Actions.Teams', () => {15 let store;16 beforeAll(() => {17 TestHelper.initBasic(Client4);18 });19 beforeEach(() => {20 store = configureStore({21 entities: {22 general: {23 config: {24 FeatureFlagCollapsedThreads: 'true',25 CollapsedThreads: 'always_on',26 },27 },28 },29 });30 });31 afterAll(() => {32 TestHelper.tearDown();33 });34 it('selectTeam', async () => {35 await Actions.selectTeam(TestHelper.basicTeam)(store.dispatch, store.getState);36 await TestHelper.wait(100);37 const {currentTeamId} = store.getState().entities.teams;38 assert.ok(currentTeamId);39 assert.equal(currentTeamId, TestHelper.basicTeam.id);40 });41 it('getMyTeams', async () => {42 TestHelper.mockLogin();43 await login(TestHelper.basicUser.email, 'password1')(store.dispatch, store.getState);44 nock(Client4.getBaseRoute()).45 get('/users/me/teams').46 reply(200, [TestHelper.basicTeam]);47 await Actions.getMyTeams()(store.dispatch, store.getState);48 const teamsRequest = store.getState().requests.teams.getMyTeams;49 const {teams} = store.getState().entities.teams;50 if (teamsRequest.status === RequestStatus.FAILURE) {51 throw new Error(JSON.stringify(teamsRequest.error));52 }53 assert.ok(teams);54 assert.ok(teams[TestHelper.basicTeam.id]);55 });56 it('getTeamsForUser', async () => {57 nock(Client4.getBaseRoute()).58 get(`/users/${TestHelper.basicUser.id}/teams`).59 reply(200, [TestHelper.basicTeam]);60 await Actions.getTeamsForUser(TestHelper.basicUser.id)(store.dispatch, store.getState);61 const teamsRequest = store.getState().requests.teams.getTeams;62 const {teams} = store.getState().entities.teams;63 if (teamsRequest.status === RequestStatus.FAILURE) {64 throw new Error(JSON.stringify(teamsRequest.error));65 }66 assert.ok(teams);67 assert.ok(teams[TestHelper.basicTeam.id]);68 });69 it('getTeams', async () => {70 let team = {...TestHelper.fakeTeam(), allow_open_invite: true};71 nock(Client4.getBaseRoute()).72 post('/teams').73 reply(201, {...team, id: TestHelper.generateId()});74 team = await Client4.createTeam(team);75 nock(Client4.getBaseRoute()).76 get('/teams').77 query(true).78 reply(200, [team]);79 await Actions.getTeams()(store.dispatch, store.getState);80 const teamsRequest = store.getState().requests.teams.getTeams;81 const {teams} = store.getState().entities.teams;82 if (teamsRequest.status === RequestStatus.FAILURE) {83 throw new Error(JSON.stringify(teamsRequest.error));84 }85 assert.ok(Object.keys(teams).length > 0);86 });87 it('getTeams with total count', async () => {88 let team = {...TestHelper.fakeTeam(), allow_open_invite: true};89 nock(Client4.getBaseRoute()).90 post('/teams').91 reply(201, {...team, id: TestHelper.generateId()});92 team = await Client4.createTeam(team);93 nock(Client4.getBaseRoute()).94 get('/teams').95 query(true).96 reply(200, {teams: [team], total_count: 43});97 await Actions.getTeams(0, 1, true)(store.dispatch, store.getState);98 const teamsRequest = store.getState().requests.teams.getTeams;99 const {teams, totalCount} = store.getState().entities.teams;100 if (teamsRequest.status === RequestStatus.FAILURE) {101 throw new Error(JSON.stringify(teamsRequest.error));102 }103 assert.ok(Object.keys(teams).length > 0);104 assert.equal(totalCount, 43);105 });106 it('getTeam', async () => {107 nock(Client4.getBaseRoute()).108 post('/teams').109 reply(201, TestHelper.fakeTeamWithId());110 const team = await Client4.createTeam(TestHelper.fakeTeam());111 nock(Client4.getBaseRoute()).112 get(`/teams/${team.id}`).113 reply(200, team);114 await Actions.getTeam(team.id)(store.dispatch, store.getState);115 const state = store.getState();116 const {teams} = state.entities.teams;117 assert.ok(teams);118 assert.ok(teams[team.id]);119 });120 it('getTeamByName', async () => {121 nock(Client4.getBaseRoute()).122 post('/teams').123 reply(201, TestHelper.fakeTeamWithId());124 const team = await Client4.createTeam(TestHelper.fakeTeam());125 nock(Client4.getBaseRoute()).126 get(`/teams/name/${team.name}`).127 reply(200, team);128 await Actions.getTeamByName(team.name)(store.dispatch, store.getState);129 const state = store.getState();130 const {teams} = state.entities.teams;131 assert.ok(teams);132 assert.ok(teams[team.id]);133 });134 it('createTeam', async () => {135 nock(Client4.getBaseRoute()).136 post('/teams').137 reply(201, TestHelper.fakeTeamWithId());138 await Actions.createTeam(139 TestHelper.fakeTeam(),140 )(store.dispatch, store.getState);141 const {teams, myMembers, currentTeamId} = store.getState().entities.teams;142 const teamId = Object.keys(teams)[0];143 assert.strictEqual(Object.keys(teams).length, 1);144 assert.strictEqual(currentTeamId, teamId);145 assert.ok(myMembers[teamId]);146 });147 it('deleteTeam', async () => {148 const secondClient = TestHelper.createClient4();149 nock(Client4.getBaseRoute()).150 post('/users').151 query(true).152 reply(201, TestHelper.fakeUserWithId());153 const user = await TestHelper.basicClient4.createUser(154 TestHelper.fakeUser(),155 null,156 null,157 TestHelper.basicTeam.invite_id,158 );159 nock(Client4.getBaseRoute()).160 post('/users/login').161 reply(200, user);162 await secondClient.login(user.email, 'password1');163 nock(Client4.getBaseRoute()).164 post('/teams').165 reply(201, TestHelper.fakeTeamWithId());166 const secondTeam = await secondClient.createTeam(167 TestHelper.fakeTeam());168 nock(Client4.getBaseRoute()).169 delete(`/teams/${secondTeam.id}`).170 reply(200, OK_RESPONSE);171 await Actions.deleteTeam(172 secondTeam.id,173 )(store.dispatch, store.getState);174 const {teams, myMembers} = store.getState().entities.teams;175 assert.ifError(teams[secondTeam.id]);176 assert.ifError(myMembers[secondTeam.id]);177 });178 it('unarchiveTeam', async () => {179 const secondClient = TestHelper.createClient4();180 nock(Client4.getBaseRoute()).181 post('/users').182 query(true).183 reply(201, TestHelper.fakeUserWithId());184 const user = await TestHelper.basicClient4.createUser(185 TestHelper.fakeUser(),186 null,187 null,188 TestHelper.basicTeam.invite_id,189 );190 nock(Client4.getBaseRoute()).191 post('/users/login').192 reply(200, user);193 await secondClient.login(user.email, 'password1');194 nock(Client4.getBaseRoute()).195 post('/teams').196 reply(201, TestHelper.fakeTeamWithId());197 const secondTeam = await secondClient.createTeam(198 TestHelper.fakeTeam());199 nock(Client4.getBaseRoute()).200 delete(`/teams/${secondTeam.id}`).201 reply(200, OK_RESPONSE);202 await Actions.deleteTeam(203 secondTeam.id,204 )(store.dispatch, store.getState);205 nock(Client4.getBaseRoute()).206 post(`/teams/${secondTeam.id}/restore`).207 reply(200, secondTeam);208 await Actions.unarchiveTeam(209 secondTeam.id,210 )(store.dispatch, store.getState);211 const {teams} = store.getState().entities.teams;212 assert.deepStrictEqual(teams[secondTeam.id], secondTeam);213 });214 it('updateTeam', async () => {215 const displayName = 'The Updated Team';216 const description = 'This is a team created by unit tests';217 const team = {218 ...TestHelper.basicTeam,219 display_name: displayName,220 description,221 };222 nock(Client4.getBaseRoute()).223 put(`/teams/${team.id}`).224 reply(200, team);225 await Actions.updateTeam(team)(store.dispatch, store.getState);226 const {teams} = store.getState().entities.teams;227 const updated = teams[TestHelper.basicTeam.id];228 assert.ok(updated);229 assert.strictEqual(updated.display_name, displayName);230 assert.strictEqual(updated.description, description);231 });232 it('patchTeam', async () => {233 const displayName = 'The Patched Team';234 const description = 'This is a team created by unit tests';235 const team = {236 ...TestHelper.basicTeam,237 display_name: displayName,238 description,239 };240 nock(Client4.getBaseRoute()).241 put(`/teams/${team.id}/patch`).242 reply(200, team);243 await Actions.patchTeam(team)(store.dispatch, store.getState);244 const {teams} = store.getState().entities.teams;245 const patched = teams[TestHelper.basicTeam.id];246 assert.ok(patched);247 assert.strictEqual(patched.display_name, displayName);248 assert.strictEqual(patched.description, description);249 });250 it('regenerateTeamInviteId', async () => {251 const patchedInviteId = TestHelper.generateId();252 const team = TestHelper.basicTeam;253 const patchedTeam = {254 ...team,255 invite_id: patchedInviteId,256 };257 nock(Client4.getBaseRoute()).258 post(`/teams/${team.id}/regenerate_invite_id`).259 reply(200, patchedTeam);260 await Actions.regenerateTeamInviteId(team.id)(store.dispatch, store.getState);261 const {teams} = store.getState().entities.teams;262 const patched = teams[TestHelper.basicTeam.id];263 assert.ok(patched);264 assert.notStrictEqual(patched.invite_id, team.invite_id);265 assert.strictEqual(patched.invite_id, patchedInviteId);266 });267 it('Join Open Team', async () => {268 const client = TestHelper.createClient4();269 nock(Client4.getBaseRoute()).270 post('/users').271 query(true).272 reply(201, TestHelper.fakeUserWithId());273 const user = await client.createUser(274 TestHelper.fakeUser(),275 null,276 null,277 TestHelper.basicTeam.invite_id,278 );279 nock(Client4.getBaseRoute()).280 post('/users/login').281 reply(200, user);282 await client.login(user.email, 'password1');283 nock(Client4.getBaseRoute()).284 post('/teams').285 reply(201, {...TestHelper.fakeTeamWithId(), allow_open_invite: true});286 const team = await client.createTeam({...TestHelper.fakeTeam(), allow_open_invite: true});287 store.dispatch({type: GeneralTypes.RECEIVED_SERVER_VERSION, data: '4.0.0'});288 nock(Client4.getBaseRoute()).289 post('/teams/members/invite').290 query(true).291 reply(201, {user_id: TestHelper.basicUser.id, team_id: team.id});292 nock(Client4.getBaseRoute()).293 get(`/teams/${team.id}`).294 reply(200, team);295 nock(Client4.getUserRoute('me')).296 get('/teams/members').297 reply(200, [{user_id: TestHelper.basicUser.id, roles: 'team_user', team_id: team.id}]);298 nock(Client4.getUserRoute('me')).299 get('/teams/unread').300 query({params: {include_collapsed_threads: true}}).301 reply(200, [{team_id: team.id, msg_count: 0, mention_count: 0}]);302 await Actions.joinTeam(team.invite_id, team.id)(store.dispatch, store.getState);303 const state = store.getState();304 const request = state.requests.teams.joinTeam;305 if (request.status !== RequestStatus.SUCCESS) {306 throw new Error(JSON.stringify(request.error));307 }308 const {teams, myMembers} = state.entities.teams;309 assert.ok(teams[team.id]);310 assert.ok(myMembers[team.id]);311 });312 it('getMyTeamMembers and getMyTeamUnreads', async () => {313 nock(Client4.getUserRoute('me')).314 get('/teams/members').315 reply(200, [{user_id: TestHelper.basicUser.id, roles: 'team_user', team_id: TestHelper.basicTeam.id}]);316 await Actions.getMyTeamMembers()(store.dispatch, store.getState);317 nock(Client4.getUserRoute('me')).318 get('/teams/unread').319 query({params: {include_collapsed_threads: true}}).320 reply(200, [{team_id: TestHelper.basicTeam.id, msg_count: 0, mention_count: 0}]);321 await Actions.getMyTeamUnreads()(store.dispatch, store.getState);322 const members = store.getState().entities.teams.myMembers;323 const member = members[TestHelper.basicTeam.id];324 assert.ok(member);325 assert.ok(Object.prototype.hasOwnProperty.call(member, 'mention_count'));326 });327 it('getTeamMembersForUser', async () => {328 nock(Client4.getUserRoute(TestHelper.basicUser.id)).329 get('/teams/members').330 reply(200, [{user_id: TestHelper.basicUser.id, team_id: TestHelper.basicTeam.id}]);331 await Actions.getTeamMembersForUser(TestHelper.basicUser.id)(store.dispatch, store.getState);332 const membersInTeam = store.getState().entities.teams.membersInTeam;333 assert.ok(membersInTeam);334 assert.ok(membersInTeam[TestHelper.basicTeam.id]);335 assert.ok(membersInTeam[TestHelper.basicTeam.id][TestHelper.basicUser.id]);336 });337 it('getTeamMember', async () => {338 nock(Client4.getBaseRoute()).339 post('/users').340 query(true).341 reply(201, TestHelper.fakeUserWithId());342 const user = await TestHelper.basicClient4.createUser(343 TestHelper.fakeUser(),344 null,345 null,346 TestHelper.basicTeam.invite_id,347 );348 nock(Client4.getBaseRoute()).349 get(`/teams/${TestHelper.basicTeam.id}/members/${user.id}`).350 reply(200, {user_id: user.id, team_id: TestHelper.basicTeam.id});351 await Actions.getTeamMember(TestHelper.basicTeam.id, user.id)(store.dispatch, store.getState);352 const members = store.getState().entities.teams.membersInTeam;353 assert.ok(members[TestHelper.basicTeam.id]);354 assert.ok(members[TestHelper.basicTeam.id][user.id]);355 });356 it('getTeamMembers', async () => {357 nock(Client4.getBaseRoute()).358 post('/users').359 reply(201, TestHelper.fakeUserWithId());360 const user1 = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());361 nock(Client4.getBaseRoute()).362 post('/users').363 reply(201, TestHelper.fakeUserWithId());364 const user2 = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());365 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).366 post('/members').367 reply(201, {user_id: user1.id, team_id: TestHelper.basicTeam.id});368 const {data: member1} = await Actions.addUserToTeam(TestHelper.basicTeam.id, user1.id)(store.dispatch, store.getState);369 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).370 post('/members').371 reply(201, {user_id: user2.id, team_id: TestHelper.basicTeam.id});372 const {data: member2} = await Actions.addUserToTeam(TestHelper.basicTeam.id, user2.id)(store.dispatch, store.getState);373 nock(Client4.getBaseRoute()).374 get(`/teams/${TestHelper.basicTeam.id}/members`).375 query(true).376 reply(200, [member1, member2, TestHelper.basicTeamMember]);377 await Actions.getTeamMembers(TestHelper.basicTeam.id)(store.dispatch, store.getState);378 const membersInTeam = store.getState().entities.teams.membersInTeam;379 assert.ok(membersInTeam[TestHelper.basicTeam.id]);380 assert.ok(membersInTeam[TestHelper.basicTeam.id][TestHelper.basicUser.id]);381 assert.ok(membersInTeam[TestHelper.basicTeam.id][user1.id]);382 assert.ok(membersInTeam[TestHelper.basicTeam.id][user2.id]);383 });384 it('getTeamMembersByIds', async () => {385 nock(Client4.getBaseRoute()).386 post('/users').387 query(true).388 reply(201, TestHelper.fakeUserWithId());389 const user1 = await TestHelper.basicClient4.createUser(390 TestHelper.fakeUser(),391 null,392 null,393 TestHelper.basicTeam.invite_id,394 );395 nock(Client4.getBaseRoute()).396 post('/users').397 query(true).398 reply(201, TestHelper.fakeUserWithId());399 const user2 = await TestHelper.basicClient4.createUser(400 TestHelper.fakeUser(),401 null,402 null,403 TestHelper.basicTeam.invite_id,404 );405 nock(Client4.getBaseRoute()).406 post(`/teams/${TestHelper.basicTeam.id}/members/ids`).407 reply(200, [{user_id: user1.id, team_id: TestHelper.basicTeam.id}, {user_id: user2.id, team_id: TestHelper.basicTeam.id}]);408 await Actions.getTeamMembersByIds(409 TestHelper.basicTeam.id,410 [user1.id, user2.id],411 )(store.dispatch, store.getState);412 const members = store.getState().entities.teams.membersInTeam;413 assert.ok(members[TestHelper.basicTeam.id]);414 assert.ok(members[TestHelper.basicTeam.id][user1.id]);415 assert.ok(members[TestHelper.basicTeam.id][user2.id]);416 });417 it('getTeamStats', async () => {418 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).419 get('/stats').420 reply(200, {team_id: TestHelper.basicTeam.id, total_member_count: 2605, active_member_count: 2571});421 await Actions.getTeamStats(TestHelper.basicTeam.id)(store.dispatch, store.getState);422 const {stats} = store.getState().entities.teams;423 const stat = stats[TestHelper.basicTeam.id];424 assert.ok(stat);425 assert.ok(stat.total_member_count > 1);426 assert.ok(stat.active_member_count > 1);427 });428 it('addUserToTeam', async () => {429 nock(Client4.getBaseRoute()).430 post('/users').431 reply(201, TestHelper.fakeUserWithId());432 const user = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());433 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).434 post('/members').435 reply(201, {user_id: user.id, team_id: TestHelper.basicTeam.id});436 await Actions.addUserToTeam(TestHelper.basicTeam.id, user.id)(store.dispatch, store.getState);437 const members = store.getState().entities.teams.membersInTeam;438 assert.ok(members[TestHelper.basicTeam.id]);439 assert.ok(members[TestHelper.basicTeam.id][user.id]);440 });441 it('addUsersToTeam', async () => {442 nock(Client4.getBaseRoute()).443 post('/users').444 reply(201, TestHelper.fakeUserWithId());445 const user = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());446 nock(Client4.getBaseRoute()).447 post('/users').448 reply(201, TestHelper.fakeUserWithId());449 const user2 = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());450 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).451 post('/members/batch').452 reply(201, [{user_id: user.id, team_id: TestHelper.basicTeam.id}, {user_id: user2.id, team_id: TestHelper.basicTeam.id}]);453 await Actions.addUsersToTeam(TestHelper.basicTeam.id, [user.id, user2.id])(store.dispatch, store.getState);454 const members = store.getState().entities.teams.membersInTeam;455 const profilesInTeam = store.getState().entities.users.profilesInTeam;456 assert.ok(members[TestHelper.basicTeam.id]);457 assert.ok(members[TestHelper.basicTeam.id][user.id]);458 assert.ok(members[TestHelper.basicTeam.id][user2.id]);459 assert.ok(profilesInTeam[TestHelper.basicTeam.id]);460 assert.ok(profilesInTeam[TestHelper.basicTeam.id].has(user.id));461 assert.ok(profilesInTeam[TestHelper.basicTeam.id].has(user2.id));462 });463 describe('removeUserFromTeam', () => {464 const team = {id: 'team'};465 const user = {id: 'user'};466 test('should remove the user from the team', async () => {467 store = configureStore({468 entities: {469 teams: {470 membersInTeam: {471 [team.id]: {472 [user.id]: {},473 },474 },475 },476 users: {477 currentUserId: '',478 profilesInTeam: {479 [team.id]: [user.id],480 },481 profilesNotInTeam: {482 [team.id]: [],483 },484 },485 },486 });487 nock(Client4.getBaseRoute()).488 delete(`/teams/${team.id}/members/${user.id}`).489 reply(200, OK_RESPONSE);490 await store.dispatch(Actions.removeUserFromTeam(team.id, user.id));491 const state = store.getState();492 expect(state.entities.teams.membersInTeam[team.id]).toEqual({});493 expect(state.entities.users.profilesInTeam[team.id]).toEqual(new Set());494 expect(state.entities.users.profilesNotInTeam[team.id]).toEqual(new Set([user.id]));495 });496 test('should leave all channels when leaving a team', async () => {497 const channel1 = {id: 'channel1', team_id: team.id};498 const channel2 = {id: 'channel2', team_id: 'team2'};499 store = configureStore({500 entities: {501 channels: {502 channels: {503 [channel1.id]: channel1,504 [channel2.id]: channel2,505 },506 myMembers: {507 [channel1.id]: {user_id: user.id, channel_id: channel1.id},508 [channel2.id]: {user_id: user.id, channel_id: channel2.id},509 },510 },511 users: {512 currentUserId: user.id,513 },514 },515 });516 nock(Client4.getBaseRoute()).517 delete(`/teams/${team.id}/members/${user.id}`).518 reply(200, OK_RESPONSE);519 await store.dispatch(Actions.removeUserFromTeam(team.id, user.id));520 const state = store.getState();521 expect(state.entities.channels.myMembers[channel1.id]).toBeFalsy();522 expect(state.entities.channels.myMembers[channel2.id]).toBeTruthy();523 });524 test('should clear the current channel when leaving a team', async () => {525 const channel = {id: 'channel'};526 store = configureStore({527 entities: {528 channels: {529 channels: {530 [channel.id]: channel,531 },532 myMembers: {},533 },534 users: {535 currentUserId: user.id,536 },537 },538 });539 nock(Client4.getBaseRoute()).540 delete(`/teams/${team.id}/members/${user.id}`).541 reply(200, OK_RESPONSE);542 await store.dispatch(Actions.removeUserFromTeam(team.id, user.id));543 const state = store.getState();544 expect(state.entities.channels.currentChannelId).toBe('');545 });546 });547 it('updateTeamMemberRoles', async () => {548 nock(Client4.getBaseRoute()).549 post('/users').550 reply(201, TestHelper.fakeUserWithId());551 const user = await TestHelper.basicClient4.createUser(TestHelper.fakeUser());552 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).553 post('/members').554 reply(201, {user_id: user.id, team_id: TestHelper.basicTeam.id});555 await Actions.addUserToTeam(TestHelper.basicTeam.id, user.id)(store.dispatch, store.getState);556 const roles = General.TEAM_USER_ROLE + ' ' + General.TEAM_ADMIN_ROLE;557 nock(Client4.getBaseRoute()).558 put(`/teams/${TestHelper.basicTeam.id}/members/${user.id}/roles`).559 reply(200, {user_id: user.id, team_id: TestHelper.basicTeam.id, roles});560 await Actions.updateTeamMemberRoles(TestHelper.basicTeam.id, user.id, roles)(store.dispatch, store.getState);561 const members = store.getState().entities.teams.membersInTeam;562 assert.ok(members[TestHelper.basicTeam.id]);563 assert.ok(members[TestHelper.basicTeam.id][user.id]);564 assert.ok(members[TestHelper.basicTeam.id][user.id].roles === roles);565 });566 it('sendEmailInvitesToTeam', async () => {567 nock(Client4.getTeamRoute(TestHelper.basicTeam.id)).568 post('/invite/email').569 reply(200, OK_RESPONSE);570 const {data} = await Actions.sendEmailInvitesToTeam(TestHelper.basicTeam.id, ['fakeemail1@example.com', 'fakeemail2@example.com'])(store.dispatch, store.getState);571 assert.deepEqual(data, OK_RESPONSE);572 });573 it('checkIfTeamExists', async () => {574 nock(Client4.getBaseRoute()).575 get(`/teams/name/${TestHelper.basicTeam.name}/exists`).576 reply(200, {exists: true});577 let {data: exists} = await Actions.checkIfTeamExists(TestHelper.basicTeam.name)(store.dispatch, store.getState);578 assert.ok(exists === true);579 nock(Client4.getBaseRoute()).580 get('/teams/name/junk/exists').581 reply(200, {exists: false});582 const {data} = await Actions.checkIfTeamExists('junk')(store.dispatch, store.getState);583 exists = data;584 assert.ok(exists === false);585 });586 it('setTeamIcon', async () => {587 TestHelper.mockLogin();588 await login(TestHelper.basicUser.email, 'password1')(store.dispatch, store.getState);589 const team = TestHelper.basicTeam;590 const imageData = fs.createReadStream('packages/mattermost-redux/test/assets/images/test.png');591 nock(Client4.getTeamRoute(team.id)).592 post('/image').593 reply(200, OK_RESPONSE);594 const {data} = await Actions.setTeamIcon(team.id, imageData)(store.dispatch, store.getState);595 assert.deepEqual(data, OK_RESPONSE);596 });597 it('removeTeamIcon', async () => {598 TestHelper.mockLogin();599 await login(TestHelper.basicUser.email, 'password1')(store.dispatch, store.getState);600 const team = TestHelper.basicTeam;601 nock(Client4.getTeamRoute(team.id)).602 delete('/image').603 reply(200, OK_RESPONSE);604 const {data} = await Actions.removeTeamIcon(team.id)(store.dispatch, store.getState);605 assert.deepEqual(data, OK_RESPONSE);606 });607 it('updateTeamScheme', async () => {608 TestHelper.mockLogin();609 await login(TestHelper.basicUser.email, 'password1')(store.dispatch, store.getState);610 const schemeId = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';611 const {id} = TestHelper.basicTeam;612 nock(Client4.getBaseRoute()).613 put('/teams/' + id + '/scheme').614 reply(200, OK_RESPONSE);615 await Actions.updateTeamScheme(id, schemeId)(store.dispatch, store.getState);616 const state = store.getState();617 const {teams} = state.entities.teams;618 const updated = teams[id];619 assert.ok(updated);620 assert.equal(updated.scheme_id, schemeId);621 });622 it('membersMinusGroupMembers', async () => {623 const teamID = 'tid10000000000000000000000';624 const groupIDs = ['gid10000000000000000000000', 'gid20000000000000000000000'];625 const page = 4;626 const perPage = 63;627 nock(Client4.getBaseRoute()).get(628 `/teams/${teamID}/members_minus_group_members?group_ids=${groupIDs.join(',')}&page=${page}&per_page=${perPage}`).629 reply(200, {users: [], total_count: 0});630 const {error} = await Actions.membersMinusGroupMembers(teamID, groupIDs, page, perPage)(store.dispatch, store.getState);631 assert.equal(error, null);632 });633 it('searchTeams', async () => {634 const userClient = TestHelper.createClient4();635 nock(Client4.getBaseRoute()).636 post('/users').637 query(true).638 reply(201, TestHelper.fakeUserWithId());639 const user = await TestHelper.basicClient4.createUser(640 TestHelper.fakeUser(),641 null,642 null,643 TestHelper.basicTeam.invite_id,644 );645 nock(Client4.getBaseRoute()).646 post('/users/login').647 reply(200, user);648 await userClient.login(user.email, 'password1');649 nock(Client4.getBaseRoute()).650 post('/teams').651 reply(201, TestHelper.fakeTeamWithId());652 const userTeam = await userClient.createTeam(653 TestHelper.fakeTeam(),654 );655 nock(Client4.getBaseRoute()).656 post('/teams/search').657 reply(200, [TestHelper.basicTeam, userTeam]);658 await store.dispatch(Actions.searchTeams('test', {page: 0}));659 const moreRequest = store.getState().requests.teams.getTeams;660 if (moreRequest.status === RequestStatus.FAILURE) {661 throw new Error(JSON.stringify(moreRequest.error));662 }663 nock(Client4.getBaseRoute()).664 post('/teams/search').665 reply(200, {teams: [TestHelper.basicTeam, userTeam], total_count: 2});666 const response = await store.dispatch(Actions.searchTeams('test', {page: '', per_page: true}));667 const paginatedRequest = store.getState().requests.teams.getTeams;668 if (paginatedRequest.status === RequestStatus.FAILURE) {669 throw new Error(JSON.stringify(paginatedRequest.error));670 }671 assert.ok(response.data.teams.length === 2);672 });...
teams.ts
Source:teams.ts
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3import {Client4} from 'mattermost-redux/client';4import {General} from '../constants';5import {ChannelTypes, TeamTypes, UserTypes} from 'mattermost-redux/action_types';6import EventEmitter from 'mattermost-redux/utils/event_emitter';7import {isCompatibleWithJoinViewTeamPermissions} from 'mattermost-redux/selectors/entities/general';8import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';9import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';10import {GetStateFunc, DispatchFunc, ActionFunc, ActionResult, batchActions, Action} from 'mattermost-redux/types/actions';11import {Team, TeamMembership, TeamMemberWithError, GetTeamMembersOpts, TeamsWithCount, TeamSearchOpts} from 'mattermost-redux/types/teams';12import {UserProfile} from 'mattermost-redux/types/users';13import {isCollapsedThreadsEnabled} from '../selectors/entities/preferences';14import {selectChannel} from './channels';15import {logError} from './errors';16import {bindClientFunc, forceLogoutIfNecessary} from './helpers';17import {getProfilesByIds, getStatusesByIds} from './users';18import {loadRolesIfNeeded} from './roles';19async function getProfilesAndStatusesForMembers(userIds: string[], dispatch: DispatchFunc, getState: GetStateFunc) {20 const {21 currentUserId,22 profiles,23 statuses,24 } = getState().entities.users;25 const profilesToLoad: string[] = [];26 const statusesToLoad: string[] = [];27 userIds.forEach((userId) => {28 if (!profiles[userId] && !profilesToLoad.includes(userId) && userId !== currentUserId) {29 profilesToLoad.push(userId);30 }31 if (!statuses[userId] && !statusesToLoad.includes(userId) && userId !== currentUserId) {32 statusesToLoad.push(userId);33 }34 });35 const requests: Array<Promise<ActionResult|ActionResult[]>> = [];36 if (profilesToLoad.length) {37 requests.push(dispatch(getProfilesByIds(profilesToLoad)));38 }39 if (statusesToLoad.length) {40 requests.push(dispatch(getStatusesByIds(statusesToLoad)));41 }42 await Promise.all(requests);43}44export function selectTeam(team: Team | string): ActionFunc {45 return async (dispatch: DispatchFunc) => {46 const teamId = (typeof team === 'string') ? team : team.id;47 dispatch({48 type: TeamTypes.SELECT_TEAM,49 data: teamId,50 });51 return {data: true};52 };53}54export function getMyTeams(): ActionFunc {55 return bindClientFunc({56 clientFunc: Client4.getMyTeams,57 onRequest: TeamTypes.MY_TEAMS_REQUEST,58 onSuccess: [TeamTypes.RECEIVED_TEAMS_LIST, TeamTypes.MY_TEAMS_SUCCESS],59 onFailure: TeamTypes.MY_TEAMS_FAILURE,60 });61}62// The argument skipCurrentTeam is a (not ideal) workaround for CRT mention counts. Unread mentions are stored in the reducer per63// team but we do not track unread mentions for DMs/GMs independently. This results in a bit of funky logic and edge case bugs64// that need workarounds like this. In the future we should fix the root cause with better APIs and redux state.65export function getMyTeamUnreads(collapsedThreads: boolean, skipCurrentTeam = false): ActionFunc {66 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {67 let unreads;68 try {69 unreads = await Client4.getMyTeamUnreads(collapsedThreads);70 } catch (error) {71 forceLogoutIfNecessary(error, dispatch, getState);72 dispatch(logError(error));73 return {error};74 }75 if (skipCurrentTeam) {76 const currentTeamId = getCurrentTeamId(getState());77 if (currentTeamId) {78 const index = unreads.findIndex((member) => member.team_id === currentTeamId);79 if (index >= 0) {80 unreads.splice(index, 1);81 }82 }83 }84 dispatch(85 {86 type: TeamTypes.RECEIVED_MY_TEAM_UNREADS,87 data: unreads,88 },89 );90 return {data: unreads};91 };92}93export function getTeam(teamId: string): ActionFunc {94 return bindClientFunc({95 clientFunc: Client4.getTeam,96 onSuccess: TeamTypes.RECEIVED_TEAM,97 params: [98 teamId,99 ],100 });101}102export function getTeamByName(teamName: string): ActionFunc {103 return bindClientFunc({104 clientFunc: Client4.getTeamByName,105 onSuccess: TeamTypes.RECEIVED_TEAM,106 params: [107 teamName,108 ],109 });110}111export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, includeTotalCount = false, excludePolicyConstrained = false): ActionFunc {112 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {113 let data;114 dispatch({type: TeamTypes.GET_TEAMS_REQUEST, data});115 try {116 data = await Client4.getTeams(page, perPage, includeTotalCount, excludePolicyConstrained) as TeamsWithCount;117 } catch (error) {118 forceLogoutIfNecessary(error, dispatch, getState);119 dispatch({type: TeamTypes.GET_TEAMS_FAILURE, data});120 dispatch(logError(error));121 return {error};122 }123 const actions: Action[] = [124 {125 type: TeamTypes.RECEIVED_TEAMS_LIST,126 data: includeTotalCount ? data.teams : data,127 },128 {129 type: TeamTypes.GET_TEAMS_SUCCESS,130 data,131 },132 ];133 if (includeTotalCount) {134 actions.push({135 type: TeamTypes.RECEIVED_TOTAL_TEAM_COUNT,136 data: data.total_count,137 });138 }139 dispatch(batchActions(actions));140 return {data};141 };142}143export function searchTeams(term: string, opts: TeamSearchOpts = {}): ActionFunc {144 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {145 dispatch({type: TeamTypes.GET_TEAMS_REQUEST, data: null});146 let response;147 try {148 response = await Client4.searchTeams(term, opts);149 } catch (error) {150 forceLogoutIfNecessary(error, dispatch, getState);151 dispatch(batchActions([152 {type: TeamTypes.GET_TEAMS_FAILURE, error},153 logError(error),154 ]));155 return {error};156 }157 // The type of the response is determined by whether or not page/perPage were set158 let teams;159 if (!opts.page || !opts.per_page) {160 teams = response as Team[];161 } else {162 teams = (response as TeamsWithCount).teams;163 }164 dispatch(batchActions([165 {166 type: TeamTypes.RECEIVED_TEAMS_LIST,167 data: teams,168 },169 {170 type: TeamTypes.GET_TEAMS_SUCCESS,171 },172 ]));173 return {data: response};174 };175}176export function createTeam(team: Team): ActionFunc {177 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {178 let created;179 try {180 created = await Client4.createTeam(team);181 } catch (error) {182 forceLogoutIfNecessary(error, dispatch, getState);183 dispatch(logError(error));184 return {error};185 }186 const member = {187 team_id: created.id,188 user_id: getState().entities.users.currentUserId,189 roles: `${General.TEAM_ADMIN_ROLE} ${General.TEAM_USER_ROLE}`,190 delete_at: 0,191 msg_count: 0,192 mention_count: 0,193 };194 dispatch(batchActions([195 {196 type: TeamTypes.CREATED_TEAM,197 data: created,198 },199 {200 type: TeamTypes.RECEIVED_MY_TEAM_MEMBER,201 data: member,202 },203 {204 type: TeamTypes.SELECT_TEAM,205 data: created.id,206 },207 ]));208 dispatch(loadRolesIfNeeded(member.roles.split(' ')));209 return {data: created};210 };211}212export function deleteTeam(teamId: string): ActionFunc {213 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {214 try {215 await Client4.deleteTeam(teamId);216 } catch (error) {217 forceLogoutIfNecessary(error, dispatch, getState);218 dispatch(logError(error));219 return {error};220 }221 const entities = getState().entities;222 const {223 currentTeamId,224 } = entities.teams;225 const actions: Action[] = [];226 if (teamId === currentTeamId) {227 EventEmitter.emit('leave_team');228 actions.push({type: ChannelTypes.SELECT_CHANNEL, data: ''});229 }230 actions.push(231 {232 type: TeamTypes.RECEIVED_TEAM_DELETED,233 data: {id: teamId},234 },235 );236 dispatch(batchActions(actions));237 return {data: true};238 };239}240export function unarchiveTeam(teamId: string): ActionFunc {241 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {242 let team: Team;243 try {244 team = await Client4.unarchiveTeam(teamId);245 } catch (error) {246 forceLogoutIfNecessary(error, dispatch, getState);247 dispatch(logError(error));248 return {error};249 }250 dispatch({251 type: TeamTypes.RECEIVED_TEAM_UNARCHIVED,252 data: team,253 });254 return {data: true};255 };256}257export function updateTeam(team: Team): ActionFunc {258 return bindClientFunc({259 clientFunc: Client4.updateTeam,260 onSuccess: TeamTypes.UPDATED_TEAM,261 params: [262 team,263 ],264 });265}266export function patchTeam(team: Team): ActionFunc {267 return bindClientFunc({268 clientFunc: Client4.patchTeam,269 onSuccess: TeamTypes.PATCHED_TEAM,270 params: [271 team,272 ],273 });274}275export function regenerateTeamInviteId(teamId: string): ActionFunc {276 return bindClientFunc({277 clientFunc: Client4.regenerateTeamInviteId,278 onSuccess: TeamTypes.REGENERATED_TEAM_INVITE_ID,279 params: [280 teamId,281 ],282 });283}284export function getMyTeamMembers(): ActionFunc {285 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {286 const getMyTeamMembersFunc = bindClientFunc({287 clientFunc: Client4.getMyTeamMembers,288 onSuccess: TeamTypes.RECEIVED_MY_TEAM_MEMBERS,289 });290 const teamMembers = (await getMyTeamMembersFunc(dispatch, getState)) as ActionResult;291 if ('data' in teamMembers && teamMembers.data) {292 const roles = new Set<string>();293 for (const teamMember of teamMembers.data) {294 for (const role of teamMember.roles.split(' ')) {295 roles.add(role);296 }297 }298 if (roles.size > 0) {299 dispatch(loadRolesIfNeeded([...roles]));300 }301 }302 return teamMembers;303 };304}305export function getTeamMembers(teamId: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, options: GetTeamMembersOpts): ActionFunc {306 return bindClientFunc({307 clientFunc: Client4.getTeamMembers,308 onRequest: TeamTypes.GET_TEAM_MEMBERS_REQUEST,309 onSuccess: [TeamTypes.RECEIVED_MEMBERS_IN_TEAM, TeamTypes.GET_TEAM_MEMBERS_SUCCESS],310 onFailure: TeamTypes.GET_TEAM_MEMBERS_FAILURE,311 params: [312 teamId,313 page,314 perPage,315 options,316 ],317 });318}319export function getTeamMember(teamId: string, userId: string): ActionFunc {320 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {321 let member;322 try {323 const memberRequest = Client4.getTeamMember(teamId, userId);324 getProfilesAndStatusesForMembers([userId], dispatch, getState);325 member = await memberRequest;326 } catch (error) {327 forceLogoutIfNecessary(error, dispatch, getState);328 dispatch(logError(error));329 return {error};330 }331 dispatch({332 type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM,333 data: [member],334 });335 return {data: member};336 };337}338export function getTeamMembersByIds(teamId: string, userIds: string[]): ActionFunc {339 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {340 let members;341 try {342 const membersRequest = Client4.getTeamMembersByIds(teamId, userIds);343 getProfilesAndStatusesForMembers(userIds, dispatch, getState);344 members = await membersRequest;345 } catch (error) {346 forceLogoutIfNecessary(error, dispatch, getState);347 dispatch(logError(error));348 return {error};349 }350 dispatch({351 type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM,352 data: members,353 });354 return {data: members};355 };356}357export function getTeamsForUser(userId: string): ActionFunc {358 return bindClientFunc({359 clientFunc: Client4.getTeamsForUser,360 onRequest: TeamTypes.GET_TEAMS_REQUEST,361 onSuccess: [TeamTypes.RECEIVED_TEAMS_LIST, TeamTypes.GET_TEAMS_SUCCESS],362 onFailure: TeamTypes.GET_TEAMS_FAILURE,363 params: [364 userId,365 ],366 });367}368export function getTeamMembersForUser(userId: string): ActionFunc {369 return bindClientFunc({370 clientFunc: Client4.getTeamMembersForUser,371 onSuccess: TeamTypes.RECEIVED_TEAM_MEMBERS,372 params: [373 userId,374 ],375 });376}377export function getTeamStats(teamId: string): ActionFunc {378 return bindClientFunc({379 clientFunc: Client4.getTeamStats,380 onSuccess: TeamTypes.RECEIVED_TEAM_STATS,381 params: [382 teamId,383 ],384 });385}386export function addUserToTeamFromInvite(token: string, inviteId: string): ActionFunc {387 return bindClientFunc({388 clientFunc: Client4.addToTeamFromInvite,389 onRequest: TeamTypes.ADD_TO_TEAM_FROM_INVITE_REQUEST,390 onSuccess: TeamTypes.ADD_TO_TEAM_FROM_INVITE_SUCCESS,391 onFailure: TeamTypes.ADD_TO_TEAM_FROM_INVITE_FAILURE,392 params: [393 token,394 inviteId,395 ],396 });397}398export function addUserToTeam(teamId: string, userId: string): ActionFunc {399 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {400 let member;401 try {402 member = await Client4.addToTeam(teamId, userId);403 } catch (error) {404 forceLogoutIfNecessary(error, dispatch, getState);405 dispatch(logError(error));406 return {error};407 }408 dispatch(batchActions([409 {410 type: UserTypes.RECEIVED_PROFILE_IN_TEAM,411 data: {id: teamId, user_id: userId},412 },413 {414 type: TeamTypes.RECEIVED_MEMBER_IN_TEAM,415 data: member,416 },417 ]));418 return {data: member};419 };420}421export function addUsersToTeam(teamId: string, userIds: string[]): ActionFunc {422 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {423 let members;424 try {425 members = await Client4.addUsersToTeam(teamId, userIds);426 } catch (error) {427 forceLogoutIfNecessary(error, dispatch, getState);428 dispatch(logError(error));429 return {error};430 }431 const profiles: Array<Partial<UserProfile>> = [];432 members.forEach((m: TeamMembership) => profiles.push({id: m.user_id}));433 dispatch(batchActions([434 {435 type: UserTypes.RECEIVED_PROFILES_LIST_IN_TEAM,436 data: profiles,437 id: teamId,438 },439 {440 type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM,441 data: members,442 },443 ]));444 return {data: members};445 };446}447export function addUsersToTeamGracefully(teamId: string, userIds: string[]): ActionFunc {448 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {449 let result: TeamMemberWithError[];450 try {451 result = await Client4.addUsersToTeamGracefully(teamId, userIds);452 } catch (error) {453 forceLogoutIfNecessary(error, dispatch, getState);454 dispatch(logError(error));455 return {error};456 }457 const addedMembers = result ? result.filter((m) => !m.error) : [];458 const profiles: Array<Partial<UserProfile>> = addedMembers.map((m) => ({id: m.user_id}));459 const members = addedMembers.map((m) => m.member);460 dispatch(batchActions([461 {462 type: UserTypes.RECEIVED_PROFILES_LIST_IN_TEAM,463 data: profiles,464 id: teamId,465 },466 {467 type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM,468 data: members,469 },470 ]));471 return {data: result};472 };473}474export function removeUserFromTeam(teamId: string, userId: string): ActionFunc {475 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {476 try {477 await Client4.removeFromTeam(teamId, userId);478 } catch (error) {479 forceLogoutIfNecessary(error, dispatch, getState);480 dispatch(logError(error));481 return {error};482 }483 const member = {484 team_id: teamId,485 user_id: userId,486 };487 const actions: Action[] = [488 {489 type: UserTypes.RECEIVED_PROFILE_NOT_IN_TEAM,490 data: {id: teamId, user_id: userId},491 },492 {493 type: TeamTypes.REMOVE_MEMBER_FROM_TEAM,494 data: member,495 },496 ];497 const state = getState();498 const currentUserId = getCurrentUserId(state);499 if (userId === currentUserId) {500 const {channels, myMembers} = state.entities.channels;501 for (const channelMember of Object.values(myMembers)) {502 const channel = channels[channelMember.channel_id];503 if (channel && channel.team_id === teamId) {504 actions.push({505 type: ChannelTypes.LEAVE_CHANNEL,506 data: channel,507 });508 }509 }510 if (teamId === getCurrentTeamId(state)) {511 actions.push(selectChannel(''));512 }513 }514 dispatch(batchActions(actions));515 return {data: true};516 };517}518export function updateTeamMemberRoles(teamId: string, userId: string, roles: string[]): ActionFunc {519 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {520 try {521 await Client4.updateTeamMemberRoles(teamId, userId, roles);522 } catch (error) {523 forceLogoutIfNecessary(error, dispatch, getState);524 dispatch(logError(error));525 return {error};526 }527 const membersInTeam = getState().entities.teams.membersInTeam[teamId];528 if (membersInTeam && membersInTeam[userId]) {529 dispatch({530 type: TeamTypes.RECEIVED_MEMBER_IN_TEAM,531 data: {...membersInTeam[userId], roles},532 });533 }534 return {data: true};535 };536}537export function sendEmailInvitesToTeam(teamId: string, emails: string[]): ActionFunc {538 return bindClientFunc({539 clientFunc: Client4.sendEmailInvitesToTeam,540 params: [541 teamId,542 emails,543 ],544 });545}546export function sendEmailGuestInvitesToChannels(teamId: string, channelIds: string[], emails: string[], message: string): ActionFunc {547 return bindClientFunc({548 clientFunc: Client4.sendEmailGuestInvitesToChannels,549 params: [550 teamId,551 channelIds,552 emails,553 message,554 ],555 });556}557export function sendEmailInvitesToTeamGracefully(teamId: string, emails: string[]): ActionFunc {558 return bindClientFunc({559 clientFunc: Client4.sendEmailInvitesToTeamGracefully,560 params: [561 teamId,562 emails,563 ],564 });565}566export function sendEmailGuestInvitesToChannelsGracefully(teamId: string, channelIds: string[], emails: string[], message: string): ActionFunc {567 return bindClientFunc({568 clientFunc: Client4.sendEmailGuestInvitesToChannelsGracefully,569 params: [570 teamId,571 channelIds,572 emails,573 message,574 ],575 });576}577export function getTeamInviteInfo(inviteId: string): ActionFunc {578 return bindClientFunc({579 clientFunc: Client4.getTeamInviteInfo,580 onRequest: TeamTypes.TEAM_INVITE_INFO_REQUEST,581 onSuccess: TeamTypes.TEAM_INVITE_INFO_SUCCESS,582 onFailure: TeamTypes.TEAM_INVITE_INFO_FAILURE,583 params: [584 inviteId,585 ],586 });587}588export function checkIfTeamExists(teamName: string): ActionFunc {589 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {590 let data;591 try {592 data = await Client4.checkIfTeamExists(teamName);593 } catch (error) {594 forceLogoutIfNecessary(error, dispatch, getState);595 dispatch(logError(error));596 return {error};597 }598 return {data: data.exists};599 };600}601export function joinTeam(inviteId: string, teamId: string): ActionFunc {602 return async (dispatch: DispatchFunc, getState: GetStateFunc) => {603 dispatch({type: TeamTypes.JOIN_TEAM_REQUEST, data: null});604 const state = getState();605 try {606 if (isCompatibleWithJoinViewTeamPermissions(state)) {607 const currentUserId = state.entities.users.currentUserId;608 await Client4.addToTeam(teamId, currentUserId);609 } else {610 await Client4.joinTeam(inviteId);611 }612 } catch (error) {613 forceLogoutIfNecessary(error, dispatch, getState);614 dispatch(batchActions([615 {type: TeamTypes.JOIN_TEAM_FAILURE, error},616 logError(error),617 ]));618 return {error};619 }620 dispatch(getMyTeamUnreads(isCollapsedThreadsEnabled(state)));621 await Promise.all([622 getTeam(teamId)(dispatch, getState),623 getMyTeamMembers()(dispatch, getState),624 ]);625 dispatch({type: TeamTypes.JOIN_TEAM_SUCCESS, data: null});626 return {data: true};627 };628}629export function setTeamIcon(teamId: string, imageData: File): ActionFunc {630 return bindClientFunc({631 clientFunc: Client4.setTeamIcon,632 params: [633 teamId,634 imageData,635 ],636 });637}638export function removeTeamIcon(teamId: string): ActionFunc {639 return bindClientFunc({640 clientFunc: Client4.removeTeamIcon,641 params: [642 teamId,643 ],644 });645}646export function updateTeamScheme(teamId: string, schemeId: string): ActionFunc {647 return bindClientFunc({648 clientFunc: async () => {649 await Client4.updateTeamScheme(teamId, schemeId);650 return {teamId, schemeId};651 },652 onSuccess: TeamTypes.UPDATED_TEAM_SCHEME,653 });654}655export function updateTeamMemberSchemeRoles(656 teamId: string,657 userId: string,658 isSchemeUser: boolean,659 isSchemeAdmin: boolean,660): ActionFunc {661 return bindClientFunc({662 clientFunc: async () => {663 await Client4.updateTeamMemberSchemeRoles(teamId, userId, isSchemeUser, isSchemeAdmin);664 return {teamId, userId, isSchemeUser, isSchemeAdmin};665 },666 onSuccess: TeamTypes.UPDATED_TEAM_MEMBER_SCHEME_ROLES,667 });668}669export function invalidateAllEmailInvites(): ActionFunc {670 return bindClientFunc({671 clientFunc: Client4.invalidateAllEmailInvites,672 });673}674export function membersMinusGroupMembers(teamID: string, groupIDs: string[], page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc {675 return bindClientFunc({676 clientFunc: Client4.teamMembersMinusGroupMembers,677 onSuccess: TeamTypes.RECEIVED_TEAM_MEMBERS_MINUS_GROUP_MEMBERS,678 params: [679 teamID,680 groupIDs,681 page,682 perPage,683 ],684 });685}686export function getInProductNotices(teamId: string, client: string, clientVersion: string): ActionFunc {687 return bindClientFunc({688 clientFunc: Client4.getInProductNotices,689 params: [690 teamId,691 client,692 clientVersion,693 ],694 });695}696export function updateNoticesAsViewed(noticeIds: string[]): ActionFunc {697 return bindClientFunc({698 clientFunc: Client4.updateNoticesAsViewed,699 params: [700 noticeIds,701 ],702 });...
team.js
Source:team.js
1$(document).ready(function(){2 /* CEO */3 $('.blue_ceo').on('mouseover', function(){4 5 $('.team__photo_2').addClass('team__opacity')6 $('.team__photo_3').addClass('team__opacity')7 $('.team__photo_4').addClass('team__opacity')8 $('.team__photo_5').addClass('team__opacity')9 $('.team__photo_6').addClass('team__opacity')10 $('.team__photo_7').addClass('team__opacity')11 $('.team__photo_8').addClass('team__opacity')12 $('.team__photo_9').addClass('team__opacity')13 $('.team__photo_10').addClass('team__opacity')14 $('.team__photo_11').addClass('team__opacity')15 $('.team__photo_12').addClass('team__opacity')16 $('.blue_cto').addClass('team__opacity')17 $('.blue_advisors').addClass('team__opacity')18 $('.blue_developers').addClass('team__opacity')19 $('.blue_pm').addClass('team__opacity')20 $('.blue_design').addClass('team__opacity')21 $('.blue_qa').addClass('team__opacity')22 })23 $('.blue_ceo').on('mouseout', function(){24 25 $('.team__photo_2').removeClass('team__opacity')26 $('.team__photo_3').removeClass('team__opacity')27 $('.team__photo_4').removeClass('team__opacity')28 $('.team__photo_5').removeClass('team__opacity')29 $('.team__photo_6').removeClass('team__opacity')30 $('.team__photo_7').removeClass('team__opacity')31 $('.team__photo_8').removeClass('team__opacity')32 $('.team__photo_9').removeClass('team__opacity')33 $('.team__photo_10').removeClass('team__opacity')34 $('.team__photo_11').removeClass('team__opacity')35 $('.team__photo_12').removeClass('team__opacity')36 $('.blue_cto').removeClass('team__opacity')37 $('.blue_advisors').removeClass('team__opacity')38 $('.blue_developers').removeClass('team__opacity')39 $('.blue_pm').removeClass('team__opacity')40 $('.blue_design').removeClass('team__opacity')41 $('.blue_qa').removeClass('team__opacity')42 })43 /* CEO */44 /* CTO */45 $('.blue_cto').on('mouseover', function(){46 47 $('.team__photo_1').addClass('team__opacity')48 $('.team__photo_3').addClass('team__opacity')49 $('.team__photo_4').addClass('team__opacity')50 $('.team__photo_5').addClass('team__opacity')51 $('.team__photo_6').addClass('team__opacity')52 $('.team__photo_7').addClass('team__opacity')53 $('.team__photo_8').addClass('team__opacity')54 $('.team__photo_9').addClass('team__opacity')55 $('.team__photo_10').addClass('team__opacity')56 $('.team__photo_11').addClass('team__opacity')57 $('.team__photo_12').addClass('team__opacity')58 $('.blue_ceo').addClass('team__opacity')59 $('.blue_advisors').addClass('team__opacity')60 $('.blue_developers').addClass('team__opacity')61 $('.blue_pm').addClass('team__opacity')62 $('.blue_design').addClass('team__opacity')63 $('.blue_qa').addClass('team__opacity')64 })65 $('.blue_cto').on('mouseout', function(){66 67 $('.team__photo_1').removeClass('team__opacity')68 $('.team__photo_3').removeClass('team__opacity')69 $('.team__photo_4').removeClass('team__opacity')70 $('.team__photo_5').removeClass('team__opacity')71 $('.team__photo_6').removeClass('team__opacity')72 $('.team__photo_7').removeClass('team__opacity')73 $('.team__photo_8').removeClass('team__opacity')74 $('.team__photo_9').removeClass('team__opacity')75 $('.team__photo_10').removeClass('team__opacity')76 $('.team__photo_11').removeClass('team__opacity')77 $('.team__photo_12').removeClass('team__opacity')78 $('.blue_ceo').removeClass('team__opacity')79 $('.blue_advisors').removeClass('team__opacity')80 $('.blue_developers').removeClass('team__opacity')81 $('.blue_pm').removeClass('team__opacity')82 $('.blue_design').removeClass('team__opacity')83 $('.blue_qa').removeClass('team__opacity')84 })85 /* CTO */86 /* DEVELOP */87 $('.blue_developers').on('mouseover', function(){88 89 $('.team__photo_1').addClass('team__opacity')90 $('.team__photo_2').addClass('team__opacity')91 $('.team__photo_4').addClass('team__opacity')92 $('.team__photo_7').addClass('team__opacity')93 $('.team__photo_8').addClass('team__opacity')94 $('.team__photo_9').addClass('team__opacity')95 $('.team__photo_10').addClass('team__opacity')96 $('.team__photo_11').addClass('team__opacity')97 $('.team__photo_12').addClass('team__opacity')98 $('.blue_ceo').addClass('team__opacity')99 $('.blue_cto').addClass('team__opacity')100 $('.blue_advisors').addClass('team__opacity')101 $('.blue_pm').addClass('team__opacity')102 $('.blue_design').addClass('team__opacity')103 $('.blue_qa').addClass('team__opacity')104 })105 $('.blue_developers').on('mouseout', function(){106 107 $('.team__photo_1').removeClass('team__opacity')108 $('.team__photo_2').removeClass('team__opacity')109 $('.team__photo_4').removeClass('team__opacity')110 $('.team__photo_7').removeClass('team__opacity')111 $('.team__photo_8').removeClass('team__opacity')112 $('.team__photo_9').removeClass('team__opacity')113 $('.team__photo_10').removeClass('team__opacity')114 $('.team__photo_11').removeClass('team__opacity')115 $('.team__photo_12').removeClass('team__opacity')116 $('.blue_ceo').removeClass('team__opacity')117 $('.blue_cto').removeClass('team__opacity')118 $('.blue_advisors').removeClass('team__opacity')119 $('.blue_pm').removeClass('team__opacity')120 $('.blue_design').removeClass('team__opacity')121 $('.blue_qa').removeClass('team__opacity')122 })123 /* DEVELOP */124 /* ADVISORS */125 $('.blue_advisors').on('mouseover', function(){126 127 $('.team__photo_1').addClass('team__opacity')128 $('.team__photo_2').addClass('team__opacity')129 $('.team__photo_3').addClass('team__opacity')130 $('.team__photo_4').addClass('team__opacity')131 $('.team__photo_5').addClass('team__opacity')132 $('.team__photo_6').addClass('team__opacity')133 $('.team__photo_8').addClass('team__opacity')134 $('.team__photo_9').addClass('team__opacity')135 $('.team__photo_12').addClass('team__opacity')136 $('.blue_ceo').addClass('team__opacity')137 $('.blue_cto').addClass('team__opacity')138 $('.blue_developers').addClass('team__opacity')139 $('.blue_pm').addClass('team__opacity')140 $('.blue_design').addClass('team__opacity')141 $('.blue_qa').addClass('team__opacity')142 })143 $('.blue_advisors').on('mouseout', function(){144 145 $('.team__photo_1').removeClass('team__opacity')146 $('.team__photo_2').removeClass('team__opacity')147 $('.team__photo_3').removeClass('team__opacity')148 $('.team__photo_4').removeClass('team__opacity')149 $('.team__photo_5').removeClass('team__opacity')150 $('.team__photo_6').removeClass('team__opacity')151 $('.team__photo_8').removeClass('team__opacity')152 $('.team__photo_9').removeClass('team__opacity')153 $('.team__photo_12').removeClass('team__opacity')154 $('.blue_ceo').removeClass('team__opacity')155 $('.blue_cto').removeClass('team__opacity')156 $('.blue_developers').removeClass('team__opacity')157 $('.blue_pm').removeClass('team__opacity')158 $('.blue_design').removeClass('team__opacity')159 $('.blue_qa').removeClass('team__opacity')160 })161 /* ADVISORS */162 /* DESIGNERS */163 $('.blue_design').on('mouseover', function(){164 165 $('.team__photo_1').addClass('team__opacity') 166 $('.team__photo_2').addClass('team__opacity')167 $('.team__photo_3').addClass('team__opacity')168 $('.team__photo_4').addClass('team__opacity')169 $('.team__photo_5').addClass('team__opacity')170 $('.team__photo_6').addClass('team__opacity')171 $('.team__photo_7').addClass('team__opacity')172 $('.team__photo_10').addClass('team__opacity')173 $('.team__photo_11').addClass('team__opacity')174 $('.team__photo_12').addClass('team__opacity')175 $('.blue_ceo').addClass('team__opacity')176 $('.blue_cto').addClass('team__opacity')177 $('.blue_advisors').addClass('team__opacity')178 $('.blue_developers').addClass('team__opacity')179 $('.blue_pm').addClass('team__opacity')180 $('.blue_qa').addClass('team__opacity')181 })182 $('.blue_design').on('mouseout', function(){183 184 $('.team__photo_1').removeClass('team__opacity') 185 $('.team__photo_2').removeClass('team__opacity')186 $('.team__photo_3').removeClass('team__opacity')187 $('.team__photo_4').removeClass('team__opacity')188 $('.team__photo_5').removeClass('team__opacity')189 $('.team__photo_6').removeClass('team__opacity')190 $('.team__photo_7').removeClass('team__opacity')191 $('.team__photo_10').removeClass('team__opacity')192 $('.team__photo_11').removeClass('team__opacity')193 $('.team__photo_12').removeClass('team__opacity')194 $('.blue_ceo').removeClass('team__opacity')195 $('.blue_cto').removeClass('team__opacity')196 $('.blue_advisors').removeClass('team__opacity')197 $('.blue_developers').removeClass('team__opacity')198 $('.blue_pm').removeClass('team__opacity')199 $('.blue_qa').removeClass('team__opacity')200 })201 /* DESIGNERS */202 /* PM */203 $('.blue_pm').on('mouseover', function(){204 $('.team__photo_1').addClass('team__opacity')205 $('.team__photo_2').addClass('team__opacity')206 $('.team__photo_3').addClass('team__opacity')207 $('.team__photo_5').addClass('team__opacity')208 $('.team__photo_6').addClass('team__opacity')209 $('.team__photo_7').addClass('team__opacity')210 $('.team__photo_8').addClass('team__opacity')211 $('.team__photo_9').addClass('team__opacity')212 $('.team__photo_10').addClass('team__opacity')213 $('.team__photo_11').addClass('team__opacity')214 $('.team__photo_12').addClass('team__opacity')215 $('.blue_ceo').addClass('team__opacity')216 $('.blue_cto').addClass('team__opacity')217 $('.blue_advisors').addClass('team__opacity')218 $('.blue_developers').addClass('team__opacity')219 $('.blue_design').addClass('team__opacity')220 $('.blue_qa').addClass('team__opacity')221 })222 $('.blue_pm').on('mouseout', function(){223 224 $('.team__photo_1').removeClass('team__opacity')225 $('.team__photo_2').removeClass('team__opacity')226 $('.team__photo_3').removeClass('team__opacity')227 $('.team__photo_5').removeClass('team__opacity')228 $('.team__photo_6').removeClass('team__opacity')229 $('.team__photo_7').removeClass('team__opacity')230 $('.team__photo_8').removeClass('team__opacity')231 $('.team__photo_9').removeClass('team__opacity')232 $('.team__photo_10').removeClass('team__opacity')233 $('.team__photo_11').removeClass('team__opacity')234 $('.team__photo_12').removeClass('team__opacity')235 $('.blue_ceo').removeClass('team__opacity')236 $('.blue_cto').removeClass('team__opacity')237 $('.blue_advisors').removeClass('team__opacity')238 $('.blue_developers').removeClass('team__opacity')239 $('.blue_design').removeClass('team__opacity')240 $('.blue_qa').removeClass('team__opacity')241 })242 /* PM */243 /* QA */244 $('.blue_qa').on('mouseover', function(){245 $('.team__photo_1').addClass('team__opacity')246 $('.team__photo_2').addClass('team__opacity')247 $('.team__photo_3').addClass('team__opacity')248 $('.team__photo_4').addClass('team__opacity')249 $('.team__photo_5').addClass('team__opacity')250 $('.team__photo_6').addClass('team__opacity')251 $('.team__photo_7').addClass('team__opacity')252 $('.team__photo_8').addClass('team__opacity')253 $('.team__photo_9').addClass('team__opacity')254 $('.team__photo_10').addClass('team__opacity')255 $('.team__photo_11').addClass('team__opacity')256 $('.blue_ceo').addClass('team__opacity')257 $('.blue_cto').addClass('team__opacity')258 $('.blue_advisors').addClass('team__opacity')259 $('.blue_developers').addClass('team__opacity')260 $('.blue_pm').addClass('team__opacity')261 $('.blue_design').addClass('team__opacity')262 })263 $('.blue_qa').on('mouseout', function(){264 265 $('.team__photo_1').removeClass('team__opacity')266 $('.team__photo_2').removeClass('team__opacity')267 $('.team__photo_3').removeClass('team__opacity')268 $('.team__photo_4').removeClass('team__opacity')269 $('.team__photo_5').removeClass('team__opacity')270 $('.team__photo_6').removeClass('team__opacity')271 $('.team__photo_7').removeClass('team__opacity')272 $('.team__photo_8').removeClass('team__opacity')273 $('.team__photo_9').removeClass('team__opacity')274 $('.team__photo_10').removeClass('team__opacity')275 $('.team__photo_11').removeClass('team__opacity')276 $('.blue_ceo').removeClass('team__opacity')277 $('.blue_cto').removeClass('team__opacity')278 $('.blue_advisors').removeClass('team__opacity')279 $('.blue_developers').removeClass('team__opacity')280 $('.blue_pm').removeClass('team__opacity')281 $('.blue_design').removeClass('team__opacity')282 })283 /* QA */...
team_utils.test.jsx
Source:team_utils.test.jsx
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3import {General} from 'mattermost-redux/constants';4import * as TeamUtils from 'utils/team_utils';5describe('TeamUtils.filterAndSortTeamsByDisplayName', () => {6 const teamA = {id: 'team_id_a', name: 'team-a', display_name: 'Team A', delete_at: 0};7 const teamB = {id: 'team_id_b', name: 'team-b', display_name: 'Team A', delete_at: 0};8 const teamC = {id: 'team_id_c', name: 'team-c', display_name: 'Team C', delete_at: null};9 const teamD = {id: 'team_id_d', name: 'team-d', display_name: 'Team D'};10 const teamE = {id: 'team_id_e', name: 'team-e', display_name: 'Team E', delete_at: 1};11 const teamF = {id: 'team_id_i', name: 'team-f', display_name: null};12 const teamG = null;13 test('should return correct sorted teams', () => {14 for (const data of [15 {teams: [teamG], result: []},16 {teams: [teamF, teamG], result: []},17 {teams: [teamA, teamB, teamC, teamD, teamE], result: [teamA, teamB, teamC, teamD]},18 {teams: [teamE, teamD, teamC, teamB, teamA], result: [teamA, teamB, teamC, teamD]},19 {teams: [teamA, teamB, teamC, teamD, teamE, teamF, teamG], result: [teamA, teamB, teamC, teamD]},20 {teams: [teamG, teamF, teamE, teamD, teamC, teamB, teamA], result: [teamA, teamB, teamC, teamD]},21 ]) {22 expect(TeamUtils.filterAndSortTeamsByDisplayName(data.teams, General.DEFAULT_LOCALE)).toEqual(data.result);23 }24 });25 test('should return correct sorted teams when teamsOrder is provided', () => {26 const teamsOrder = 'team_id_d,team_id_b,team_id_a,team_id_c';27 for (const data of [28 {teams: [teamG], result: []},29 {teams: [teamF, teamG], result: []},30 {teams: [teamA, teamB, teamC, teamD, teamE], result: [teamD, teamB, teamA, teamC]},31 {teams: [teamE, teamD, teamC, teamB, teamA], result: [teamD, teamB, teamA, teamC]},32 {teams: [teamA, teamB, teamC, teamD, teamE, teamF, teamG], result: [teamD, teamB, teamA, teamC]},33 {teams: [teamG, teamF, teamE, teamD, teamC, teamB, teamA], result: [teamD, teamB, teamA, teamC]},34 ]) {35 expect(TeamUtils.filterAndSortTeamsByDisplayName(data.teams, General.DEFAULT_LOCALE, teamsOrder)).toEqual(data.result);36 }37 });...
Using AI Code Generation
1const { launch, team } = require("qawolf");2const selectors = require("./selectors/test");3describe("test", () => {4 let browser;5 let page;6 beforeAll(async () => {7 browser = await launch();8 });9 afterAll(async () => {10 await browser.close();11 });12 beforeEach(async () => {13 page = await browser.newPage();14 });15 afterEach(async () => {16 await page.close();17 });18 it("test", async () => {19 await team(page, selectors);20 });21});22const qawolf = require("qawolf");23module.exports = {24};25const { launch, team } = require("qawolf");26const selectors = require("./selectors/test");27describe("test", () => {28 let browser;29 let page;30 beforeAll(async () => {31 browser = await launch();32 });33 afterAll(async () => {34 await browser.close();35 });36 beforeEach(async () => {37 page = await browser.newPage();38 });39 afterEach(async () => {40 await page.close();41 });42 it("test", async () => {43 await team(page, selectors);44 });45});46const qawolf = require("qawolf");47module.exports = {48};49const { launch, team } = require("qawolf");50const selectors = require("./selectors/test");51describe("test", () => {52 let browser;53 let page;54 beforeAll(async () => {55 browser = await launch();56 });57 afterAll(async () => {58 await browser.close();59 });
Using AI Code Generation
1const { team } = require("qawolf");2async function main() {3 const browser = await team.launchBrowser();4 const context = await team.launchContext(browser);5 const page = await team.newPage(context);6 await page.click("text=Sign In");7 await page.fill("input[type=text]", "
Using AI Code Generation
1const { team } = require("qawolf");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const team = await team.launch(context);7 const browser = await chromium.launch();8 const context = await browser.newContext();9 const page = await team.page(context);10 await team.close();11})();12const { team } = require("qawolf");13const { chromium } = require("playwright");14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const team = await team.launch(context);18 const browser = await chromium.launch();19 const context = await browser.newContext();20 const page = await team.page(context);21 await team.close();22})();23const { team } = require("qawolf");24const { chromium } = require("playwright");25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const team = await team.launch(context);29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await team.page(context);32 await team.close();33})();34const { team } = require("qawolf");35const { chromium } = require("playwright");36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const team = await team.launch(context);40 const browser = await chromium.launch();
Using AI Code Generation
1const { team } = require("@qawolf/team");2const { create } = require("@qawolf/create");3async function main() {4 const browser = await qawolf.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const page2 = await context.newPage();8 const page3 = await context.newPage();9 const page4 = await context.newPage();10 const page5 = await context.newPage();11 const page6 = await context.newPage();12 const page7 = await context.newPage();13 const page8 = await context.newPage();14 const page9 = await context.newPage();15 const page10 = await context.newPage();16 const page11 = await context.newPage();
Using AI Code Generation
1const { team } = require('qawolf');2const { chromium } = require('playwright');3const team = await team.create();4const browser = await chromium.launch();5const page = await browser.newPage();6const context = await browser.newContext();7const page2 = await context.newPage();8await browser.close();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!