120 lines
3.8 KiB
JavaScript
120 lines
3.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { buildApp } from '../dist/app.js';
|
|
import {
|
|
haversineMeters,
|
|
StoreDiscoveryRepository
|
|
} from '../dist/stores/store-discovery-repository.js';
|
|
|
|
assert.ok(haversineMeters(31.2304, 121.4737, 31.2304, 121.4737) < 1);
|
|
assert.ok(haversineMeters(31.2304, 121.4737, 31.2200, 121.4800) > 1000);
|
|
|
|
const rows = [
|
|
{
|
|
id: 11, name: '近店', address: 'A', city: '上海市', district: '黄浦区',
|
|
longitude: '121.4737', latitude: '31.2304', contactPhone: '',
|
|
timezone: 'Asia/Shanghai', businessStatus: 'OPEN',
|
|
weekday: 4, openMinute: 0, closeMinute: 0, isClosed: 0, sortOrder: 1
|
|
},
|
|
{
|
|
id: 12, name: '远店', address: 'B', city: '上海市', district: '浦东新区',
|
|
longitude: '121.6000', latitude: '31.3000', contactPhone: '',
|
|
timezone: 'Asia/Shanghai', businessStatus: 'OPEN',
|
|
weekday: 4, openMinute: 0, closeMinute: 0, isClosed: 0, sortOrder: 2
|
|
}
|
|
];
|
|
const repository = new StoreDiscoveryRepository({
|
|
async execute(sql, params) {
|
|
assert.match(sql, /s\.tenant_id = \?/);
|
|
assert.deepEqual(params, ['7', '上海市']);
|
|
return [rows, []];
|
|
}
|
|
});
|
|
const stores = await repository.findStores({
|
|
tenantId: '7', city: '上海市', latitude: 31.2304, longitude: 121.4737,
|
|
now: new Date('2026-06-18T04:00:00.000Z')
|
|
});
|
|
assert.deepEqual(stores.map((store) => store.id), ['11', '12']);
|
|
assert.equal(stores[0].distanceMeters, 0);
|
|
assert.equal(stores[0].openNow, true);
|
|
|
|
const app = await buildApp({
|
|
storeDiscovery: {
|
|
tenancy: {
|
|
async resolveLoginContext(appId, tenantId) {
|
|
assert.equal(appId, 'wx-test-app');
|
|
assert.equal(tenantId, '7');
|
|
return { tenantId: '7', platformAppId: '9', appId };
|
|
}
|
|
},
|
|
repository: {
|
|
async findStores(query) {
|
|
assert.equal(query.city, '上海市');
|
|
return stores;
|
|
},
|
|
async getStore(query) {
|
|
assert.equal(query.tenantId, '7');
|
|
assert.equal(query.storeId, '11');
|
|
return stores[0];
|
|
},
|
|
async listRooms(query) {
|
|
assert.deepEqual(query, { tenantId: '7', storeId: '11' });
|
|
return [{
|
|
id: '101',
|
|
storeId: '11',
|
|
categoryName: '棋牌包间',
|
|
name: '青竹房',
|
|
roomNo: 'A101',
|
|
capacity: 6,
|
|
basePriceCents: 3600,
|
|
weekdayPriceCents: 3200,
|
|
holidayPriceCents: 4200,
|
|
overnightPriceCents: 12800,
|
|
fullDayPriceCents: 22800,
|
|
minimumSpendCents: 0,
|
|
depositCents: 5000,
|
|
minimumMinutes: 60,
|
|
maxAdvanceStartMinutes: 30,
|
|
maxAdvanceDays: 7,
|
|
configurationStatus: 'ENABLED',
|
|
operationalStatus: 'AVAILABLE',
|
|
tags: ['自动麻将机'],
|
|
images: [],
|
|
sortOrder: 1
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
});
|
|
const response = await app.inject({
|
|
method: 'GET',
|
|
url: '/app-api/stores?city=%E4%B8%8A%E6%B5%B7%E5%B8%82',
|
|
headers: { 'x-wechat-appid': 'wx-test-app', 'tenant-id': '7' }
|
|
});
|
|
assert.equal(response.statusCode, 200);
|
|
assert.equal(response.json().data[0].id, '11');
|
|
const invalid = await app.inject({
|
|
method: 'GET',
|
|
url: '/app-api/stores?latitude=31.2',
|
|
headers: { 'x-wechat-appid': 'wx-test-app', 'tenant-id': '7' }
|
|
});
|
|
assert.equal(invalid.statusCode, 400);
|
|
|
|
const detail = await app.inject({
|
|
method: 'GET',
|
|
url: '/app-api/stores/11',
|
|
headers: { 'x-wechat-appid': 'wx-test-app', 'tenant-id': '7' }
|
|
});
|
|
assert.equal(detail.statusCode, 200);
|
|
assert.equal(detail.json().data.name, '近店');
|
|
|
|
const rooms = await app.inject({
|
|
method: 'GET',
|
|
url: '/app-api/stores/11/rooms',
|
|
headers: { 'x-wechat-appid': 'wx-test-app', 'tenant-id': '7' }
|
|
});
|
|
assert.equal(rooms.statusCode, 200);
|
|
assert.equal(rooms.json().data[0].id, '101');
|
|
await app.close();
|
|
|
|
console.log('PASS: M08-A public store detail and room discovery support customer miniapp browsing.');
|