Procházet zdrojové kódy

fix: guard exclusive coupon activity navigation

Developer před 2 týdny
rodič
revize
af184ae820
2 změnil soubory, kde provedl 16 přidání a 3 odebrání
  1. 4 3
      pagesMy/exclusiveScroll.vue
  2. 12 0
      tests/exclusive-coupon-use.test.js

+ 4 - 3
pagesMy/exclusiveScroll.vue

@@ -112,8 +112,9 @@
 		})
 	}
 	
-	const handleUse = item => {
-		uni.navigateTo({
+	const handleUse = item => {
+		if (!item.activityId) return proxy.$showToast('该专享券未关联有效活动,请联系管理员')
+		uni.navigateTo({
 			url:'/pagesHome/activityDetail?id='+item.activityId
 		})
 	}
@@ -310,4 +311,4 @@
 			}
 		}
 	}
-</style>
+</style>

+ 12 - 0
tests/exclusive-coupon-use.test.js

@@ -0,0 +1,12 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import fs from 'node:fs'
+import path from 'node:path'
+
+const couponPageFile = path.resolve('pagesMy/exclusiveScroll.vue')
+
+test('专享券点击使用前必须校验活动关联', () => {
+  const source = fs.readFileSync(couponPageFile, 'utf8')
+
+  assert.match(source, /const handleUse\s*=\s*item\s*=>\s*\{[\s\S]*?if\s*\(!item\.activityId\)/)
+})