|
|
@@ -16,6 +16,11 @@ const checks = []
|
|
|
const errors = []
|
|
|
const unknown = []
|
|
|
const orders = []
|
|
|
+const detailRequests = []
|
|
|
+const receiptRequests = []
|
|
|
+let receiptUnauthorized = true
|
|
|
+let detailMode = 'items'
|
|
|
+const expectedHttpErrors = new Set()
|
|
|
const ids = { ng: '620699181539139625', ae: '620699181539139643' }
|
|
|
const art = '<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160"><rect width="160" height="160" fill="#f4f6f8"/><rect x="55" y="18" width="50" height="125" rx="8" fill="#e9f4f8"/><rect x="60" y="65" width="40" height="45" fill="#202259"/></svg>'
|
|
|
|
|
|
@@ -49,6 +54,29 @@ async function main() {
|
|
|
allGoods: [{ ID: 'P1', GOODS_NAME: 'Sample registration product', GOODS_NO: 'SKU1', COVER: 'guest-fixture.png', SELL_PRICE: 100, MARKET_PRICE: 120, PRICE_PV: 20, STORE_NUMS: 5, TAX_RATE: 7.5, CODE: 'NGN' }],
|
|
|
allOpenBank: [], region: [], decLevel: [], isDec: '0', payList: [{ label: 'pay_stack', name: 'Paystack' }]
|
|
|
}
|
|
|
+ } else if (api === '/v1/shop/no-login-order-detail') {
|
|
|
+ assert.equal(request.method(), 'GET')
|
|
|
+ const sn = url.searchParams.get('orderSn')
|
|
|
+ assert(sn && sn.startsWith('SAMPLE-ORDER-'))
|
|
|
+ detailRequests.push(sn)
|
|
|
+ if (detailMode === 'error') return route.fulfill({ contentType: 'application/json', body: JSON.stringify({ success: false, message: 'Sample query failure' }) })
|
|
|
+ data = {
|
|
|
+ order: { SN: sn, STATUS: 'Unpaid', CURRENCY: 'NGN', CREATED_AT: 1792000000, ORDER_AMOUNT: '120.00', PAY_AMOUNT: '130.00', PAY_FREIGHT: '10.00', CONSIGNEE: 'Sample recipient', MOBILE: '+234123456789', FULL_ADDRESS: 'Sample street, Lagos', COUNTRY: 'Nigeria', PAY_TYPE: 'Paystack', USER_NAME: 'PRIVATE-MEMBER', SHOW_BV: true },
|
|
|
+ goods: [{ GOODS_TITLE: 'Sample ordered product', SKU_CODE: 'SAMPLE-SKU', COVER: 'guest-fixture.png', REAL_PRICE: '120.00', BUY_NUMS: 1, TAX_RATE: 7.5 }]
|
|
|
+ }
|
|
|
+ if (detailMode === 'empty') {
|
|
|
+ data.goods = []
|
|
|
+ Object.assign(data.order, { STATUS: 'Paid', ORDER_AMOUNT: '2999000.00', PAY_AMOUNT: '2999000.00', FULL_ADDRESS: '', CONSIGNEE: '', MOBILE: '' })
|
|
|
+ }
|
|
|
+ } else if (api.startsWith('/v1/shop/no-login-order-export/') || api.startsWith('/v1/shop/order-export/')) {
|
|
|
+ assert.equal(request.method(), 'GET')
|
|
|
+ receiptRequests.push(api)
|
|
|
+ assert.equal(Boolean(request.headers().authorization), api.startsWith('/v1/shop/order-export/'), 'Receipt endpoint must follow the current session')
|
|
|
+ if (receiptUnauthorized) {
|
|
|
+ expectedHttpErrors.add(url.href)
|
|
|
+ return route.fulfill({ status: 401, contentType: 'application/json', body: JSON.stringify({ status: 401, code: 0, message: 'Unauthorized' }) })
|
|
|
+ }
|
|
|
+ data = { fileUrl: origin + '/sample-receipt.pdf', targetName: 'sample-receipt.pdf' }
|
|
|
} else if (api === '/v1/shop/no-login-reconsume-sure-order') {
|
|
|
assert.equal(request.method(), 'POST')
|
|
|
const params = request.postDataJSON()
|
|
|
@@ -62,6 +90,7 @@ async function main() {
|
|
|
return route.fulfill({ contentType: 'application/json', body: JSON.stringify({ success: true, data: { data }}) })
|
|
|
}
|
|
|
if (request.resourceType() === 'image' && url.origin !== origin) return route.fulfill({ contentType: 'image/svg+xml', body: art })
|
|
|
+ if (url.href === origin + '/sample-receipt.pdf') return route.fulfill({ contentType: 'application/pdf', headers: { 'Content-Disposition': 'attachment; filename="sample-receipt.pdf"' }, body: '%PDF-1.4\n%%EOF' })
|
|
|
if (url.origin === origin) return route.continue()
|
|
|
unknown.push(url.origin + url.pathname)
|
|
|
return route.abort()
|
|
|
@@ -69,7 +98,7 @@ async function main() {
|
|
|
const page = await context.newPage()
|
|
|
page.setDefaultTimeout(10000)
|
|
|
page.on('pageerror', error => errors.push(error.message))
|
|
|
- page.on('console', message => { if (message.type() === 'error') errors.push(message.text()) })
|
|
|
+ page.on('console', message => { if (message.type() === 'error' && !expectedHttpErrors.has(message.location().url)) errors.push(message.text()) })
|
|
|
const layouts = async(label, dialog = false) => {
|
|
|
for (const [width, height] of viewports) {
|
|
|
await page.setViewportSize({ width, height })
|
|
|
@@ -79,7 +108,7 @@ async function main() {
|
|
|
const box = await page.locator('.el-dialog:visible').boundingBox()
|
|
|
assert(box && box.x >= 0 && box.x + box.width <= width + 1, label + ' dialog overflow')
|
|
|
}
|
|
|
- if (width === 375 && height === 812 && /checkout|email|market/.test(label)) await page.screenshot({ path: path.join(output, label + '-mobile.png'), fullPage: true, animations: 'disabled' })
|
|
|
+ if (width === 375 && height === 812 && /checkout|email|market|order/.test(label)) await page.screenshot({ path: path.join(output, label + '-mobile.png'), fullPage: true, animations: 'disabled' })
|
|
|
checks.push({ label, width, height })
|
|
|
}
|
|
|
await page.setViewportSize({ width: 1440, height: 900 })
|
|
|
@@ -160,9 +189,48 @@ async function main() {
|
|
|
assert.equal(orders.length, before, 'Resuming payment must not create another order')
|
|
|
await page.evaluate(() => window.samplePayment.callback({ reference: window.samplePayment.ref }))
|
|
|
await page.waitForURL(/guest-order\?order=SAMPLE-ORDER-/)
|
|
|
- assert((await page.locator('.ng-guest-order').textContent()).includes('Order details are not available yet'))
|
|
|
+ await page.getByText('Sample ordered product', { exact: true }).waitFor()
|
|
|
+ const orderText = await page.locator('.ng-guest-order').textContent()
|
|
|
+ assert(orderText.includes('NGN 130.00') && orderText.includes('Unpaid'), 'SDK success must not replace server payment status')
|
|
|
+ assert(!orderText.includes('PRIVATE-MEMBER') && !orderText.includes('BV'))
|
|
|
+ assert.equal(await page.locator('.ng-public-header').count(), 0)
|
|
|
await layouts(market + '-order')
|
|
|
+ const detailCount = detailRequests.length
|
|
|
+ await page.reload()
|
|
|
+ await page.getByText('Sample ordered product', { exact: true }).waitFor()
|
|
|
+ assert.equal(detailRequests.length, detailCount + 1, 'Refresh must load the order from the API')
|
|
|
+ await context.grantPermissions(['clipboard-read', 'clipboard-write'], { origin })
|
|
|
+ await page.getByRole('button', { name: 'Copy', exact: true }).focus()
|
|
|
+ await page.keyboard.press('Enter')
|
|
|
+ assert.equal(await page.evaluate(() => navigator.clipboard.readText()), page.url(), 'Copied link must follow the current environment')
|
|
|
+ await page.getByRole('button', { name: 'Download receipt', exact: true }).click()
|
|
|
+ await page.getByRole('alert').filter({ hasText: 'Receipt download is unavailable' }).waitFor()
|
|
|
+ assert(page.url().includes('/guest-order?order='), 'Receipt 401 must not redirect to login')
|
|
|
+ receiptUnauthorized = false
|
|
|
+ const downloadPromise = page.waitForEvent('download')
|
|
|
+ await page.getByRole('button', { name: 'Download receipt', exact: true }).click()
|
|
|
+ assert.equal((await downloadPromise).suggestedFilename(), 'sample-receipt.pdf')
|
|
|
+ receiptUnauthorized = true
|
|
|
}
|
|
|
+ detailMode = 'empty'
|
|
|
+ await page.goto(origin + '/#/guest-order?order=SAMPLE-ORDER-EMPTY')
|
|
|
+ await page.getByText('Item details are unavailable.', { exact: true }).waitFor()
|
|
|
+ assert((await page.locator('.ng-guest-order-grand-total').textContent()).includes('NGN 2,999,000.00'))
|
|
|
+ assert.equal(await page.locator('.ng-guest-order-overview .el-tag--success').count(), 1)
|
|
|
+ await layouts('empty-order')
|
|
|
+ detailMode = 'error'
|
|
|
+ await page.goto(origin + '/#/guest-order?order=SAMPLE-ORDER-ERROR')
|
|
|
+ await page.getByRole('button', { name: 'Retry', exact: true }).waitFor()
|
|
|
+ assert.equal(await page.locator('.ng-guest-order-details').count(), 0)
|
|
|
+ await layouts('failed-order')
|
|
|
+ detailMode = 'items'
|
|
|
+ await page.getByRole('button', { name: 'Retry', exact: true }).click()
|
|
|
+ await page.getByText('Sample ordered product', { exact: true }).waitFor()
|
|
|
+ const requestCount = detailRequests.length
|
|
|
+ await page.goto(origin + '/#/guest-order')
|
|
|
+ await page.getByText('Order reference unavailable', { exact: true }).waitFor()
|
|
|
+ assert.equal(detailRequests.length, requestCount)
|
|
|
+ await layouts('missing-order')
|
|
|
await page.goto(origin + '/#/signup')
|
|
|
await page.locator('#ng-signup-SignupPagevue-0').click()
|
|
|
await page.getByText('Nigeria', { exact: true }).click()
|
|
|
@@ -182,6 +250,31 @@ async function main() {
|
|
|
await page.goto(origin + '/#/dashboard/repeat-purchase')
|
|
|
await page.waitForURL(/#\/login/)
|
|
|
assert.equal(await page.evaluate(() => localStorage.getItem('accessToken')), null)
|
|
|
+ // 仅隔离浏览器里的样例会话;外网仍由上面的请求白名单完全拦截。
|
|
|
+ await page.evaluate(() => {
|
|
|
+ const now = String(Math.floor(Date.now() / 1000))
|
|
|
+ localStorage.setItem('accessToken', 'sample-session')
|
|
|
+ localStorage.setItem('accessTokenExpiresIn', '86400')
|
|
|
+ localStorage.setItem('accessTokenUpdateAt', now)
|
|
|
+ localStorage.setItem('refreshToken', 'sample-refresh')
|
|
|
+ localStorage.setItem('refreshTokenExpiresIn', '86400')
|
|
|
+ localStorage.setItem('refreshTokenUpdateAt', now)
|
|
|
+ })
|
|
|
+ await page.goto(origin + '/#/guest-order?order=SAMPLE-ORDER-SIGNED-IN')
|
|
|
+ await page.getByText('Sample ordered product', { exact: true }).waitFor()
|
|
|
+ assert.equal(await page.locator('.ng-public-header').count(), 1, 'Signed-in order details must retain the header')
|
|
|
+ await layouts('signed-in-order')
|
|
|
+ receiptUnauthorized = false
|
|
|
+ const memberReceipt = page.waitForEvent('download')
|
|
|
+ await page.getByRole('button', { name: 'Download receipt', exact: true }).click()
|
|
|
+ assert.equal((await memberReceipt).suggestedFilename(), 'sample-receipt.pdf')
|
|
|
+ assert.equal(receiptRequests[receiptRequests.length - 1], '/v1/shop/order-export/SAMPLE-ORDER-SIGNED-IN')
|
|
|
+ await page.evaluate(() => {
|
|
|
+ for (const key of ['accessToken', 'accessTokenExpiresIn', 'accessTokenUpdateAt', 'refreshToken', 'refreshTokenExpiresIn', 'refreshTokenUpdateAt']) localStorage.removeItem(key)
|
|
|
+ })
|
|
|
+ await page.reload()
|
|
|
+ await page.getByText('Sample ordered product', { exact: true }).waitFor()
|
|
|
+ assert.equal(await page.locator('.ng-public-header').count(), 0, 'Anonymous order details must keep the header hidden')
|
|
|
assert.deepEqual(unknown, [])
|
|
|
assert.deepEqual(errors, [])
|
|
|
fs.writeFileSync(path.join(output, 'results.json'), JSON.stringify({ checks, orders: orders.length, errors, unknown }, null, 2))
|