123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {SentryAppFixture} from 'sentry-fixture/sentryApp';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- waitFor,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import OrganizationDeveloperSettings from 'sentry/views/settings/organizationDeveloperSettings/index';
- describe('Organization Developer Settings', function () {
- const {organization: org, routerProps, router} = initializeOrg();
- const sentryApp = SentryAppFixture({
- scopes: [
- 'team:read',
- 'project:releases',
- 'event:read',
- 'event:write',
- 'org:read',
- 'org:write',
- ],
- });
- beforeEach(() => {
- MockApiClient.clearMockResponses();
- });
- describe('when no Apps exist', () => {
- it('displays empty state', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${org.slug}/sentry-apps/`,
- body: [],
- });
- render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
- await waitFor(() => {
- expect(
- screen.getByText('No internal integrations have been created yet.')
- ).toBeInTheDocument();
- });
- });
- });
- describe('with unpublished apps', () => {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- url: `/organizations/${org.slug}/sentry-apps/`,
- body: [sentryApp],
- });
- });
- it('internal integrations list is empty', () => {
- render(<OrganizationDeveloperSettings {...routerProps} organization={org} />, {
- organization: org,
- });
- expect(
- screen.getByText('No internal integrations have been created yet.')
- ).toBeInTheDocument();
- });
- it('public integrations list contains 1 item', () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />,
- {organization: org}
- );
- expect(screen.getByText('Sample App')).toBeInTheDocument();
- expect(screen.getByText('unpublished')).toBeInTheDocument();
- });
- it('allows for deletion', async () => {
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/`,
- method: 'DELETE',
- body: [],
- });
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />
- );
- const deleteButton = await screen.findByRole('button', {name: 'Delete'});
- expect(deleteButton).toHaveAttribute('aria-disabled', 'false');
- await userEvent.click(deleteButton);
- renderGlobalModal();
- const dialog = await screen.findByRole('dialog');
- expect(dialog).toBeInTheDocument();
- const input = await within(dialog).findByPlaceholderText('sample-app');
- await userEvent.type(input, 'sample-app');
- const confirmDeleteButton = await screen.findByRole('button', {name: 'Confirm'});
- await userEvent.click(confirmDeleteButton);
- await screen.findByText('No public integrations have been created yet.');
- });
- it('can make a request to publish an integration', async () => {
- const mock = MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/publish-request/`,
- method: 'POST',
- });
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />
- );
- const publishButton = await screen.findByRole('button', {name: 'Publish'});
- expect(publishButton).toHaveAttribute('aria-disabled', 'false');
- await userEvent.click(publishButton);
- renderGlobalModal();
- const dialog = await screen.findByRole('dialog');
- expect(dialog).toBeInTheDocument();
- const questionnaire = [
- {
- answer: 'Answer 0',
- question: 'What does your integration do? Please be as detailed as possible.',
- },
- {answer: 'Answer 1', question: 'What value does it offer customers?'},
- {
- answer: 'Answer 2',
- question: 'Do you operate the web service your integration communicates with?',
- },
- {
- answer: 'Answer 3',
- question:
- 'Please justify why you are requesting each of the following permissions: Team Read, Release Admin, Event Write, Organization Write.',
- },
- ];
- for (const {question, answer} of questionnaire) {
- const element = within(dialog).getByRole('textbox', {name: question});
- await userEvent.type(element, answer);
- }
- const requestPublishButton =
- await within(dialog).findByLabelText('Request Publication');
- expect(requestPublishButton).toHaveAttribute('aria-disabled', 'false');
- await userEvent.click(requestPublishButton);
- expect(mock).toHaveBeenCalledWith(
- `/sentry-apps/${sentryApp.slug}/publish-request/`,
- expect.objectContaining({
- data: {questionnaire},
- })
- );
- });
- });
- describe('with published apps', () => {
- beforeEach(() => {
- const publishedSentryApp = SentryAppFixture({status: 'published'});
- MockApiClient.addMockResponse({
- url: `/organizations/${org.slug}/sentry-apps/`,
- body: [publishedSentryApp],
- });
- });
- it('shows the published status', () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />
- );
- expect(screen.getByText('published')).toBeInTheDocument();
- });
- it('trash button is disabled', async () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />
- );
- const deleteButton = await screen.findByRole('button', {name: 'Delete'});
- expect(deleteButton).toHaveAttribute('aria-disabled', 'true');
- });
- it('publish button is disabled', async () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={org}
- location={{...router.location, query: {type: 'public'}}}
- />
- );
- const publishButton = await screen.findByRole('button', {name: 'Publish'});
- expect(publishButton).toHaveAttribute('aria-disabled', 'true');
- });
- });
- describe('with Internal Integrations', () => {
- beforeEach(() => {
- const internalIntegration = SentryAppFixture({status: 'internal'});
- MockApiClient.addMockResponse({
- url: `/organizations/${org.slug}/sentry-apps/`,
- body: [internalIntegration],
- });
- });
- it('allows deleting', async () => {
- render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
- const deleteButton = await screen.findByRole('button', {name: 'Delete'});
- expect(deleteButton).toHaveAttribute('aria-disabled', 'false');
- });
- it('publish button does not exist', () => {
- render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
- expect(screen.queryByText('Publish')).not.toBeInTheDocument();
- });
- });
- describe('without Owner permissions', () => {
- const newOrg = OrganizationFixture({access: ['org:read']});
- beforeEach(() => {
- MockApiClient.addMockResponse({
- url: `/organizations/${newOrg.slug}/sentry-apps/`,
- body: [sentryApp],
- });
- });
- it('trash button is disabled', async () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={newOrg}
- location={{...router.location, query: {type: 'public'}}}
- />,
- {organization: newOrg}
- );
- const deleteButton = await screen.findByRole('button', {name: 'Delete'});
- expect(deleteButton).toHaveAttribute('aria-disabled', 'true');
- });
- it('publish button is disabled', async () => {
- render(
- <OrganizationDeveloperSettings
- {...routerProps}
- organization={newOrg}
- location={{...router.location, query: {type: 'public'}}}
- />,
- {organization: newOrg}
- );
- const publishButton = await screen.findByRole('button', {name: 'Publish'});
- expect(publishButton).toHaveAttribute('aria-disabled', 'true');
- });
- });
- });
|