55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { decodeReplicateParams, phpUnserialize } from '../src/reports/newTemplates/phpDecoder';
|
||
import { formatDeadlineOffset } from '../src/reports/newTemplates/deadlineOffsetParser';
|
||
import { decodeFullReplicationParams } from '../src/reports/newTemplates/replicationParamsParser';
|
||
|
||
describe('phpUnserialize', () => {
|
||
it('разбирает массив с строками и числами', () => {
|
||
const raw = 'a:3:{s:6:"PERIOD";s:6:"weekly";s:10:"EVERY_WEEK";i:1;s:9:"WEEK_DAYS";a:2:{i:0;i:1;i:1;i:3;}}';
|
||
const decoded = phpUnserialize(raw);
|
||
expect(decoded.PERIOD).toBe('weekly');
|
||
expect(decoded.EVERY_WEEK).toBe(1);
|
||
expect(decoded.WEEK_DAYS).toEqual([1, 3]);
|
||
});
|
||
});
|
||
|
||
describe('decodeReplicateParams', () => {
|
||
it('приводит PHP-параметры к числам и строкам', () => {
|
||
const raw = 'a:4:{s:6:"PERIOD";s:5:"daily";s:9:"EVERY_DAY";s:1:"2";s:12:"WORKDAY_ONLY";s:1:"Y";s:11:"REPEAT_TILL";s:7:"endless";}';
|
||
const params = decodeReplicateParams(raw);
|
||
expect(params.PERIOD).toBe('daily');
|
||
expect(params.EVERY_DAY).toBe(2);
|
||
expect(params.WORKDAY_ONLY).toBe('Y');
|
||
expect(params.REPEAT_TILL).toBe('endless');
|
||
});
|
||
});
|
||
|
||
describe('formatDeadlineOffset', () => {
|
||
it('форматирует обычные сутки', () => {
|
||
expect(formatDeadlineOffset(String(2 * 86400 + 3 * 3600), 'N')).toBe('2 д, 3 ч');
|
||
});
|
||
|
||
it('форматирует рабочие дни по 9 часов', () => {
|
||
expect(formatDeadlineOffset(String(9 * 3600 * 2 + 3600), 'Y')).toBe('2 раб. д, 1 раб. ч');
|
||
});
|
||
|
||
it('возвращает пустую строку для нуля', () => {
|
||
expect(formatDeadlineOffset('0', 'N')).toBe('');
|
||
});
|
||
});
|
||
|
||
describe('decodeFullReplicationParams', () => {
|
||
it('описывает еженедельное повторение', () => {
|
||
const text = decodeFullReplicationParams({
|
||
PERIOD: 'weekly',
|
||
EVERY_WEEK: 1,
|
||
WEEK_DAYS: [1, 3],
|
||
REPEAT_TILL: 'endless',
|
||
TIME: '09:00',
|
||
});
|
||
expect(text).toContain('Каждую неделю в понедельник, среду');
|
||
expect(text).toContain('бесконечно');
|
||
expect(text).toContain('в 09:00');
|
||
});
|
||
});
|