锁定微信订阅失败响应
微信订阅消息失败结果不再向 H5 透出原生错误 微信订阅测试覆盖 requestSubscribeMessage 失败的稳定原因 native shell 总门禁反查微信订阅结果边界
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/* global wx */
|
/* global wx */
|
||||||
|
|
||||||
const SUBSCRIBE_RESULT_STORAGE_KEY = 'genarrative:wechat-subscribe-result';
|
const SUBSCRIBE_RESULT_STORAGE_KEY = 'genarrative:wechat-subscribe-result';
|
||||||
|
const WECHAT_SUBSCRIBE_UNAVAILABLE_REASON = 'wechat subscribe unavailable';
|
||||||
|
|
||||||
function appendSubscribeResult(url, result) {
|
function appendSubscribeResult(url, result) {
|
||||||
const hashIndex = String(url || '').indexOf('#');
|
const hashIndex = String(url || '').indexOf('#');
|
||||||
@@ -98,10 +99,11 @@ function createSubscribeMessagePageController(pageContext, options = {}) {
|
|||||||
wx.navigateBack();
|
wx.navigateBack();
|
||||||
},
|
},
|
||||||
fail(error) {
|
fail(error) {
|
||||||
|
console.error('[subscribe-message] request failed', error);
|
||||||
notifyPageResult(
|
notifyPageResult(
|
||||||
page,
|
page,
|
||||||
'skip',
|
'skip',
|
||||||
error && error.errMsg ? error.errMsg : 'failed',
|
WECHAT_SUBSCRIBE_UNAVAILABLE_REASON,
|
||||||
);
|
);
|
||||||
wx.navigateBack();
|
wx.navigateBack();
|
||||||
},
|
},
|
||||||
@@ -121,6 +123,7 @@ function createSubscribeMessagePageController(pageContext, options = {}) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SUBSCRIBE_RESULT_STORAGE_KEY,
|
SUBSCRIBE_RESULT_STORAGE_KEY,
|
||||||
|
WECHAT_SUBSCRIBE_UNAVAILABLE_REASON,
|
||||||
appendSubscribeResult,
|
appendSubscribeResult,
|
||||||
buildSubscribeResultValue,
|
buildSubscribeResultValue,
|
||||||
createSubscribeMessagePageController,
|
createSubscribeMessagePageController,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ describe('subscribe-message mini program bridge', () => {
|
|||||||
let subscribeMessageBridge;
|
let subscribeMessageBridge;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
globalThis.wx = {
|
globalThis.wx = {
|
||||||
requestSubscribeMessage: vi.fn(),
|
requestSubscribeMessage: vi.fn(),
|
||||||
setStorageSync: vi.fn(),
|
setStorageSync: vi.fn(),
|
||||||
@@ -62,6 +63,38 @@ describe('subscribe-message mini program bridge', () => {
|
|||||||
expect(globalThis.wx.navigateBack).toHaveBeenCalled();
|
expect(globalThis.wx.navigateBack).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('hides requestSubscribeMessage native failure details from H5 result', () => {
|
||||||
|
const {
|
||||||
|
SUBSCRIBE_RESULT_STORAGE_KEY,
|
||||||
|
createSubscribeMessagePageController,
|
||||||
|
} = subscribeMessageBridge;
|
||||||
|
const subscribeError = {
|
||||||
|
errMsg: 'requestSubscribeMessage:fail private native detail',
|
||||||
|
};
|
||||||
|
globalThis.wx.requestSubscribeMessage.mockImplementationOnce((options) => {
|
||||||
|
options.fail?.(subscribeError);
|
||||||
|
});
|
||||||
|
const page = createSubscribeMessagePageController(
|
||||||
|
{
|
||||||
|
setData: vi.fn(),
|
||||||
|
},
|
||||||
|
{ templateId: TEST_TEMPLATE_ID },
|
||||||
|
);
|
||||||
|
page.onLoad({ requestId: 'request-fail' });
|
||||||
|
|
||||||
|
page.requestSubscribe();
|
||||||
|
|
||||||
|
expect(globalThis.wx.setStorageSync).toHaveBeenCalledWith(
|
||||||
|
SUBSCRIBE_RESULT_STORAGE_KEY,
|
||||||
|
'request-fail:skip:wechat%20subscribe%20unavailable',
|
||||||
|
);
|
||||||
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
|
'[subscribe-message] request failed',
|
||||||
|
subscribeError,
|
||||||
|
);
|
||||||
|
expect(globalThis.wx.navigateBack).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
test('skip action notifies previous web-view', () => {
|
test('skip action notifies previous web-view', () => {
|
||||||
const {
|
const {
|
||||||
SUBSCRIBE_RESULT_STORAGE_KEY,
|
SUBSCRIBE_RESULT_STORAGE_KEY,
|
||||||
|
|||||||
@@ -1909,6 +1909,39 @@ function assertWechatPaymentResultBoundaries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assertWechatSubscribeResultBoundaries() {
|
||||||
|
const subscribeSource = fs.readFileSync(
|
||||||
|
'miniprogram/host-bridge/subscribeMessage.js',
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
const subscribeTestSource = fs.readFileSync(
|
||||||
|
'miniprogram/host-bridge/subscribeMessage.test.js',
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const snippet of [
|
||||||
|
"WECHAT_SUBSCRIBE_UNAVAILABLE_REASON = 'wechat subscribe unavailable'",
|
||||||
|
"console.error('[subscribe-message] request failed', error)",
|
||||||
|
'WECHAT_SUBSCRIBE_UNAVAILABLE_REASON',
|
||||||
|
]) {
|
||||||
|
if (!subscribeSource.includes(snippet)) {
|
||||||
|
throw new Error(`wechat subscribe bridge must include ${snippet}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subscribeSource.includes("error && error.errMsg ? error.errMsg : 'failed'")) {
|
||||||
|
throw new Error('wechat subscribe bridge must not expose native subscribe errors to H5');
|
||||||
|
}
|
||||||
|
for (const snippet of [
|
||||||
|
'hides requestSubscribeMessage native failure details from H5 result',
|
||||||
|
'wechat%20subscribe%20unavailable',
|
||||||
|
"expect(console.error).toHaveBeenCalledWith(",
|
||||||
|
]) {
|
||||||
|
if (!subscribeTestSource.includes(snippet)) {
|
||||||
|
throw new Error(`wechat subscribe bridge test must include ${snippet}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function assertHostBridgeLayerLayout() {
|
function assertHostBridgeLayerLayout() {
|
||||||
assertSameList(
|
assertSameList(
|
||||||
readDirectoryFileList(
|
readDirectoryFileList(
|
||||||
@@ -2139,6 +2172,9 @@ assertWechatMiniProgramCapabilityFlows();
|
|||||||
console.log('[check:native-shells] wechat-payment-result-boundaries');
|
console.log('[check:native-shells] wechat-payment-result-boundaries');
|
||||||
assertWechatPaymentResultBoundaries();
|
assertWechatPaymentResultBoundaries();
|
||||||
|
|
||||||
|
console.log('[check:native-shells] wechat-subscribe-result-boundaries');
|
||||||
|
assertWechatSubscribeResultBoundaries();
|
||||||
|
|
||||||
console.log('[check:native-shells] h5-host-bridge-event-subscription-gates');
|
console.log('[check:native-shells] h5-host-bridge-event-subscription-gates');
|
||||||
assertH5HostBridgeEventSubscriptionGates();
|
assertH5HostBridgeEventSubscriptionGates();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user