mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
d3dc6cf76d
Add a volume-mapping guide and surface build/version metadata throughout the project. Changes included: - documentation: Add documentation/deployment/volume-mapping.md and update TABLEOFCONTENTS.md and README to reference it (helps users align download client and RMAB paths). - CI: Capture package.json version in .github/workflows/build-unified-image.yml, pass APP_VERSION as a build-arg, and update the Discord notification to show the semantic version and pull `:latest`. - Docker: Declare ARG APP_VERSION and expose NEXT_PUBLIC_APP_VERSION / APP_VERSION / GIT_COMMIT env vars in dockerfile.unified so runtime and client can read the semantic version and commit. - App API/UI: Update src/app/api/version/route.ts and src/components/ui/VersionBadge.tsx to prefer semantic app version (APP_VERSION / NEXT_PUBLIC_APP_VERSION), include fullVersion and commit info, show commit in tooltip, and adjust fallback/dev labels. - Tests: Update tests (system.routes.test.ts and VersionBadge.test.tsx) to reflect the new version/commit fields and behavior. - Audible integration: Add ipRedirectOverride query param to multiple Audible requests to avoid IP-based region redirects. - Misc: Bump package.json version to 1.0.0. These changes make version information consistent between build, runtime, and UI, improve CI notifications, add user guidance for common volume-mapping issues, and harden Audible scraping against region redirects.
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
/**
|
|
* Component: Version Badge Tests
|
|
* Documentation: documentation/frontend/components.md
|
|
*/
|
|
|
|
// @vitest-environment jsdom
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
import { VersionBadge } from '@/components/ui/VersionBadge';
|
|
|
|
const originalVersion = process.env.NEXT_PUBLIC_APP_VERSION;
|
|
const originalCommit = process.env.NEXT_PUBLIC_GIT_COMMIT;
|
|
|
|
describe('VersionBadge', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
if (originalVersion === undefined) {
|
|
delete process.env.NEXT_PUBLIC_APP_VERSION;
|
|
} else {
|
|
process.env.NEXT_PUBLIC_APP_VERSION = originalVersion;
|
|
}
|
|
if (originalCommit === undefined) {
|
|
delete process.env.NEXT_PUBLIC_GIT_COMMIT;
|
|
} else {
|
|
process.env.NEXT_PUBLIC_GIT_COMMIT = originalCommit;
|
|
}
|
|
});
|
|
|
|
it('renders semantic version from build-time env var', async () => {
|
|
process.env.NEXT_PUBLIC_APP_VERSION = '1.0.0';
|
|
process.env.NEXT_PUBLIC_GIT_COMMIT = 'abcdef1234';
|
|
const fetchMock = vi.fn();
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
render(<VersionBadge />);
|
|
|
|
expect(await screen.findByText('v1.0.0')).toBeInTheDocument();
|
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('falls back to API when build-time version is unavailable', async () => {
|
|
process.env.NEXT_PUBLIC_APP_VERSION = 'unknown';
|
|
const fetchMock = vi.fn().mockResolvedValue({
|
|
json: async () => ({ version: 'v1.2.3', commit: 'abc1234' }),
|
|
});
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
render(<VersionBadge />);
|
|
|
|
expect(await screen.findByText('v1.2.3')).toBeInTheDocument();
|
|
expect(fetchMock).toHaveBeenCalledWith('/api/version');
|
|
});
|
|
|
|
it('shows dev version when API fetch fails', async () => {
|
|
process.env.NEXT_PUBLIC_APP_VERSION = 'unknown';
|
|
const fetchMock = vi.fn().mockRejectedValue(new Error('down'));
|
|
const errorMock = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
render(<VersionBadge />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText('vDEV')).toBeInTheDocument();
|
|
});
|
|
expect(errorMock).toHaveBeenCalledWith('Failed to fetch version:', expect.any(Error));
|
|
});
|
|
});
|