bitrix/test_timeman.lua

66 lines
2.0 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 timeman = require('bitrix.timeman')
-- Настройка логирования
log.outfile = 'logs/tests_timeman_live_'..os.date('%Y-%m-%d_%H-%M-%S')..'.log'
log.level = 'trace'
log.info("===== СТАРТ ТЕСТИРОВАНИЯ (РЕЖИМ LIVE) =====")
--=== ТЕСТЫ ===--
local function test_timeman_start()
log.info('--- Тест: Начало рабочего дня (timeman.start) ---')
local fields = {
DEVICE = {
TYPE = "browser",
NAME = "Lua SDK Test",
LAT = "0",
LON = "0"
}
}
local result, error_response = timeman.timeman.start(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_timeman_stop(record_id)
if not record_id then return end -- Если старт не удался, пропускаем
log.info('--- Тест: Завершение рабочего дня (timeman.stop) ---')
local fields = {
ID = record_id,
DEVICE = {
TYPE = "browser",
NAME = "Lua SDK Test",
LAT = "0",
LON = "0"
}
}
local result, error_response = timeman.timeman.stop(fields)
if result and result.result then
log.info('Тест завершения дня: УСПЕШНО.')
else
log.error('Тест завершения дня: ПРОВАЛЕНО.')
if error_response then log.error(error_response) end
end
end
--=== ЗАПУСК ТЕСТОВ ===--
local new_record_id = test_timeman_start()
test_timeman_stop(new_record_id)
log.info("===== ЗАВЕРШЕНИЕ ТЕСТИРОВАНИЯ =====")