bitrix/test_calendar.lua

78 lines
3.1 KiB
Lua
Raw Permalink 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.

local json = require('cjson')
local log = require('utils.log')
local calendar = require('bitrix.calendar')
-- Настройка логирования
log.outfile = 'logs/tests_calendar_live_'..os.date('%Y-%m-%d_%H-%M-%S')..'.log'
log.level = 'trace'
log.info("===== СТАРТ ТЕСТИРОВАНИЯ (РЕЖИМ LIVE) =====")
-- Данные для тестов
local test_user_id = 1 -- Текущий пользователь (обычно ID 1)
local tomorrow = os.date("!*t", os.time() + 24*3600)
local date_from = os.date("%Y%m%dT000000", tomorrow)
local date_to = os.date("%Y%m%dT235959", tomorrow)
--=== ТЕСТЫ ===--
local function test_section_get()
log.info('--- Тест: Получение списка календарей (section.get) ---')
local result, error_response = calendar.calendar.section.get()
if result and #result > 0 then
log.info(string.format('Тест получения календарей: УСПЕШНО. Найдено календарей: %d', #result))
-- Выведем названия первых двух для примера
log.debug('Пример: ' .. result[1].NAME .. ', ' .. (result[2] and result[2].NAME or 'N/A'))
else
log.error('Тест получения календарей: ПРОВАЛЕНО.')
if error_response then log.error(error_response) end
end
end
local function test_event_add()
log.info('--- Тест: Создание события (event.add) ---')
local event_name = "Test Event - " .. os.date("%H-%M-%S")
local fields = {
NAME = event_name,
DESCRIPTION = "Создано автоматически тестовым скриптом",
DT_FROM = date_from,
DT_TO = date_to,
OWNER_ID = test_user_id,
}
local result, error_response = calendar.calendar.event.add(fields)
if result and result.ID then
log.info(string.format('Тест создания события: УСПЕШНО. ID нового события: %d', result.ID))
return result.ID -- Возвращаем ID для следующего теста
else
log.error('Тест создания события: ПРОВАЛЕНО.')
if error_response then log.error(error_response) end
return nil
end
end
local function test_event_get(new_event_id)
if not new_event_id then return end -- Если создание не удалось, пропускаем
log.info('--- Тест: Получение события по ID (event.get) ---')
local result, error_response = calendar.calendar.event.get(new_event_id)
if result and result.ID == new_event_id then
log.info(string.format('Тест получения события: УСПЕШНО. Название: "%s"', result.NAME))
else
log.error('Тест получения события: ПРОВАЛЕНО.')
if error_response then log.error(error_response) end
end
end
--=== ЗАПУСК ТЕСТОВ ===--
test_section_get()
local new_event_id = test_event_add()
test_event_get(new_event_id)
log.info("===== ЗАВЕРШЕНИЕ ТЕСТИРОВАНИЯ =====")