feat: harden phase one workflows
This commit is contained in:
@@ -4,11 +4,21 @@ function listCategories() {
|
||||
return request({ url: '/api/mini/product-categories' })
|
||||
}
|
||||
|
||||
function listProducts(categoryId) {
|
||||
function listProducts(categoryId, keyword) {
|
||||
return request({
|
||||
url: '/api/mini/products',
|
||||
data: categoryId ? { categoryId } : {}
|
||||
})
|
||||
url: '/api/mini/products/page',
|
||||
data: buildProductQuery(categoryId, keyword)
|
||||
}).then((page) => page && page.records ? page.records : [])
|
||||
}
|
||||
|
||||
function buildProductQuery(categoryId, keyword) {
|
||||
const data = {
|
||||
pageNo: 1,
|
||||
pageSize: 20
|
||||
}
|
||||
if (categoryId) data.categoryId = categoryId
|
||||
if (keyword) data.keyword = keyword
|
||||
return data
|
||||
}
|
||||
|
||||
function getProductDetail(id) {
|
||||
@@ -26,6 +36,7 @@ function createGoodsOrder(data) {
|
||||
module.exports = {
|
||||
listCategories,
|
||||
listProducts,
|
||||
buildProductQuery,
|
||||
getProductDetail,
|
||||
createGoodsOrder
|
||||
}
|
||||
|
||||
12
miniapp/miniprogram/api/productApi.test.js
Normal file
12
miniapp/miniprogram/api/productApi.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const { buildProductQuery } = require('./productApi')
|
||||
|
||||
describe('buildProductQuery', () => {
|
||||
test('keeps pagination and optional filters stable', () => {
|
||||
expect(buildProductQuery(2, '苹果')).toEqual({
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
categoryId: 2,
|
||||
keyword: '苹果'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,10 +1,20 @@
|
||||
const { request } = require('../utils/request')
|
||||
|
||||
function listSecondGoods(category) {
|
||||
function listSecondGoods(category, keyword) {
|
||||
return request({
|
||||
url: '/api/mini/second-goods',
|
||||
data: category ? { category } : {}
|
||||
})
|
||||
url: '/api/mini/second-goods/page',
|
||||
data: buildSecondGoodsQuery(category, keyword)
|
||||
}).then((page) => page && page.records ? page.records : [])
|
||||
}
|
||||
|
||||
function buildSecondGoodsQuery(category, keyword) {
|
||||
const data = {
|
||||
pageNo: 1,
|
||||
pageSize: 20
|
||||
}
|
||||
if (category) data.category = category
|
||||
if (keyword) data.keyword = keyword
|
||||
return data
|
||||
}
|
||||
|
||||
function getSecondGoodsDetail(id) {
|
||||
@@ -21,6 +31,7 @@ function createSecondGoods(data) {
|
||||
|
||||
module.exports = {
|
||||
listSecondGoods,
|
||||
buildSecondGoodsQuery,
|
||||
getSecondGoodsDetail,
|
||||
createSecondGoods
|
||||
}
|
||||
|
||||
12
miniapp/miniprogram/api/secondGoodsApi.test.js
Normal file
12
miniapp/miniprogram/api/secondGoodsApi.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const { buildSecondGoodsQuery } = require('./secondGoodsApi')
|
||||
|
||||
describe('buildSecondGoodsQuery', () => {
|
||||
test('keeps pagination and optional filters stable', () => {
|
||||
expect(buildSecondGoodsQuery('母婴', '儿童')).toEqual({
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
category: '母婴',
|
||||
keyword: '儿童'
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user