ci / module boundaries / boundaries (push) Successful in 7s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m2s
ci / ts / ts (packages + web) (push) Successful in 3m8s
ci / desktop / rust (desktop proxy) (push) Successful in 4m21s
release / release (версия и заметки) (push) Successful in 6s
release / android (APK в релиз) (push) Successful in 4m0s
release / desktop (Linux и Windows в релиз) (push) Successful in 11m49s
release / prune (старые файлы и прогоны) (push) Successful in 5s
Clean release notes in Android and desktop update dialogs. Persist downloaded audio and offline playback events per server and user; add desktop update checks, checksum verification and installer launch.
46 lines
2.3 KiB
TypeScript
46 lines
2.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { AuthSession, type AuthUser } from '@pipu/core';
|
|
|
|
import { createDesktop, desktopFetch, isDesktop } from './desktop';
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe('desktop bridge', () => {
|
|
it('restores the last desktop user when the proxy cannot reach the server', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('offline', { status: 502, headers: { 'x-pipu-transport-error': '1' } })));
|
|
const user = { id: 'alice', username: 'alice' } as AuthUser;
|
|
const clear = vi.fn();
|
|
const session = new AuthSession({ clientType: 'desktop', fetch: desktopFetch, baseUrl: 'http://local', refreshStore: {
|
|
get: async () => 'refresh', set: vi.fn(), clear, getUser: async () => user,
|
|
} });
|
|
expect(await session.restore()).toEqual({ status: 'signed_in', offline: true, user });
|
|
expect(clear).not.toHaveBeenCalled();
|
|
});
|
|
it('reports a failed proxy hop as a network failure, preserving real HTTP errors', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('offline', { status: 502, headers: { 'x-pipu-transport-error': '1' } })));
|
|
await expect(desktopFetch('http://local/api')).rejects.toThrow('Server unavailable');
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('denied', { status: 401 })));
|
|
expect((await desktopFetch('http://local/api')).status).toBe(401);
|
|
});
|
|
it('is inactive in the browser', () => {
|
|
expect(isDesktop()).toBe(false);
|
|
});
|
|
|
|
it('bootstraps through the Tauri invoke surface', async () => {
|
|
const invoke = vi.fn(async (cmd: string) => {
|
|
if (cmd === 'bootstrap') return { proxyBase: 'http://127.0.0.1:9/abc', server: 'https://music.example' };
|
|
if (cmd === 'set_server') return 'https://music.example/pipu';
|
|
return null;
|
|
});
|
|
(window as Window & { __TAURI__?: unknown }).__TAURI__ = { core: { invoke }, event: { listen: vi.fn() } };
|
|
const desktop = await createDesktop();
|
|
expect(desktop?.proxyBase).toBe('http://127.0.0.1:9/abc');
|
|
expect(desktop?.server).toBe('https://music.example');
|
|
await desktop?.setServer('https://music.example/pipu');
|
|
expect(invoke).toHaveBeenCalledWith('set_server', { url: 'https://music.example/pipu' });
|
|
delete (window as Window & { __TAURI__?: unknown }).__TAURI__;
|
|
});
|
|
});
|