Skip to content

Commit

Permalink
feat: 增加feed listing的类跟测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Nov 4, 2024
1 parent 69cf39c commit 6287eeb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/feed/product/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ListingProduct } from '@/listing/product'
import type { ProductData } from '@/help/state'
import { FeedHeader } from '../FeedHeader'

export class FeedProduct {
sellerId: string
list: ProductData[]
marketplace_id: string
constructor(sellerId: string, marketplace_id: string, list: ProductData[]) {
this.sellerId = sellerId
this.marketplace_id = marketplace_id
this.list = list
}

main() {
return {
header: new FeedHeader(this.sellerId).main(),
messages: this.genMessage(),
}
}

genMessage() {
return this.list.map((item, idx) => {
return {
messageId: idx + 1,
sku: item.sku,
operationType: 'UPDATE',
...new ListingProduct(this.marketplace_id, item).main(),
}
})
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './feed/img'
export * from './feed/price'
export * from './feed/product'
export * from './feed/quantity'
export * from './feed/relation'

Expand Down
12 changes: 12 additions & 0 deletions test/feed/product/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FeedProduct } from '@/index'
import { describe, expect, it } from 'vitest'
import { listingData, parentListingData } from '../../listing/product/state'

describe('should', () => {
const t1 = new FeedProduct('sellerId', 'ATVPDKIKX0DER', [listingData, parentListingData])
it('t1 message', () => {
const obj = t1.main()
console.log(JSON.stringify(obj, null, 2))
expect(obj.messages.length).toEqual(2)
})
})

0 comments on commit 6287eeb

Please sign in to comment.