Files
mp-pilates/packages/server/src/user/__tests__/subscription-message.service.spec.ts

80 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
buildClassReviewSubscribeData,
buildBookingCancelledSubscribeData,
buildClassReminderSubscribeData,
} from '../subscription-message.service'
describe('Class review subscribe payload', () => {
it('fills thing1 course, thing2 coach, time3 class time and thing4 tip', () => {
expect(buildClassReviewSubscribeData({
studioName: 'Focus Core 普拉提工作室',
date: new Date('2026-09-09T00:00:00.000Z'),
startTime: '10:00:00',
})).toEqual({
thing1: { value: 'Focus Core 普拉提工作室' },
thing2: { value: 'Iris' },
time3: { value: '2026年09月09日 10:00' },
thing4: { value: '欢迎留下这节课的感受' },
})
})
it('falls back to a short course name and trims thing fields to 20 characters', () => {
const data = buildClassReviewSubscribeData({
studioName: '超长工作室名称用来测试微信订阅消息字段截断是否生效',
date: new Date('2026-01-02T00:00:00.000Z'),
startTime: '09:30',
})
expect(data.thing1.value).toHaveLength(20)
expect(data.thing1.value).toBe('超长工作室名称用来测试微信订阅消息字段截断是否生效'.slice(0, 20))
expect(data.time3.value).toBe('2026年01月02日 09:30')
})
})
describe('Booking cancelled subscribe payload', () => {
it('formats date11, date1 and thing2 correctly', () => {
const data = buildBookingCancelledSubscribeData({
bookingDate: '2026-09-10',
courseTime: '10:00-11:00',
courseName: '普拉提一对一私教体验课',
})
expect(data).toEqual({
date11: { value: '2026-09-10' },
date1: { value: '10:00-11:00' },
thing2: { value: '普拉提一对一私教体验课' },
})
})
it('trims courseName to 20 characters', () => {
const data = buildBookingCancelledSubscribeData({
bookingDate: '2026-09-10',
courseTime: '10:00-11:00',
courseName: '这是一个超过二十个汉字的普拉提非常长非常长非常长的课程名称',
})
expect(data.thing2.value).toHaveLength(20)
})
})
describe('Class reminder subscribe payload', () => {
it('formats thing1, time2 and thing5 correctly', () => {
const data = buildClassReminderSubscribeData({
courseName: '普拉提核心床小班课',
classTime: '2026-09-10 15:00',
tips: '课程将于1小时后开始请准时出席',
})
expect(data).toEqual({
thing1: { value: '普拉提核心床小班课' },
time2: { value: '2026-09-10 15:00' },
thing5: { value: '课程将于1小时后开始请准时出席' },
})
})
it('falls back to default tips and trims fields to 20 characters', () => {
const data = buildClassReminderSubscribeData({
courseName: '超过二十个字的超长课程名称请务必进行截断处理测试',
classTime: '14:00',
})
expect(data.thing1.value).toHaveLength(20)
expect(data.thing5.value).toBe('课程即将于1小时后开始请准时出席'.slice(0, 20))
})
})