Files
corescope-rx/test/play-upload.test.mjs
T
efiten c898d6f5e8 play-upload: promote a versionCode that is already on Play to another track
The first production release (2026-11-26) needed 12800, already on alpha, as a
draft on production. upload cannot do that: Play refuses a bundle whose
versionCode it already has. promote <versionCode> [--track production]
[--notes vX.Y.Z] finds the release holding that versionCode, copies its name
and notes into a draft on the target track, and leaves rolling out to the
Console, as upload does.
2026-11-26 18:15:52 +01:00

65 lines
3.3 KiB
JavaScript

// The Play upload script builds a draft release without ending the live one, and takes its
// notes from the release file's summary line.
// Run: node --test
import { test } from 'node:test';
import assert from 'node:assert';
import { generateKeyPairSync, createVerify } from 'node:crypto';
import { releaseSummary, withDraft, draftRelease, signedJwt, mappingPath, promotedDraft, NOTES_MAX } from '../scripts/play-upload.mjs';
test('the notes are the summary line, without markdown', () => {
const md = '# CoreDrive RX v1.2.3\r\n\r\nThe **Android app** keeps\n`capturing`.\r\n\r\n## What\'s new\n\n- x\n';
assert.equal(releaseSummary(md), 'The Android app keeps capturing.');
});
test('notes over the Play limit or a missing summary fail instead of uploading', () => {
assert.throws(() => releaseSummary('# T\n\n' + 'a'.repeat(NOTES_MAX + 1)), /Play allows/);
assert.throws(() => releaseSummary('# T\n\n## Only headings\n'), /no summary/);
});
test('a new draft replaces an old draft and keeps the live release', () => {
const live = { status: 'completed', versionCodes: ['12403'] };
const old = { status: 'draft', versionCodes: ['12404'] };
const draft = draftRelease(12405, '1.24.5', 'n');
assert.deepStrictEqual(withDraft([live, old], draft), [live, draft]);
assert.deepStrictEqual(withDraft(undefined, draft), [draft]);
assert.deepStrictEqual(draft, {
name: '12405 (1.24.5)', versionCodes: ['12405'], status: 'draft',
releaseNotes: [{ language: 'en-US', text: 'n' }],
});
});
test('the token request is a JWT signed with the service account key', () => {
const { privateKey, publicKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });
const key = { client_email: 'sa@x.iam.gserviceaccount.com', token_uri: 'https://oauth2.example/token',
private_key: privateKey.export({ type: 'pkcs8', format: 'pem' }) };
const [h, c, s] = signedJwt(key, 1000).split('.');
const claims = JSON.parse(Buffer.from(c, 'base64url'));
assert.deepStrictEqual(claims, { iss: key.client_email, scope: 'https://www.googleapis.com/auth/androidpublisher',
aud: key.token_uri, iat: 1000, exp: 4600 });
assert.equal(JSON.parse(Buffer.from(h, 'base64url')).alg, 'RS256');
assert.ok(createVerify('RSA-SHA256').update(h + '.' + c).verify(publicKey, s, 'base64url'));
});
test('the mapping file goes to the deobfuscation slot of its versionCode', () => {
assert.equal(mappingPath(12501), '/apks/12501/deobfuscationFiles/proguard?uploadType=media');
});
test('promote copies name and notes of the release that holds the versionCode', () => {
const tracks = [
{ track: 'production', releases: [] },
{ track: 'alpha', releases: [
{ name: '12700 (1.27.0)', versionCodes: ['12700'], status: 'completed', releaseNotes: [{ language: 'en-US', text: 'old' }] },
{ name: '12800 (1.28.0)', versionCodes: ['12800'], status: 'completed', releaseNotes: [{ language: 'en-US', text: 'banner' }] },
] },
];
assert.deepStrictEqual(promotedDraft(tracks, 12800), {
name: '12800 (1.28.0)', versionCodes: ['12800'], status: 'draft',
releaseNotes: [{ language: 'en-US', text: 'banner' }],
});
});
test('promote refuses a versionCode that is on no track', () => {
assert.throws(() => promotedDraft([{ track: 'alpha', releases: [] }], '99999'), /on no track/);
assert.throws(() => promotedDraft(undefined, '12800'), /on no track/);
});