55 lines
3 KiB
TypeScript
55 lines
3 KiB
TypeScript
// Play Console deep links of one app: the link builder (playAppUrl) and where the ids come from (play-ids.ts).
|
|
import { describe, expect, test } from 'bun:test';
|
|
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { PLAY_DEVELOPERS, pickConsoleId, playAppUrl } from '../cli/lib/console-links';
|
|
import { rememberedPlay, resolvePlayIds } from '../cli/lib/play-ids';
|
|
|
|
const DEV = '5550000000000000001', APP = '4970000000000000002';
|
|
|
|
describe('playAppUrl', () => {
|
|
test('both ids: the app dashboard', () => {
|
|
expect(playAppUrl({ developerId: DEV, appId: APP })).toBe(`https://play.google.com/console/u/0/developers/${DEV}/app/${APP}/app-dashboard`);
|
|
});
|
|
test('developer id only: that developer\'s app list', () => {
|
|
expect(playAppUrl({ developerId: DEV })).toBe(`https://play.google.com/console/u/0/developers/${DEV}/app-list`);
|
|
});
|
|
test('nothing known: the developer chooser, never the console root', () => {
|
|
expect(playAppUrl({})).toBe(PLAY_DEVELOPERS);
|
|
expect(playAppUrl({ appId: APP })).toBe(PLAY_DEVELOPERS);
|
|
expect(playAppUrl({ developerId: 'abc' })).toBe(PLAY_DEVELOPERS);
|
|
expect(playAppUrl({})).not.toBe('https://play.google.com/console');
|
|
});
|
|
});
|
|
|
|
describe('resolvePlayIds', () => {
|
|
test('order: config > workspace > profile > remembered', () => {
|
|
expect(resolvePlayIds({ config: { developerId: '1' }, workspace: '2', profile: '3', remembered: { developerId: '4' } }).developerId).toBe('1');
|
|
expect(resolvePlayIds({ workspace: '2', profile: '3', remembered: { developerId: '4' } }).developerId).toBe('2');
|
|
expect(resolvePlayIds({ profile: '3', remembered: { developerId: '4' } }).developerId).toBe('3');
|
|
expect(resolvePlayIds({ remembered: { developerId: '4' } }).developerId).toBe('4');
|
|
expect(resolvePlayIds({})).toEqual({ developerId: null, appId: null });
|
|
});
|
|
test('non-digit values are skipped, never guessed', () => {
|
|
expect(resolvePlayIds({ config: { developerId: 'x1' }, profile: ` ${DEV} ` }).developerId).toBe(DEV);
|
|
expect(pickConsoleId('', null, undefined, '12a')).toBeNull();
|
|
});
|
|
test('app id: config, then the remembered one', () => {
|
|
expect(resolvePlayIds({ config: { appId: APP }, remembered: { appId: '9' } }).appId).toBe(APP);
|
|
expect(resolvePlayIds({ remembered: { appId: '9' } }).appId).toBe('9');
|
|
});
|
|
});
|
|
|
|
describe('rememberedPlay', () => {
|
|
test('reads console-accounts.json per package; missing / broken file = {}', () => {
|
|
const dir = mkdtempSync(join(tmpdir(), 'sb-playids-'));
|
|
const f = join(dir, 'console-accounts.json');
|
|
expect(rememberedPlay('com.example.app', f)).toEqual({});
|
|
writeFileSync(f, JSON.stringify({ version: 1, play: { 'com.example.app': { developerId: DEV, account: 'Example', at: '2026-10-01' } } }));
|
|
expect(rememberedPlay('com.example.app', f)).toEqual({ developerId: DEV, appId: undefined });
|
|
expect(rememberedPlay('com.example.other', f)).toEqual({});
|
|
writeFileSync(f, '{nope');
|
|
expect(rememberedPlay('com.example.app', f)).toEqual({});
|
|
});
|
|
});
|