123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import {browserHistory} from 'react-router';
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {logout} from 'app/actionCreators/account';
- import React from 'react';
- import AcceptOrganizationInvite from 'app/views/acceptOrganizationInvite';
- jest.mock('app/actionCreators/account');
- const addMock = body =>
- MockApiClient.addMockResponse({
- url: '/accept-invite/1/abc/',
- method: 'GET',
- body,
- });
- describe('AcceptOrganizationInvite', function() {
- it('can accept invitation', async function() {
- addMock({
- orgSlug: 'test-org',
- needsAuthentication: false,
- needs2fa: false,
- needsSso: false,
- existingMember: false,
- });
- const wrapper = mountWithTheme(
- <AcceptOrganizationInvite params={{memberId: '1', token: 'abc'}} />,
- TestStubs.routerContext()
- );
- const joinButton = wrapper.find('Button[label="join-organization"]');
- expect(joinButton.exists()).toBe(true);
- expect(joinButton.text()).toBe('Join the test-org organization');
- const acceptMock = MockApiClient.addMockResponse({
- url: '/accept-invite/1/abc/',
- method: 'POST',
- });
- joinButton.simulate('click');
- expect(acceptMock).toHaveBeenCalled();
- expect(wrapper.find('Button[label="join-organization"]').props().disabled).toBe(true);
- await tick();
- expect(browserHistory.replace).toHaveBeenCalledWith('/test-org/');
- });
- it('requires authentication to join', function() {
- addMock({
- orgSlug: 'test-org',
- needsAuthentication: true,
- needs2fa: false,
- needsSso: false,
- existingMember: false,
- });
- const wrapper = mountWithTheme(
- <AcceptOrganizationInvite params={{memberId: '1', token: 'abc'}} />,
- TestStubs.routerContext()
- );
- const joinButton = wrapper.find('Button[label="join-organization"]');
- expect(joinButton.exists()).toBe(false);
- expect(wrapper.find('Button[label="create-account"]').exists()).toBe(true);
- });
- it('suggests sso authentication to login', function() {
- addMock({
- orgSlug: 'test-org',
- needsAuthentication: true,
- needs2fa: false,
- needsSso: true,
- existingMember: false,
- });
- const wrapper = mountWithTheme(
- <AcceptOrganizationInvite params={{memberId: '1', token: 'abc'}} />,
- TestStubs.routerContext()
- );
- const joinButton = wrapper.find('Button[label="join-organization"]');
- expect(joinButton.exists()).toBe(false);
- expect(wrapper.find('Button[label="create-account"]').exists()).toBe(false);
- expect(wrapper.find('[data-test-id="suggests-sso"]').exists()).toBe(true);
- expect(wrapper.find('Button[label="sso-login"]').exists()).toBe(true);
- });
- it('shows a logout button for existing members', async function() {
- addMock({
- orgSlug: 'test-org',
- needsAuthentication: false,
- needs2fa: false,
- needsSso: false,
- existingMember: true,
- });
- const wrapper = mountWithTheme(
- <AcceptOrganizationInvite params={{memberId: '1', token: 'abc'}} />,
- TestStubs.routerContext()
- );
- const existingMember = wrapper.find('[data-test-id="existing-member"]');
- expect(existingMember.exists()).toBe(true);
- const {replace} = window.location;
- window.location.replace = jest.fn();
- existingMember.find('Link').simulate('click');
- expect(logout).toHaveBeenCalled();
- await tick();
- expect(window.location.replace).toHaveBeenCalled();
- window.location.replace = replace;
- });
- it('shows 2fa warning', function() {
- addMock({
- orgSlug: 'test-org',
- needsAuthentication: false,
- needs2fa: true,
- needsSso: false,
- existingMember: false,
- });
- const wrapper = mountWithTheme(
- <AcceptOrganizationInvite params={{memberId: '1', token: 'abc'}} />,
- TestStubs.routerContext()
- );
- expect(wrapper.find('[data-test-id="2fa-warning"]').exists()).toBe(true);
- });
- });
|