MM-54514 fix for invite_id being updated on all changes (#24674)

* fix for invite_id being updated on all changes

* lint fixes

* update webapp unit tests

* change fix to webapp

* lint fixes

* Update teams.ts

* update tests

* revert package-lock.json

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Scott Bishel
2023-10-24 08:49:19 -06:00
коммит произвёл GitHub
родитель 6125b0ca7f
Коммит 86812b9b9e
4 изменённых файлов: 83 добавлений и 27 удалений

Просмотреть файл

@@ -126,7 +126,10 @@ describe('components/TeamSettings', () => {
wrapper.instance().handleAllowedDomainsSubmit();
expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
expect(actions.patchTeam).toHaveBeenCalledWith({
allowed_domains: '',
id: props.team?.id,
});
});
test('should call actions.patchTeam on handleNameSubmit', () => {
@@ -141,7 +144,10 @@ describe('components/TeamSettings', () => {
wrapper.instance().handleNameSubmit();
expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
expect(actions.patchTeam).toHaveBeenCalledWith({
display_name: props.team?.display_name,
id: props.team?.id,
});
});
test('should call actions.patchTeam on handleInviteIdSubmit', () => {
@@ -173,7 +179,10 @@ describe('components/TeamSettings', () => {
}
expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
expect(actions.patchTeam).toHaveBeenCalledWith({
description: newDescription,
id: props.team?.id,
});
});
test('should match snapshot when team is group constrained', () => {

Просмотреть файл

@@ -106,9 +106,10 @@ export class GeneralTab extends React.PureComponent<Props, State> {
handleAllowedDomainsSubmit = async () => {
const state = {serverError: '', clientError: ''};
const data = {...this.props.team};
data.allowed_domains = this.state.allowed_domains;
const data = {
id: this.props.team?.id,
allowed_domains: this.state.allowed_domains,
};
const {error} = await this.props.actions.patchTeam(data);
if (error) {
@@ -151,9 +152,10 @@ export class GeneralTab extends React.PureComponent<Props, State> {
return;
}
const data = {...this.props.team};
data.display_name = this.state.name;
const data = {
id: this.props.team?.id,
display_name: this.state.name,
};
const {error} = await this.props.actions.patchTeam(data);
if (error) {
@@ -198,9 +200,10 @@ export class GeneralTab extends React.PureComponent<Props, State> {
return;
}
const data = {...this.props.team};
data.description = this.state.description;
const data = {
id: this.props.team?.id,
description: this.state.description,
};
const {error} = await this.props.actions.patchTeam(data);
if (error) {

Просмотреть файл

@@ -737,38 +737,77 @@ describe('Actions.Teams', () => {
});
it('setTeamIcon', async () => {
const team = {id: 'teamId', invite_id: ''};
store = configureStore({
entities: {
teams: {
teams: {
[team!.id]: {...team},
},
},
},
});
TestHelper.mockLogin();
store.dispatch({
type: UserTypes.LOGIN_SUCCESS,
});
await loadMe()(store.dispatch, store.getState);
const team = TestHelper.basicTeam;
let state = store.getState();
expect(state.entities.teams.teams[team!.id].invite_id).toEqual('');
const imageData = fs.createReadStream('src/packages/mattermost-redux/test/assets/images/test.png');
nock(Client4.getTeamRoute(team!.id)).
post('/image').
reply(200, OK_RESPONSE);
nock(Client4.getTeamRoute(team!.id)).
get('').
reply(200, {...team, invite_id: 'inviteId'});
const {data} = await Actions.setTeamIcon(team!.id, imageData as any)(store.dispatch, store.getState) as ActionResult;
expect(data).toEqual(OK_RESPONSE);
state = store.getState();
expect(state.entities.teams.teams[team!.id].invite_id).toEqual('inviteId');
});
it('removeTeamIcon', async () => {
const team = {id: 'teamId', invite_id: ''};
store = configureStore({
entities: {
teams: {
teams: {
[team!.id]: {...team},
},
},
},
});
TestHelper.mockLogin();
store.dispatch({
type: UserTypes.LOGIN_SUCCESS,
});
await loadMe()(store.dispatch, store.getState);
const team = TestHelper.basicTeam;
let state = store.getState();
expect(state.entities.teams.teams[team!.id].invite_id).toEqual('');
nock(Client4.getTeamRoute(team!.id)).
delete('/image').
reply(200, OK_RESPONSE);
nock(Client4.getTeamRoute(team!.id)).
get('').
reply(200, {...team, invite_id: 'inviteId'});
const {data} = await Actions.removeTeamIcon(team!.id)(store.dispatch, store.getState) as ActionResult;
expect(data).toEqual(OK_RESPONSE);
state = store.getState();
expect(state.entities.teams.teams[team!.id].invite_id).toEqual('inviteId');
});
it('updateTeamScheme', async () => {

Просмотреть файл

@@ -737,22 +737,27 @@ export function joinTeam(inviteId: string, teamId: string): ActionFunc {
}
export function setTeamIcon(teamId: string, imageData: File): ActionFunc {
return bindClientFunc({
clientFunc: Client4.setTeamIcon,
params: [
teamId,
imageData,
],
});
return async (dispatch: DispatchFunc) => {
await Client4.setTeamIcon(teamId, imageData);
const team = await Client4.getTeam(teamId);
dispatch({
type: TeamTypes.PATCHED_TEAM,
data: team,
});
return {data: {status: 'OK'}};
};
}
export function removeTeamIcon(teamId: string): ActionFunc {
return bindClientFunc({
clientFunc: Client4.removeTeamIcon,
params: [
teamId,
],
});
return async (dispatch: DispatchFunc) => {
await Client4.removeTeamIcon(teamId);
const team = await Client4.getTeam(teamId);
dispatch({
type: TeamTypes.PATCHED_TEAM,
data: team,
});
return {data: {status: 'OK'}};
};
}
export function updateTeamScheme(teamId: string, schemeId: string): ActionFunc {