play products --dry: name what a run would change per product (listings added / changed / removed, regional prices old -> new, dropped regions, activation); checked live with convertRegionPrices allowed, store unchanged; test on a sanitized recorded product
This commit is contained in:
parent
3a755823da
commit
3256beb59f
3 changed files with 78 additions and 3 deletions
|
|
@ -13,6 +13,8 @@
|
|||
listings and images (sha256 of each uploaded file) compared with the local copy, the edit deleted. Before, the
|
||||
dry runs wrote into the edit (PUT details and listings; for images every image set cleared and uploaded) and
|
||||
called `:validate` before discarding it. The output says per language what would change.
|
||||
- `play products --dry` names what a run would change per product (listings added / changed / removed, regional
|
||||
prices old -> new, dropped regions, activation) instead of "update · 174 regions" for every existing product.
|
||||
- `play status`, `play next-version-code`: the read-only edit goes through one helper that always deletes it and
|
||||
warns when the delete fails; `next-version-code` counts distinct version codes (one code on two tracks is one).
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { playCodes, sellsOn } from '../lib/config';
|
|||
import type { Ctx } from '../lib/ctx';
|
||||
import { need } from '../lib/ctx';
|
||||
import { done, log, step, warn } from '../lib/log';
|
||||
import { type Money, playRegionConfigs, toMoney } from '../lib/money';
|
||||
import { fromMoney, type Money, playRegionConfigs, type RegionConfig, toMoney } from '../lib/money';
|
||||
import { playClient } from './client';
|
||||
|
||||
const OPTION = 'buy';
|
||||
|
|
@ -20,7 +20,46 @@ interface Converted {
|
|||
convertedOtherRegionsPrice?: { usdPrice: Money; eurPrice: Money };
|
||||
regionVersion?: { version: string };
|
||||
}
|
||||
interface Existing { productId: string; purchaseOptions?: { purchaseOptionId: string; state?: string }[] }
|
||||
type PlayMoney = Omit<Money, 'units'> & { units?: string };
|
||||
export interface Existing {
|
||||
productId: string;
|
||||
listings?: { languageCode: string; title?: string; description?: string }[];
|
||||
purchaseOptions?: { purchaseOptionId: string; state?: string; regionalPricingAndAvailabilityConfigs?: { regionCode: string; price?: PlayMoney; availability?: string }[];
|
||||
newRegionsConfig?: { usdPrice?: PlayMoney; eurPrice?: PlayMoney; availability?: string } }[];
|
||||
}
|
||||
|
||||
const money = (m?: PlayMoney): string => (m ? `${m.currencyCode} ${fromMoney(m).toFixed(2)}` : '-');
|
||||
|
||||
/**
|
||||
* What a run would change on one product, from the product Play has now (oneTimeProducts list) and the body the run
|
||||
* would PATCH. The PATCH replaces listings and purchase options, so a language on Play that is not in the config is
|
||||
* removed. Prices are compared per region (currency and amount). Empty: nothing would change. Pure.
|
||||
*/
|
||||
export function productChanges(cur: Existing | undefined, want: { listings: { languageCode: string; title: string; description: string }[]; regions: RegionConfig[]; newRegions: { usdPrice: Money; eurPrice: Money } }): string[] {
|
||||
if (!cur) return ['create'];
|
||||
const out: string[] = [];
|
||||
const have = new Map((cur.listings ?? []).map(l => [l.languageCode, l]));
|
||||
const added = want.listings.filter(l => !have.has(l.languageCode)).map(l => l.languageCode);
|
||||
const changed = want.listings.filter(l => { const h = have.get(l.languageCode); return h && ((h.title ?? '') !== l.title || (h.description ?? '') !== l.description); }).map(l => l.languageCode);
|
||||
const removed = [...have.keys()].filter(c => !want.listings.some(l => l.languageCode === c));
|
||||
if (added.length) out.push(`listings added: ${added.join(', ')}`);
|
||||
if (changed.length) out.push(`listings changed: ${changed.join(', ')}`);
|
||||
if (removed.length) out.push(`listings removed: ${removed.join(', ')}`);
|
||||
const opt = cur.purchaseOptions?.find(o => o.purchaseOptionId === OPTION);
|
||||
const now = new Map((opt?.regionalPricingAndAvailabilityConfigs ?? []).map(r => [r.regionCode, r]));
|
||||
const prices = want.regions.flatMap(r => {
|
||||
const h = now.get(r.regionCode)?.price;
|
||||
return h && h.currencyCode === r.price.currencyCode && Math.round(fromMoney(h) * 100) === Math.round(fromMoney(r.price) * 100) ? [] : [`${r.regionCode} ${money(h)} -> ${money(r.price)}`];
|
||||
});
|
||||
const gone = [...now.keys()].filter(c => !want.regions.some(r => r.regionCode === c));
|
||||
if (prices.length) out.push(`prices in ${prices.length} region(s): ${prices.slice(0, 6).join(', ')}${prices.length > 6 ? ', ...' : ''}`);
|
||||
if (gone.length) out.push(`regions dropped: ${gone.join(', ')}`);
|
||||
const nr = opt?.newRegionsConfig;
|
||||
if (money(nr?.usdPrice) !== money(want.newRegions.usdPrice) || money(nr?.eurPrice) !== money(want.newRegions.eurPrice))
|
||||
out.push(`other regions ${money(nr?.usdPrice)} / ${money(nr?.eurPrice)} -> ${money(want.newRegions.usdPrice)} / ${money(want.newRegions.eurPrice)}`);
|
||||
if (opt?.state !== 'ACTIVE') out.push('purchase option activated');
|
||||
return out;
|
||||
}
|
||||
|
||||
export async function listOneTimeProducts(play: Awaited<ReturnType<typeof playClient>>): Promise<Existing[]> {
|
||||
const out: Existing[] = [];
|
||||
|
|
@ -62,7 +101,11 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
}],
|
||||
};
|
||||
const cur = existing.get(p.id);
|
||||
if (dry) { log('play', `${tag}: ${cur ? 'update' : 'create'} · ${regions.length} regions · ${listings.length} listings (dry)`); continue; }
|
||||
if (dry) {
|
||||
const ch = productChanges(cur, { listings, regions, newRegions: conv.convertedOtherRegionsPrice });
|
||||
log('play', `${tag}: ${!ch.length ? 'unchanged' : ch[0] === 'create' ? `would create · ${regions.length} regions · ${listings.length} listings` : 'would update ' + ch.join('; ')} (dry)`);
|
||||
continue;
|
||||
}
|
||||
const v = encodeURIComponent(conv.regionVersion?.version ?? '2022/02');
|
||||
await play.call('PATCH', `${play.API}/onetimeproducts/${encodeURIComponent(p.id)}?allowMissing=true®ionsVersion.version=${v}&updateMask=listings,purchaseOptions`, body);
|
||||
log('play', `${tag}: ${cur ? 'updated' : 'created'} · ${regions.length} regions · ${listings.length} listings`);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
// health / validate said "vitals not readable" with the error cut off inside the long query string.
|
||||
// - `play listing --dry` and `play images --dry` wrote into the edit (PUT details / listings, image DELETE + uploads,
|
||||
// :validate) before discarding it. Now they read and compare only.
|
||||
// - `play products --dry` (oneTimeProducts list + pricing:convertRegionPrices) said "update · 174 regions" for every
|
||||
// existing product, even when a run would change a regional price or replace the listings. It names the changes.
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { createHash, generateKeyPairSync } from 'node:crypto';
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
||||
|
|
@ -17,6 +19,8 @@ import type { Loaded, ShipConfig } from '../cli/lib/config';
|
|||
import { healthFindings, healthTable, issuesQuery, metricQuery } from '../cli/lib/health';
|
||||
import { imageChange, run as imagesRun } from '../cli/play/images';
|
||||
import { detailsChanges, listingChanges, run as listingRun } from '../cli/play/listing';
|
||||
import { type Existing, productChanges } from '../cli/play/products';
|
||||
import { toMoney } from '../cli/lib/money';
|
||||
|
||||
const PKG = 'com.example.game';
|
||||
const API = `https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${PKG}`;
|
||||
|
|
@ -181,3 +185,29 @@ describe('play images --dry: hashes compared, nothing uploaded', () => {
|
|||
expect(lines.join('\n')).toContain('en-US: would replace featureGraphic (1 -> 1), tenInchScreenshots (0 -> 2)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('play products --dry: what would change on an existing product', () => {
|
||||
// one product of oneTimeProducts.list, as answered (3 of 174 regions; Money without nanos for whole prices)
|
||||
const CUR: Existing = { productId: 'com.example.game.no_ads',
|
||||
listings: [{ languageCode: 'en-US', title: 'No Ads', description: 'Removes interstitial ads.' }, { languageCode: 'tr-TR', title: 'Reklamsız', description: 'Ara reklamları kaldırır.' }],
|
||||
purchaseOptions: [{ purchaseOptionId: 'buy', state: 'ACTIVE',
|
||||
regionalPricingAndAvailabilityConfigs: [
|
||||
{ regionCode: 'AE', price: { currencyCode: 'AED', units: '11', nanos: 990000000 }, availability: 'AVAILABLE' },
|
||||
{ regionCode: 'JP', price: { currencyCode: 'JPY', units: '450' }, availability: 'AVAILABLE' },
|
||||
{ regionCode: 'TR', price: { currencyCode: 'TRY', units: '129', nanos: 990000000 }, availability: 'AVAILABLE' }],
|
||||
newRegionsConfig: { usdPrice: { currencyCode: 'USD', units: '2', nanos: 990000000 }, eurPrice: { currencyCode: 'EUR', units: '2', nanos: 670000000 }, availability: 'AVAILABLE' } }] };
|
||||
const region = (regionCode: string, c: string, v: number) => ({ regionCode, availability: 'AVAILABLE' as const, price: toMoney(c, v) });
|
||||
const want = { listings: CUR.listings!.map(l => ({ languageCode: l.languageCode, title: l.title!, description: l.description! })),
|
||||
regions: [region('AE', 'AED', 11.99), region('JP', 'JPY', 450), region('TR', 'TRY', 129.99)], newRegions: { usdPrice: toMoney('USD', 2.99), eurPrice: toMoney('EUR', 2.67) } };
|
||||
|
||||
test('the same product converted again is unchanged (toMoney nanos 0 equals Money without nanos)', () => {
|
||||
expect(productChanges(CUR, want)).toEqual([]);
|
||||
expect(productChanges(undefined, want)).toEqual(['create']);
|
||||
});
|
||||
test('a price override, a changed and a dropped listing, a dropped region are named', () => {
|
||||
const w = { ...want, listings: [{ ...want.listings[0]!, title: 'Remove Ads' }], regions: [want.regions[0]!, region('TR', 'TRY', 99.99)] };
|
||||
expect(productChanges(CUR, w)).toEqual(['listings changed: en-US', 'listings removed: tr-TR', 'prices in 1 region(s): TR TRY 129.99 -> TRY 99.99', 'regions dropped: JP']);
|
||||
const draft = { ...CUR, purchaseOptions: [{ ...CUR.purchaseOptions![0]!, state: 'DRAFT' }] };
|
||||
expect(productChanges(draft, want)).toEqual(['purchase option activated']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue