mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(p2p): force browser mode on p2p subdomains
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
configureP2PBrowserPkcOptions,
|
||||
getPureP2PBrowserPreference,
|
||||
isP2PBrowserHostname,
|
||||
isPureP2PBrowserForced,
|
||||
P2P_BROWSER_PKC_OPTIONS,
|
||||
PURE_P2P_BROWSER_SETTING_KEY,
|
||||
setPureP2PBrowserPreference,
|
||||
@@ -40,6 +41,21 @@ describe('p2p-browser-config', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('forces browser PKC options on p2p subdomains', () => {
|
||||
const targetWindow = {
|
||||
location: { hostname: 'p2p.5chan.app' },
|
||||
localStorage: createStorage({ [PURE_P2P_BROWSER_SETTING_KEY]: 'false' }),
|
||||
defaultPkcOptions: {
|
||||
ipfsGatewayUrls: ['https://gateway.example'],
|
||||
},
|
||||
};
|
||||
|
||||
expect(isPureP2PBrowserForced(targetWindow)).toBe(true);
|
||||
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
|
||||
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(true);
|
||||
expect(targetWindow.defaultPkcOptions).toEqual(P2P_BROWSER_PKC_OPTIONS);
|
||||
});
|
||||
|
||||
it('configures browser PKC options when pure p2p is enabled', () => {
|
||||
const targetWindow = {
|
||||
location: { hostname: '5chan.app' },
|
||||
@@ -80,6 +96,7 @@ describe('p2p-browser-config', () => {
|
||||
|
||||
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
|
||||
expect(targetWindow.defaultPkcOptions).toBe(defaultPkcOptions);
|
||||
expect(isPureP2PBrowserForced({ ...targetWindow, location: { hostname: 'p2p.5chan.app' } })).toBe(false);
|
||||
});
|
||||
|
||||
it('persists and reads the browser pure p2p preference', () => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
const browserWindow = {
|
||||
electronApi: undefined,
|
||||
isElectron: false,
|
||||
location: { hostname: '5chan.app' },
|
||||
localStorage: {
|
||||
getItem: () => null,
|
||||
setItem: () => undefined,
|
||||
@@ -19,6 +20,17 @@ const browserWindow = {
|
||||
const electronWindow = {
|
||||
electronApi: { isElectron: true },
|
||||
isElectron: true,
|
||||
location: { hostname: 'localhost' },
|
||||
} as unknown as Window;
|
||||
|
||||
const p2pBrowserWindow = {
|
||||
electronApi: undefined,
|
||||
isElectron: false,
|
||||
location: { hostname: 'p2p.5chan.app' },
|
||||
localStorage: {
|
||||
getItem: () => 'false',
|
||||
setItem: () => undefined,
|
||||
},
|
||||
} as unknown as Window;
|
||||
|
||||
describe('p2p-runtime', () => {
|
||||
@@ -40,6 +52,13 @@ describe('p2p-runtime', () => {
|
||||
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
|
||||
});
|
||||
|
||||
it('forces browser p2p on p2p subdomains even with gateway account options', () => {
|
||||
const gatewayAccount = { pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } };
|
||||
|
||||
expect(isBrowserPureP2PEnabled(gatewayAccount, p2pBrowserWindow)).toBe(true);
|
||||
expect(shouldShowP2PSettingsSection(gatewayAccount, p2pBrowserWindow)).toBe(true);
|
||||
});
|
||||
|
||||
it('builds browser p2p and gateway account options without a direct pkc-js import', () => {
|
||||
const account = {
|
||||
pkcOptions: {
|
||||
|
||||
Reference in New Issue
Block a user