|
|
@@ -0,0 +1,90 @@
|
|
|
+const test = require('node:test');
|
|
|
+const assert = require('node:assert/strict');
|
|
|
+const config = require('../app.json');
|
|
|
+
|
|
|
+const origin = 'https://www.yuban.co';
|
|
|
+const container = '/common-page/pages/web-view/index';
|
|
|
+let definition;
|
|
|
+global.Page = page => { definition = page; };
|
|
|
+const app = { Parse: { User: { current: () => null } }, globalData: {}, checkAuth: async () => {} };
|
|
|
+global.getApp = () => app;
|
|
|
+global.wx = { getStorageSync: () => '', redirectTo: () => {} };
|
|
|
+require('../common-page/pages/web-view/index');
|
|
|
+function newPage() {
|
|
|
+ return { ...definition, data: { ...definition.data }, setData(update) { Object.assign(this.data, update); } };
|
|
|
+}
|
|
|
+function recipientOptions(path) {
|
|
|
+ assert.equal(path.split('?')[0], container);
|
|
|
+ assert.ok(config.subpackages.some(pkg => pkg.pages.some(page => '/' + pkg.root + '/' + page === container)));
|
|
|
+ return Object.fromEntries(path.split('?').slice(1).join('?').split('&').map(pair => {
|
|
|
+ const split = pair.indexOf('=');
|
|
|
+ return [pair.slice(0, split), pair.slice(split + 1)];
|
|
|
+ }));
|
|
|
+}
|
|
|
+
|
|
|
+for (const route of ['/home','/community','/community?tab=topic']) {
|
|
|
+ test('a new recipient opens '+route, async () => {
|
|
|
+ const sender = newPage();
|
|
|
+ sender.data.path = origin + '/home?token=sender-session';
|
|
|
+ const current = origin + route + (route.includes('?') ? '&' : '?') + 'token=secret&mobile=13800000001';
|
|
|
+ const card = sender.onShareAppMessage({ webViewUrl: current });
|
|
|
+ assert.ok(card?.path, 'native menu must return a usable path');
|
|
|
+ assert.doesNotMatch(decodeURIComponent(card.path), /token|secret|mobile|13800000001/);
|
|
|
+ const recipient = newPage();
|
|
|
+ recipient.checkUserLogin = () => assert.fail('sharing should open before native login');
|
|
|
+ await recipient.onLoad(recipientOptions(card.path));
|
|
|
+ assert.equal(recipient.data.path, origin + route);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+test('an old card without parameters opens a usable homepage', async () => {
|
|
|
+ const page = newPage();
|
|
|
+ await page.onLoad({});
|
|
|
+ assert.equal(page.data.path, origin + '/home');
|
|
|
+});
|
|
|
+
|
|
|
+test('an old chat card with a URL opens the original public destination', async t => {
|
|
|
+ global.getCurrentPages = () => [{}];
|
|
|
+ wx.getEnterOptionsSync = () => ({ path: container, scene: 1008 });
|
|
|
+ t.after(() => { delete global.getCurrentPages; delete wx.getEnterOptionsSync; });
|
|
|
+ const page = newPage();
|
|
|
+ await page.onLoad({ path: encodeURIComponent(origin + '/community?tab=topic&userId=sender') });
|
|
|
+ assert.equal(page.data.path, origin + '/community?tab=topic');
|
|
|
+});
|
|
|
+
|
|
|
+test('cards preserve supported content IDs and discard other fields', async () => {
|
|
|
+ for (const [path, landing] of [
|
|
|
+ ['/topic/t123?token=secret', '/?shareType=topic&shareId=t123'],
|
|
|
+ ['/article/abc_123', '/?shareType=story&shareId=abc_123'],
|
|
|
+ ['/ai-personality?articleId=r123&mobile=123', '/?shareType=ai-report&shareId=r123&reportType=personality'],
|
|
|
+ ['/family-preview/f123', '/?shareType=family-preview&shareId=f123'],
|
|
|
+ ['/community?tab=mine', '/community'],
|
|
|
+ ]) {
|
|
|
+ const sender = newPage();
|
|
|
+ sender.data.path = origin + path;
|
|
|
+ const recipient = newPage();
|
|
|
+ await recipient.onLoad(recipientOptions(sender.onShareAppMessage().path));
|
|
|
+ assert.equal(recipient.data.path, origin + landing);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+test('a missing or invalid destination recovers to home', async () => {
|
|
|
+ for (const path of ['', '%', 'https://www.yuban.co.example/home', origin + '/user-profile']) {
|
|
|
+ const page = newPage();
|
|
|
+ await page.onLoad({ path, fromShare: '1' });
|
|
|
+ assert.equal(page.data.path, origin + '/home');
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+test('ordinary in-app launches retain the original auth and carousel paths', async () => {
|
|
|
+ const gated = newPage();
|
|
|
+ let checked = false;
|
|
|
+ gated.checkUserLogin = async () => { checked = true; return false; };
|
|
|
+ await gated.onLoad({ path: encodeURIComponent(origin + '/user-profile') });
|
|
|
+ assert.ok(checked);
|
|
|
+ assert.equal(gated.data.path, '');
|
|
|
+ const carousel = newPage();
|
|
|
+ await carousel.onLoad({ path: encodeURIComponent(origin + '/home'), skipAuth: 'true' });
|
|
|
+ assert.ok(carousel.data.path.startsWith(origin + '/home?'));
|
|
|
+ assert.match(carousel.data.path, /fromStartup=1/);
|
|
|
+});
|