41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { Ignitor } from '@adonisjs/core'
|
|
|
|
const APP_ROOT = new URL('../../', import.meta.url)
|
|
const IMPORTER = (filePath: string) => {
|
|
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
return import(new URL(filePath, APP_ROOT).href)
|
|
}
|
|
return import(filePath)
|
|
}
|
|
|
|
const ignitor = new Ignitor(APP_ROOT, { importer: IMPORTER })
|
|
const app = ignitor.createApp('web')
|
|
await app.init()
|
|
await app.boot()
|
|
|
|
const ErpService = (await import('#services/erp_service')).default
|
|
const AiService = (await import('#services/ai_service')).default
|
|
const Product = (await import('#models/product')).default
|
|
const EbayService = (await import('#services/ebay_service')).default
|
|
|
|
async function runSyncServiceTest() {
|
|
const product = await Product.query().where('id', 182).first()
|
|
if (!product) {
|
|
throw new Error('Không có sản phẩm nào trong database để test AI suggest')
|
|
}
|
|
console.log(Date.now())
|
|
console.log(`Testing AI suggest for product SKU=${product.sku}, condition=${product.condition}`)
|
|
const dataSources = await ErpService.getSupplierPricing(product)
|
|
console.log("dataSources", dataSources.length)
|
|
const dataEbay = await EbayService.getMarketData(product)
|
|
console.log("dataEbay", dataEbay.sale.length, dataEbay.sold.length)
|
|
const result = await AiService.suggest({ dataEbay, dataSources, product })
|
|
|
|
assert.ok(result, 'Không nhận được dữ liệu từ AI suggest')
|
|
console.log(result)
|
|
console.log(Date.now())
|
|
}
|
|
|
|
await runSyncServiceTest()
|