Skip to content

Commit

Permalink
MM-11880 Have Team Settings modal use the patch endpoint instead of t…
Browse files Browse the repository at this point in the history
…he update endpoint (mattermost#1853)

* Change team settings to use patch instead of update endpoint

* Fix after rebase

* Change team test to use patchTeam

* Fix assertions
  • Loading branch information
mojicaj authored and jwilander committed Oct 15, 2018
1 parent ec24d2f commit fe57d18
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
tests/reports
.DS_Store
mattermost-webapp.iml
.vscode/
4 changes: 2 additions & 2 deletions components/team_general_tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {updateTeam, removeTeamIcon, setTeamIcon} from 'mattermost-redux/actions/teams';
import {patchTeam, removeTeamIcon, setTeamIcon} from 'mattermost-redux/actions/teams';
import {Permissions} from 'mattermost-redux/constants';
import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles';

Expand All @@ -26,7 +26,7 @@ function mapStateToProps(state, ownProps) {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
updateTeam,
patchTeam,
removeTeamIcon,
setTeamIcon,
}, dispatch),
Expand Down
12 changes: 6 additions & 6 deletions components/team_general_tab/team_general_tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class GeneralTab extends React.Component {
collapseModal: PropTypes.func.isRequired,
maxFileSize: PropTypes.number.isRequired,
actions: PropTypes.shape({
updateTeam: PropTypes.func.isRequired,
patchTeam: PropTypes.func.isRequired,
removeTeamIcon: PropTypes.func.isRequired,
setTeamIcon: PropTypes.func.isRequired,
}).isRequired,
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class GeneralTab extends React.Component {
var data = {...this.props.team};
data.allowed_domains = this.state.allowed_domains;

const {error} = await this.props.actions.updateTeam(data);
const {error} = await this.props.actions.patchTeam(data);

if (error) {
state.serverError = error.message;
Expand All @@ -125,7 +125,7 @@ export default class GeneralTab extends React.Component {
var data = {...this.props.team};
data.allow_open_invite = this.state.allow_open_invite;

const {error} = await this.props.actions.updateTeam(data);
const {error} = await this.props.actions.patchTeam(data);

if (error) {
state.serverError = error.message;
Expand Down Expand Up @@ -170,7 +170,7 @@ export default class GeneralTab extends React.Component {
var data = {...this.props.team};
data.display_name = this.state.name;

const {error} = await this.props.actions.updateTeam(data);
const {error} = await this.props.actions.patchTeam(data);

if (error) {
state.serverError = error.message;
Expand Down Expand Up @@ -201,7 +201,7 @@ export default class GeneralTab extends React.Component {
var data = {...this.props.team};
data.invite_id = this.state.invite_id;

const {error} = await this.props.actions.updateTeam(data);
const {error} = await this.props.actions.patchTeam(data);

if (error) {
state.serverError = error.message;
Expand Down Expand Up @@ -236,7 +236,7 @@ export default class GeneralTab extends React.Component {
var data = {...this.props.team};
data.description = this.state.description;

const {error} = await this.props.actions.updateTeam(data);
const {error} = await this.props.actions.patchTeam(data);

if (error) {
state.serverError = error.message;
Expand Down
96 changes: 93 additions & 3 deletions tests/components/team_general_tab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('components/TeamSettings', () => {
closeModal: () => {}, //eslint-disable-line no-empty-function
collapseModal: () => {}, //eslint-disable-line no-empty-function
actions: {
updateTeam: () => {}, //eslint-disable-line no-empty-function
patchTeam: () => {}, //eslint-disable-line no-empty-function
removeTeamIcon: () => {}, //eslint-disable-line no-empty-function
setTeamIcon: () => {}, //eslint-disable-line no-empty-function
},
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('components/TeamSettings', () => {

test('should call actions.setTeamIcon on handleTeamIconSubmit', () => {
const actions = {
updateTeam: jest.fn(),
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('components/TeamSettings', () => {

test('should call actions.removeTeamIcon on handleTeamIconRemove', () => {
const actions = {
updateTeam: jest.fn(),
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};
Expand All @@ -112,4 +112,94 @@ describe('components/TeamSettings', () => {
expect(wrapper1).toMatchSnapshot();
expect(wrapper2).toMatchSnapshot();
});

test('should call actions.patchTeam on handleAllowedDomainsSubmit', () => {
const actions = {
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};

const props = {...defaultProps, actions};

const wrapper = shallow(<GeneralTab {...props}/>);

wrapper.instance().handleAllowedDomainsSubmit({preventDefault: jest.fn()});

expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
});

test('should call actions.patchTeam on handleOpenInviteSubmit', () => {
const actions = {
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};

const props = {...defaultProps, actions};

const wrapper = shallow(<GeneralTab {...props}/>);

wrapper.instance().handleOpenInviteSubmit({preventDefault: jest.fn()});

expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
});

test('should call actions.patchTeam on handleNameSubmit', () => {
const actions = {
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};

const props = {...defaultProps, actions};
props.team.display_name = 'TestTeam';

const wrapper = shallow(<GeneralTab {...props}/>);

wrapper.instance().handleNameSubmit({preventDefault: jest.fn()});

expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
});

test('should call actions.patchTeam on handleInviteIdSubmit', () => {
const actions = {
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};

const props = {...defaultProps, actions};
props.team.invite_id = '12345';

const wrapper = shallow(<GeneralTab {...props}/>);

wrapper.instance().handleInviteIdSubmit({preventDefault: jest.fn()});

expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
});

test('should call actions.patchTeam on handleDescriptionSubmit', () => {
const actions = {
patchTeam: jest.fn(),
removeTeamIcon: jest.fn(),
setTeamIcon: jest.fn(),
};

const props = {...defaultProps, actions};

const wrapper = shallow(<GeneralTab {...props}/>);

const newDescription = 'The Test Team';
wrapper.setState({description: newDescription});
wrapper.instance().handleDescriptionSubmit({preventDefault: jest.fn()});
props.team.description = newDescription;

expect(actions.patchTeam).toHaveBeenCalledTimes(1);
expect(actions.patchTeam).toHaveBeenCalledWith(props.team);
});
});

0 comments on commit fe57d18

Please sign in to comment.