2017-02-24 15:08:59 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
|
|
|
import { connectedComponent, reduxMockStore } from 'test/helpers';
|
|
|
|
import ConnectedEmailTokenRedirect, { EmailTokenRedirect } from 'components/EmailTokenRedirect/EmailTokenRedirect';
|
|
|
|
import Kolide from 'kolide';
|
|
|
|
import { userStub } from 'test/stubs';
|
|
|
|
|
|
|
|
describe('EmailTokenRedirect - component', () => {
|
|
|
|
beforeEach(() => {
|
2020-12-01 18:15:12 +00:00
|
|
|
jest.spyOn(Kolide.users, 'confirmEmailChange')
|
|
|
|
.mockImplementation(() => Promise.resolve({ ...userStub, email: 'new@email.com' }));
|
2017-02-24 15:08:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const authStore = {
|
|
|
|
auth: {
|
|
|
|
user: userStub,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const token = 'KFBR392';
|
|
|
|
const defaultProps = {
|
|
|
|
params: {
|
|
|
|
token,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('componentWillMount', () => {
|
|
|
|
it('calls the API when a token and user are present', () => {
|
|
|
|
const mockStore = reduxMockStore(authStore);
|
|
|
|
|
|
|
|
mount(connectedComponent(ConnectedEmailTokenRedirect, {
|
|
|
|
mockStore,
|
|
|
|
props: defaultProps,
|
|
|
|
}));
|
|
|
|
|
|
|
|
expect(Kolide.users.confirmEmailChange).toHaveBeenCalledWith(userStub, token);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not call the API when only a token is present', () => {
|
|
|
|
const mockStore = reduxMockStore({ auth: {} });
|
|
|
|
|
|
|
|
mount(connectedComponent(ConnectedEmailTokenRedirect, {
|
|
|
|
mockStore,
|
|
|
|
props: defaultProps,
|
|
|
|
}));
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(Kolide.users.confirmEmailChange).not.toHaveBeenCalled();
|
2017-02-24 15:08:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('componentWillReceiveProps', () => {
|
|
|
|
it('calls the API when a user is received', () => {
|
|
|
|
const mockStore = reduxMockStore();
|
|
|
|
const props = { dispatch: mockStore.dispatch, token };
|
|
|
|
const Component = mount(<EmailTokenRedirect {...props} />);
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(Kolide.users.confirmEmailChange).not.toHaveBeenCalled();
|
2017-02-24 15:08:59 +00:00
|
|
|
|
|
|
|
Component.setProps({ user: userStub });
|
|
|
|
|
|
|
|
expect(Kolide.users.confirmEmailChange).toHaveBeenCalledWith(userStub, token);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|