21 lines
1.1 KiB
JavaScript
21 lines
1.1 KiB
JavaScript
|
|
import test from 'node:test'
|
||
|
|
import assert from 'node:assert/strict'
|
||
|
|
import { purchaseLinkLabel } from '../../src/utils/purchase-link-label.js'
|
||
|
|
|
||
|
|
test('recognises actual Taobao, Tmall and JD links without changing unknown content', () => {
|
||
|
|
assert.equal(purchaseLinkLabel('https://item.taobao.com/item.htm?id=123'), '淘宝')
|
||
|
|
assert.equal(purchaseLinkLabel('https://detail.tmall.com/item.htm?id=1'), '淘宝')
|
||
|
|
assert.equal(purchaseLinkLabel('https://m.tb.cn/h.test'), '淘宝')
|
||
|
|
assert.equal(purchaseLinkLabel('https://e.tb.cn/h.test'), '淘宝')
|
||
|
|
assert.equal(purchaseLinkLabel('https://item.jd.com/123.html'), '京东')
|
||
|
|
assert.equal(purchaseLinkLabel('https://3.cn/abc'), '京东')
|
||
|
|
assert.equal(purchaseLinkLabel('https://example.com/product'), 'https://example.com/product')
|
||
|
|
assert.equal(purchaseLinkLabel('其他备注'), '其他备注')
|
||
|
|
})
|
||
|
|
|
||
|
|
test('does not misidentify lookalike hosts or URLs with credentials', () => {
|
||
|
|
for (const text of ['https://taobao.com.example.com/item', 'https://notjd.com/', 'https://jd.com@evil.test/', 'javascript://jd.com/']) {
|
||
|
|
assert.equal(purchaseLinkLabel(text), text)
|
||
|
|
}
|
||
|
|
})
|