2023-07-18 19:35:29 +03:00
|
|
|
const tokens = [
|
|
|
|
{
|
|
|
|
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
|
|
network: 'ethereum',
|
|
|
|
symbol: 'USDC',
|
2023-08-10 22:29:37 +03:00
|
|
|
image: 'http://127.0.0.1:3000/api/image/tokens/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
2023-07-18 19:35:29 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: 'NATIVE',
|
|
|
|
network: 'ethereum',
|
|
|
|
symbol: 'ETH',
|
2023-08-10 22:29:37 +03:00
|
|
|
image: 'http://127.0.0.1:3000/api/image/tokens/ethereum/NATIVE',
|
2023-07-18 19:35:29 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: 'NATIVE',
|
|
|
|
network: 'polygon',
|
|
|
|
symbol: 'MATIC',
|
2023-08-10 22:29:37 +03:00
|
|
|
image: 'http://127.0.0.1:3000/api/image/tokens/polygon/NATIVE',
|
2023-07-18 19:35:29 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0x6982508145454ce325ddbe47a25d4ec3d2311933',
|
|
|
|
network: 'ethereum',
|
|
|
|
symbol: 'PEPE',
|
2023-08-10 22:29:37 +03:00
|
|
|
image: 'http://127.0.0.1:3000/api/image/tokens/ethereum/0x6982508145454ce325ddbe47a25d4ec3d2311933',
|
2023-07-18 19:35:29 +03:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
test.each(tokens)('should inject metadata for valid tokens', async (token) => {
|
|
|
|
const url = 'http://127.0.0.1:3000/tokens/' + token.network + '/' + token.address
|
|
|
|
const body = await fetch(new Request(url)).then((res) => res.text())
|
|
|
|
expect(body).toMatchSnapshot()
|
|
|
|
expect(body).toContain(`<meta property="og:title" content="Get ${token.symbol} on Uniswap"/>`)
|
2023-08-12 01:53:48 +03:00
|
|
|
expect(body).not.toContain(`<meta property="og:description"`)
|
2023-07-18 19:35:29 +03:00
|
|
|
expect(body).toContain(`<meta property="og:image" content="${token.image}"/>`)
|
|
|
|
expect(body).toContain(`<meta property="og:image:width" content="1200"/>`)
|
|
|
|
expect(body).toContain(`<meta property="og:image:height" content="630"/>`)
|
|
|
|
expect(body).toContain(`<meta property="og:type" content="website"/>`)
|
|
|
|
expect(body).toContain(`<meta property="og:url" content="${url}"/>`)
|
|
|
|
expect(body).toContain(`<meta property="og:image:alt" content="Get ${token.symbol} on Uniswap"/>`)
|
|
|
|
expect(body).toContain(`<meta property="twitter:card" content="summary_large_image"/>`)
|
|
|
|
expect(body).toContain(`<meta property="twitter:title" content="Get ${token.symbol} on Uniswap"/>`)
|
|
|
|
expect(body).toContain(`<meta property="twitter:image" content="${token.image}"/>`)
|
|
|
|
expect(body).toContain(`<meta property="twitter:image:alt" content="Get ${token.symbol} on Uniswap"/>`)
|
|
|
|
})
|
|
|
|
|
|
|
|
const invalidTokens = [
|
|
|
|
'http://127.0.0.1:3000/tokens/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb49',
|
|
|
|
'http://127.0.0.1:3000/tokens/ethereum',
|
|
|
|
'http://127.0.0.1:3000/tokens/ethereun',
|
|
|
|
'http://127.0.0.1:3000/tokens/ethereum/0x0',
|
|
|
|
'http://127.0.0.1:3000/tokens/ethereum//',
|
|
|
|
'http://127.0.0.1:3000/tokens/potato/?potato=1',
|
|
|
|
]
|
|
|
|
|
|
|
|
test.each(invalidTokens)('should not inject metadata for invalid tokens', async (url) => {
|
|
|
|
const body = await fetch(new Request(url)).then((res) => res.text())
|
|
|
|
expect(body).not.toContain('og:title')
|
|
|
|
expect(body).not.toContain('og:image')
|
|
|
|
expect(body).not.toContain('og:image:width')
|
|
|
|
expect(body).not.toContain('og:image:height')
|
|
|
|
expect(body).not.toContain('og:type')
|
|
|
|
expect(body).not.toContain('og:url')
|
|
|
|
expect(body).not.toContain('og:image:alt')
|
|
|
|
expect(body).not.toContain('twitter:card')
|
|
|
|
expect(body).not.toContain('twitter:title')
|
|
|
|
expect(body).not.toContain('twitter:image')
|
|
|
|
expect(body).not.toContain('twitter:image:alt')
|
|
|
|
})
|