Files
JayuCloud/JC-Salon-WeChat/pages/account-settings/index.test.js
T

56 lines
1.4 KiB
JavaScript

const assert = require('assert')
let pageDefinition
let currentProfile
global.Page = definition => { pageDefinition = definition }
global.wx = {
getStorageSync: () => ({}),
setStorageSync: () => {},
showToast: () => {}
}
global.getApp = () => ({ setSession: () => {} })
const profileCache = require('../../utils/profile-cache')
profileCache.getProfile = async () => currentProfile
require('./index')
async function loadProfile(profile) {
currentProfile = profile
const page = {
data: { ...pageDefinition.data },
setData(values) {
Object.entries(values).forEach(([key, value]) => {
const parts = key.split('.')
if (parts.length === 1) this.data[key] = value
else this.data[parts[0]] = { ...this.data[parts[0]], [parts[1]]: value }
})
}
}
await pageDefinition.loadProfile.call(page)
return page.data
}
async function run() {
const empty = await loadProfile({
type: 2,
shopBusinessExpireTime: null,
shopBusinessExpired: false,
shopBusinessRemainingDays: null
})
assert.strictEqual(empty.profile.shopBusinessExpireTime, null)
const active = await loadProfile({
type: 2,
shopBusinessExpireTime: '2026-12-31T23:59:59',
shopBusinessExpired: false,
shopBusinessRemainingDays: 66
})
assert.strictEqual(active.profile.shopBusinessExpireTime, '2026-12-31T23:59:59')
}
run().catch(error => {
console.error(error)
process.exitCode = 1
})