GitNexus/gitnexus-web/test/unit/access-token-prompt.test.tsx
Shifra Williams f2717c6a7c
Some checks are pending
Scorecard / Scorecard analysis (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Skill copy sync / shipped skills drift guard (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
feat(render): add one-click deploy to render support (#2804)
2026-08-06 00:19:44 +00:00

60 lines
2.2 KiB
TypeScript

/**
* The onboarding half of the edge token gate: a 401 has to read as "enter a
* token", not "start a server", and the token the user enters has to reach
* sessionStorage — and only sessionStorage.
*/
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { AccessTokenPrompt } from '../../src/components/AccessTokenPrompt';
import { i18nReady } from '../../src/i18n';
import { AUTH_TOKEN_STORAGE_KEY } from '../../src/config/ui-constants';
import { getAuthToken, setAuthToken } from '../../src/services/backend-client';
const TOKEN = 'deploy-token-abc123';
describe('AccessTokenPrompt', () => {
beforeEach(async () => {
await i18nReady;
setAuthToken('');
});
afterEach(() => {
setAuthToken('');
});
it('stores an entered token in sessionStorage, never localStorage', async () => {
const user = userEvent.setup();
const onSubmit = vi.fn();
render(<AccessTokenPrompt onSubmit={onSubmit} />);
const input = screen.getByLabelText('Access Token');
// Masked by default — the token is never rendered in plain text unasked.
expect(input).toHaveAttribute('type', 'password');
await user.type(input, TOKEN);
await user.click(screen.getByRole('button', { name: 'Connect' }));
expect(getAuthToken()).toBe(TOKEN);
expect(sessionStorage.getItem(AUTH_TOKEN_STORAGE_KEY)).toBe(TOKEN);
expect(localStorage.getItem(AUTH_TOKEN_STORAGE_KEY)).toBeNull();
expect(onSubmit).toHaveBeenCalledOnce();
});
it('reveals and re-masks the token on request', async () => {
const user = userEvent.setup();
render(<AccessTokenPrompt />);
await user.click(screen.getByRole('button', { name: 'Show access token' }));
expect(screen.getByLabelText('Access Token')).toHaveAttribute('type', 'text');
await user.click(screen.getByRole('button', { name: 'Hide access token' }));
expect(screen.getByLabelText('Access Token')).toHaveAttribute('type', 'password');
});
it('points at the Render environment variable that holds the token', () => {
render(<AccessTokenPrompt />);
expect(screen.getByText(/GITNEXUS_SERVE_AUTH_TOKEN/)).toBeInTheDocument();
});
});