35 行
1.3 KiB
C++
35 行
1.3 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "csp/db/sqlite_db.h"
|
|
#include "csp/services/import_service.h"
|
|
|
|
TEST_CASE("import service query latest job and items") {
|
|
auto db = csp::db::SqliteDb::OpenMemory();
|
|
csp::db::ApplyMigrations(db);
|
|
|
|
db.Exec(
|
|
"INSERT INTO import_jobs(status,trigger,total_count,processed_count,success_count,"
|
|
"failed_count,options_json,last_error,started_at,finished_at,updated_at,created_at)"
|
|
"VALUES('running','manual',10,3,2,1,'{}','',100,null,120,90);");
|
|
db.Exec(
|
|
"INSERT INTO import_job_items(job_id,source_path,status,title,difficulty,problem_id,"
|
|
"error_text,started_at,finished_at,updated_at,created_at)"
|
|
"VALUES(1,'CSP-J/2024/Round1/A.pdf','success','A',2,11,'',101,102,120,100);");
|
|
|
|
csp::services::ImportService svc(db);
|
|
const auto latest = svc.GetLatestJob();
|
|
REQUIRE(latest.has_value());
|
|
REQUIRE(latest->id == 1);
|
|
REQUIRE(latest->status == "running");
|
|
REQUIRE(latest->processed_count == 3);
|
|
|
|
csp::services::ImportJobItemQuery q;
|
|
q.page = 1;
|
|
q.page_size = 20;
|
|
const auto items = svc.ListItems(1, q);
|
|
REQUIRE(items.size() == 1);
|
|
REQUIRE(items[0].source_path == "CSP-J/2024/Round1/A.pdf");
|
|
REQUIRE(items[0].status == "success");
|
|
REQUIRE(items[0].problem_id.has_value());
|
|
}
|