mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-12 05:10:52 +02:00
104 lines
3.6 KiB
JavaScript
104 lines
3.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { createRequire } from 'node:module';
|
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const { _internal } = require('./withAstraAndroidRelease.js');
|
|
|
|
const APP_GRADLE = `apply plugin: "com.android.application"
|
|
|
|
android {
|
|
signingConfigs {
|
|
debug {
|
|
storeFile file('debug.keystore')
|
|
}
|
|
}
|
|
buildTypes {
|
|
debug {
|
|
signingConfig signingConfigs.debug
|
|
}
|
|
release {
|
|
signingConfig signingConfigs.debug
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
test('adds fail-closed release signing without changing debug signing', () => {
|
|
const transformed = _internal.addReleaseSigning(APP_GRADLE);
|
|
|
|
assert.match(transformed, /ASTRA_ALLOW_INSECURE_RELEASE_SIGNING/);
|
|
assert.match(transformed, /throw new GradleException\('Release signing is not configured/);
|
|
assert.match(transformed, /debug \{\n signingConfig signingConfigs\.debug/);
|
|
assert.match(
|
|
transformed,
|
|
/release \{\n signingConfig astraReleaseSigningConfigured \? signingConfigs\.release : signingConfigs\.debug/
|
|
);
|
|
});
|
|
|
|
test('release signing transform is idempotent', () => {
|
|
const transformed = _internal.addReleaseSigning(APP_GRADLE);
|
|
assert.equal(_internal.addReleaseSigning(transformed), transformed);
|
|
assert.equal(transformed.split(_internal.SIGNING_MARKER).length - 1, 1);
|
|
});
|
|
|
|
test('appendBlock adds a native block exactly once', () => {
|
|
const once = _internal.appendBlock('base\n', _internal.SETTINGS_MARKER, `\n${_internal.SETTINGS_MARKER}\nblock\n`);
|
|
const twice = _internal.appendBlock(once, _internal.SETTINGS_MARKER, `\n${_internal.SETTINGS_MARKER}\nblock\n`);
|
|
|
|
assert.equal(once, twice);
|
|
assert.equal(once.split(_internal.SETTINGS_MARKER).length - 1, 1);
|
|
});
|
|
|
|
test('marks QR scanning camera hardware as optional without duplicating it', () => {
|
|
const manifest = { manifest: {} };
|
|
|
|
_internal.ensureOptionalCameraFeature(manifest);
|
|
_internal.ensureOptionalCameraFeature(manifest);
|
|
|
|
assert.deepEqual(manifest.manifest['uses-feature'], [
|
|
{
|
|
$: {
|
|
'android:name': 'android.hardware.camera',
|
|
'android:required': 'false',
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('writes deterministic Astra and RNTP notification icon resources', async (t) => {
|
|
const projectRoot = await mkdtemp(path.join(tmpdir(), 'astra-notification-icon-'));
|
|
t.after(() => rm(projectRoot, { recursive: true, force: true }));
|
|
|
|
await _internal.writeNotificationIconResources(projectRoot);
|
|
const drawablePath = path.join(
|
|
projectRoot,
|
|
'app/src/main/res/drawable',
|
|
_internal.NOTIFICATION_ICON_FILE
|
|
);
|
|
const overridePath = path.join(
|
|
projectRoot,
|
|
'app/src/main/res/values',
|
|
_internal.NOTIFICATION_OVERRIDE_FILE
|
|
);
|
|
const firstDrawable = await readFile(drawablePath, 'utf8');
|
|
const firstOverride = await readFile(overridePath, 'utf8');
|
|
|
|
assert.equal(firstDrawable, _internal.NOTIFICATION_ICON_VECTOR);
|
|
assert.match(firstDrawable, /android:width="24dp"/);
|
|
assert.match(firstDrawable, /android:fillColor="#FFFFFFFF"/);
|
|
assert.doesNotMatch(firstDrawable, /background|logoShadow/);
|
|
assert.equal(firstOverride, _internal.NOTIFICATION_ICON_OVERRIDE);
|
|
assert.match(
|
|
firstOverride,
|
|
/name="exo_notification_small_icon" type="drawable">@drawable\/astra_notification_icon/
|
|
);
|
|
|
|
await _internal.writeNotificationIconResources(projectRoot);
|
|
assert.equal(await readFile(drawablePath, 'utf8'), firstDrawable);
|
|
assert.equal(await readFile(overridePath, 'utf8'), firstOverride);
|
|
});
|