mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
FSL-1.0-Apache-2.0 grants us the code, not the name. "Sentry" is Functional Software's trademark, so every place the running app says it to a user -- page titles, onboarding, empty states, toasts, settings copy, the self-hosted footer -- now says Sentinel. Attribution is the other half of the deal and stays untouched: upstream copyright headers, LICENSE, NOTICE. So does anything where the mark is a fact rather than a brand -- @sentry/* packages, sentry-cli, the wizard and bundler plugins, docs.sentry.io, the whole gettingStartedDocs tree. Renaming those would leave instructions that no longer work. Nothing structural moved. No import, identifier, route path, feature flag, API field or test id changed; the diff is 312 lines in and 312 out. Colocated specs were updated in lockstep with the copy they assert. Marketing and community links point at hanzo.ai, only where a real page exists to point at. Co-authored-by: Hanzo Dev <[email protected]>
131 lines
3.9 KiB
TypeScript
131 lines
3.9 KiB
TypeScript
import {initializeOrg} from 'sentry-test/initializeOrg';
|
|
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
|
|
|
import * as indicators from 'sentry/actionCreators/indicator';
|
|
import OrganizationsStore from 'sentry/stores/organizationsStore';
|
|
import type {OrgAuthToken} from 'sentry/types';
|
|
import {OrganizationAuthTokensNewAuthToken} from 'sentry/views/settings/organizationAuthTokens/newAuthToken';
|
|
|
|
describe('OrganizationAuthTokensNewAuthToken', function () {
|
|
const ENDPOINT = '/organizations/org-slug/org-auth-tokens/';
|
|
const {organization, router} = initializeOrg();
|
|
|
|
const defaultProps = {
|
|
organization,
|
|
router,
|
|
location: router.location,
|
|
params: {orgId: organization.slug},
|
|
routes: router.routes,
|
|
route: {},
|
|
routeParams: router.params,
|
|
};
|
|
|
|
beforeEach(function () {
|
|
OrganizationsStore.addOrReplace(organization);
|
|
});
|
|
|
|
afterEach(function () {
|
|
MockApiClient.clearMockResponses();
|
|
});
|
|
|
|
it('can create token', async function () {
|
|
render(<OrganizationAuthTokensNewAuthToken {...defaultProps} />);
|
|
|
|
const generatedToken: OrgAuthToken & {token: string} = {
|
|
id: '1',
|
|
name: 'My Token',
|
|
token: 'sntrys_XXXXXXX',
|
|
tokenLastCharacters: 'XXXX',
|
|
dateCreated: new Date('2023-01-01T00:00:00.000Z'),
|
|
scopes: ['org:read'],
|
|
};
|
|
|
|
const mock = MockApiClient.addMockResponse({
|
|
url: ENDPOINT,
|
|
method: 'POST',
|
|
body: generatedToken,
|
|
});
|
|
|
|
expect(screen.queryByLabelText('Generated token')).not.toBeInTheDocument();
|
|
|
|
await userEvent.type(screen.getByLabelText('Name'), 'My Token');
|
|
await userEvent.click(screen.getByRole('button', {name: 'Create Auth Token'}));
|
|
|
|
expect(screen.getByLabelText('Generated token')).toHaveValue('sntrys_XXXXXXX');
|
|
expect(screen.queryByLabelText('Name')).not.toBeInTheDocument();
|
|
|
|
expect(mock).toHaveBeenCalledWith(
|
|
ENDPOINT,
|
|
expect.objectContaining({
|
|
data: {name: 'My Token'},
|
|
})
|
|
);
|
|
});
|
|
|
|
it('handles API errors when creating token', async function () {
|
|
jest.spyOn(indicators, 'addErrorMessage');
|
|
|
|
render(<OrganizationAuthTokensNewAuthToken {...defaultProps} />);
|
|
|
|
const mock = MockApiClient.addMockResponse({
|
|
url: ENDPOINT,
|
|
method: 'POST',
|
|
body: {
|
|
detail: 'Test API error occurred.',
|
|
},
|
|
statusCode: 400,
|
|
});
|
|
|
|
expect(screen.queryByLabelText('Generated token')).not.toBeInTheDocument();
|
|
|
|
await userEvent.type(screen.getByLabelText('Name'), 'My Token');
|
|
await userEvent.click(screen.getByRole('button', {name: 'Create Auth Token'}));
|
|
|
|
expect(screen.queryByLabelText('Generated token')).not.toBeInTheDocument();
|
|
|
|
expect(indicators.addErrorMessage).toHaveBeenCalledWith(
|
|
'Failed to create a new auth token.'
|
|
);
|
|
|
|
expect(mock).toHaveBeenCalledWith(
|
|
ENDPOINT,
|
|
expect.objectContaining({
|
|
data: {name: 'My Token'},
|
|
})
|
|
);
|
|
});
|
|
|
|
it('handles missing_system_url_prefix API error when creating token', async function () {
|
|
jest.spyOn(indicators, 'addErrorMessage');
|
|
|
|
render(<OrganizationAuthTokensNewAuthToken {...defaultProps} />);
|
|
|
|
const mock = MockApiClient.addMockResponse({
|
|
url: ENDPOINT,
|
|
method: 'POST',
|
|
body: {
|
|
detail: {message: 'test message', code: 'missing_system_url_prefix'},
|
|
},
|
|
statusCode: 400,
|
|
});
|
|
|
|
expect(screen.queryByLabelText('Generated token')).not.toBeInTheDocument();
|
|
|
|
await userEvent.type(screen.getByLabelText('Name'), 'My Token');
|
|
await userEvent.click(screen.getByRole('button', {name: 'Create Auth Token'}));
|
|
|
|
expect(screen.queryByLabelText('Generated token')).not.toBeInTheDocument();
|
|
|
|
expect(indicators.addErrorMessage).toHaveBeenCalledWith(
|
|
'You have to configure `system.url-prefix` in your Sentinel instance in order to generate tokens.'
|
|
);
|
|
|
|
expect(mock).toHaveBeenCalledWith(
|
|
ENDPOINT,
|
|
expect.objectContaining({
|
|
data: {name: 'My Token'},
|
|
})
|
|
);
|
|
});
|
|
});
|