Skip to content

fix required params #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions packages/@dcl/sdk-commands/src/commands/start/explorer-alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { CliComponents } from '../../components'

const isWindows = /^win/.test(process.platform)

// Helper function to convert string to boolean
function stringToBoolean(value: string | undefined, defaultValue: boolean = true): boolean {
if (!value) return defaultValue
return value.toLowerCase() === 'true'
}

export async function runExplorerAlpha(
components: CliComponents,
opts: {
Expand Down Expand Up @@ -48,27 +42,32 @@ async function runApp(
const cmd = isWindows ? 'start' : 'open'
const position = args['--position'] ?? `${baseCoords.x},${baseCoords.y}`
const realm = args['--realm'] ?? realmValue
const localScene = stringToBoolean(args['--local-scene'], true)
const debug = stringToBoolean(args['--debug'], true)
const dclenv = args['--dclenv'] ?? 'org'
const skipAuthScreen = stringToBoolean(args['--skip-auth-screen'], true)
const landscapeTerrainEnabled = stringToBoolean(args['--landscape-terrain-enabled'], true)
const openDeeplinkInNewInstance = args['-n']
const skipAuthScreen = !!args['--skip-auth-screen']
const landscapeTerrainEnabled = !!args['--landscape-terrain-enabled']
const openDeeplinkInNewInstance = !!args['-n']

try {
const params = new URLSearchParams()

params.set('realm', realm)
params.set('position', position)
params.set('local-scene', localScene.toString())
params.set('debug', debug.toString())
params.set('hub', isHub.toString())
params.set('dclenv', dclenv)
params.set('skip-auth-screen', skipAuthScreen.toString())
params.set('landscape-terrain-enabled', landscapeTerrainEnabled.toString())

params.set('local-scene', 'true')
params.set('debug', 'true')

if (isHub) {
params.set('hub', 'true')
}
if (skipAuthScreen) {
params.set('skip-auth-screen', 'true')
}
if (landscapeTerrainEnabled) {
params.set('landscape-terrain-enabled', 'true')
}
if (openDeeplinkInNewInstance) {
params.set('open-deeplink-in-new-instance', openDeeplinkInNewInstance.toString())
params.set('open-deeplink-in-new-instance', 'true')
}

const queryParams = params.toString()
Expand Down
8 changes: 4 additions & 4 deletions packages/@dcl/sdk-commands/src/commands/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export const args = declareArgs({
'--explorer-alpha': Boolean,
'--hub': Boolean,
// Params related to the explorer-alpha
'--debug': String,
'--debug': Boolean,
'--dclenv': String,
'--realm': String,
'--local-scene': String,
'--local-scene': Boolean,
'--position': String,
'--skip-auth-screen': String,
'--landscape-terrain-enabled': String,
'--skip-auth-screen': Boolean,
'--landscape-terrain-enabled': Boolean,
'-n': Boolean
})

Expand Down
88 changes: 33 additions & 55 deletions test/sdk-commands/commands/start/explorer-alpha.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ describe('explorer-alpha', () => {
jest.restoreAllMocks()
})

describe('stringToBoolean function', () => {
it('should return true for "true" string', async () => {
// We need to test the internal stringToBoolean function
// Since it's not exported, we'll test it through the runExplorerAlpha function
// by checking the URL parameters
describe('boolean parameters', () => {
it('should always include local-scene and debug parameters', async () => {
const args: any = {
'--local-scene': 'true',
'--debug': 'true',
'--skip-auth-screen': 'true',
'--landscape-terrain-enabled': 'true'
'--local-scene': true,
'--debug': true,
'--skip-auth-screen': true,
'--landscape-terrain-enabled': true
}

await runExplorerAlpha(mockComponents, {
Expand All @@ -60,12 +57,12 @@ describe('explorer-alpha', () => {
)
})

it('should return false for "false" string', async () => {
it('should always include local-scene and debug even when they are false', async () => {
const args: any = {
'--local-scene': 'false',
'--debug': 'false',
'--skip-auth-screen': 'false',
'--landscape-terrain-enabled': 'false'
'--local-scene': false,
'--debug': false,
'--skip-auth-screen': false,
'--landscape-terrain-enabled': false
}

await runExplorerAlpha(mockComponents, {
Expand All @@ -79,12 +76,12 @@ describe('explorer-alpha', () => {
expect(mockExec).toHaveBeenCalledWith(
'/test',
'open',
expect.arrayContaining([expect.stringContaining('local-scene=false')]),
expect.arrayContaining([expect.stringContaining('local-scene=true')]),
{ silent: true }
)
})

it('should return default value (true) for undefined values', async () => {
it('should always include local-scene and debug even when they are undefined', async () => {
const args: any = {}

await runExplorerAlpha(mockComponents, {
Expand All @@ -102,35 +99,6 @@ describe('explorer-alpha', () => {
{ silent: true }
)
})

it('should handle case-insensitive boolean strings', async () => {
const args: any = {
'--local-scene': 'TRUE',
'--debug': 'False',
'--skip-auth-screen': 'True',
'--landscape-terrain-enabled': 'FALSE'
}

await runExplorerAlpha(mockComponents, {
cwd: '/test',
realm: 'test-realm',
baseCoords: { x: 0, y: 0 },
isHub: false,
args
})

expect(mockExec).toHaveBeenCalledWith(
'/test',
'open',
expect.arrayContaining([
expect.stringContaining('local-scene=true'),
expect.stringContaining('debug=false'),
expect.stringContaining('skip-auth-screen=true'),
expect.stringContaining('landscape-terrain-enabled=false')
]),
{ silent: true }
)
})
})

describe('openDeeplinkInNewInstance parameter', () => {
Expand Down Expand Up @@ -180,11 +148,11 @@ describe('explorer-alpha', () => {
const args: any = {
'--position': '10,20',
'--realm': 'custom-realm',
'--local-scene': 'true',
'--debug': 'false',
'--local-scene': true,
'--debug': false,
'--dclenv': 'zone',
'--skip-auth-screen': 'true',
'--landscape-terrain-enabled': 'false',
'--skip-auth-screen': true,
'--landscape-terrain-enabled': false,
'-n': true
}

Expand All @@ -199,13 +167,23 @@ describe('explorer-alpha', () => {
expect(mockExec).toHaveBeenCalledWith(
'/test',
'open',
expect.arrayContaining([
expect.stringMatching(
/decentraland:\/\/.*realm=custom-realm.*position=10%2C20.*local-scene=true.*debug=false.*hub=true.*dclenv=zone.*skip-auth-screen=true.*landscape-terrain-enabled=false.*open-deeplink-in-new-instance=true/
)
]),
expect.arrayContaining([expect.stringMatching(/decentraland:\/\/".*"$/)]),
{ silent: true }
)

// Check that all expected parameters are present
const callArgs = mockExec.mock.calls[0][2][0]
expect(callArgs).toContain('realm=custom-realm')
expect(callArgs).toContain('position=10%2C20')
expect(callArgs).toContain('dclenv=zone')
expect(callArgs).toContain('local-scene=true')
expect(callArgs).toContain('debug=true')
expect(callArgs).toContain('hub=true')
expect(callArgs).toContain('skip-auth-screen=true')
expect(callArgs).toContain('open-deeplink-in-new-instance=true')

// Check that false parameters are not present
expect(callArgs).not.toContain('landscape-terrain-enabled=true')
})

it('should use default values when parameters are not provided', async () => {
Expand All @@ -224,7 +202,7 @@ describe('explorer-alpha', () => {
'open',
expect.arrayContaining([
expect.stringMatching(
/decentraland:\/\/.*realm=default-realm.*position=5%2C10.*local-scene=true.*debug=true.*hub=false.*dclenv=org.*skip-auth-screen=true.*landscape-terrain-enabled=true/
/decentraland:\/\/.*realm=default-realm.*position=5%2C10.*dclenv=org.*local-scene=true.*debug=true/
)
]),
{ silent: true }
Expand Down
Loading