2023-06-02 07:23:13 +00:00
|
|
|
import test from 'ava'
|
|
|
|
|
2023-06-07 19:09:00 +00:00
|
|
|
import { SerpAPIClient } from '@/services/serpapi'
|
|
|
|
|
2023-06-13 08:09:26 +00:00
|
|
|
import { ky } from '../_utils'
|
2023-06-02 07:23:13 +00:00
|
|
|
|
2023-06-15 05:06:10 +00:00
|
|
|
test('SerpAPIClient.search - coffee', async (t) => {
|
2023-06-02 07:23:13 +00:00
|
|
|
if (!process.env.SERPAPI_API_KEY) {
|
|
|
|
return t.pass()
|
|
|
|
}
|
|
|
|
|
|
|
|
t.timeout(2 * 60 * 1000)
|
2023-06-13 08:09:26 +00:00
|
|
|
const client = new SerpAPIClient({ ky })
|
2023-06-02 07:23:13 +00:00
|
|
|
|
|
|
|
const result = await client.search('coffee')
|
2023-06-15 05:06:10 +00:00
|
|
|
// console.log(JSON.stringify(result, null, 2))
|
|
|
|
t.truthy(result.organic_results)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('SerpAPIClient.search - answer box', async (t) => {
|
|
|
|
if (!process.env.SERPAPI_API_KEY) {
|
|
|
|
return t.pass()
|
|
|
|
}
|
|
|
|
|
|
|
|
t.timeout(2 * 60 * 1000)
|
|
|
|
const client = new SerpAPIClient({ ky })
|
|
|
|
|
|
|
|
const result = await client.search(
|
|
|
|
'how many planets are there in the milky way?'
|
|
|
|
)
|
|
|
|
// console.log(JSON.stringify(result, null, 2))
|
|
|
|
t.truthy(result.answer_box)
|
2023-06-02 07:23:13 +00:00
|
|
|
})
|