};
handleUpdateUser = () => {
+ const { user } = this.props;
+
this.setState({ submitting: true });
updateUser({
- email: this.state.email,
+ email: user!.local ? this.state.email : undefined,
login: this.state.login,
- name: this.state.name,
+ name: user!.local ? this.state.name : undefined,
scmAccount: uniq(this.state.scmAccounts)
}).then(() => {
this.props.onUpdateUsers();
updateUser: jest.fn().mockResolvedValue({})
}));
+beforeEach(() => {
+ jest.clearAllMocks();
+});
+
it('should render correctly', () => {
expect(shallowRender().dive()).toMatchSnapshot();
expect(shallowRender({ user: undefined }).dive()).toMatchSnapshot();
});
});
-it('should correctly update a user', () => {
+it('should correctly update a local user', () => {
const email = 'foo@bar.ch';
const login = 'foo';
const name = 'Foo';
});
});
+it('should correctly update a non-local user', () => {
+ const email = 'foo@bar.ch';
+ const login = 'foo';
+ const name = 'Foo';
+ const scmAccounts = ['gh', 'bitbucket'];
+ const wrapper = shallowRender({
+ user: mockUser({ email, local: false, login, name, scmAccounts })
+ }).dive();
+
+ submit(wrapper.find('form'));
+
+ expect(updateUser).toBeCalledWith(
+ expect.not.objectContaining({
+ email,
+ name
+ })
+ );
+});
+
function shallowRender(props: Partial<UserForm['props']> = {}) {
return shallow(
<UserForm onClose={jest.fn()} onUpdateUsers={jest.fn()} user={mockUser()} {...props} />