mirror of
https://github.com/sebastiandine/Card-Collection-Manager-3.git
synced 2026-08-28 17:01:02 +00:00
patch: sonarqube fixes.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
- `collection_service_tests.cpp` — `CollectionService<MagicCard>` (uses inline `InMemoryRepo` + `StubImageStore`).
|
||||
- `config_service_tests.cpp` — `ConfigService` against `InMemoryFileSystem`.
|
||||
- `json_collection_repository_tests.cpp`, `json_set_repository_tests.cpp` — repository round-trips against `InMemoryFileSystem`.
|
||||
- `local_image_store_tests.cpp` — `LocalImageStore` against `InMemoryFileSystem` + `ConfigService`: `copyIn` (extension preserved, missing source errors), `remove` (existing file deleted; absent path is a no-op), `resolvePath` layout under `dataStorage/<game>/images/`.
|
||||
- `set_service_tests.cpp` — `SetService` with `FakeSetSource` + `InMemSetRepo`.
|
||||
- `magic_set_source_tests.cpp` — `MagicSetSource::parseResponse` (Scryfall mapping). Drives `fetchAll` via `FixedHttpClient` fake.
|
||||
- `magic_card_preview_source_tests.cpp` — `MagicCardPreviewSource::buildSearchUrl` URL-encoding rules + `parseResponse` (`data[0].image_uris.normal`). Drives `fetchImageUrl` via `FixedHttpClient`.
|
||||
|
||||
@@ -12,6 +12,7 @@ add_executable(ccm_core_tests
|
||||
config_service_tests.cpp
|
||||
json_collection_repository_tests.cpp
|
||||
json_set_repository_tests.cpp
|
||||
local_image_store_tests.cpp
|
||||
set_service_tests.cpp
|
||||
magic_set_source_tests.cpp
|
||||
magic_card_preview_source_tests.cpp
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "ccm/infra/LocalImageStore.hpp"
|
||||
#include "ccm/services/ConfigService.hpp"
|
||||
|
||||
#include "fakes/InMemoryFileSystem.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
using namespace ccm;
|
||||
using ccm::testing::InMemoryFileSystem;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string dirNameForGame(Game g) {
|
||||
switch (g) {
|
||||
case Game::Magic: return "magic";
|
||||
case Game::Pokemon: return "pokemon";
|
||||
case Game::YuGiOh: return "yugioh";
|
||||
}
|
||||
return "magic";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_SUITE("LocalImageStore") {
|
||||
TEST_CASE("copyIn creates images directory and preserves source extension") {
|
||||
InMemoryFileSystem mem;
|
||||
ConfigService cfg{mem, "/app/config.json", "/coll"};
|
||||
REQUIRE(cfg.initialize().isOk());
|
||||
LocalImageStore store(mem, cfg, dirNameForGame);
|
||||
|
||||
REQUIRE(mem.writeText("/incoming/card.PNG", "img-bytes").isOk());
|
||||
|
||||
auto r = store.copyIn(Game::Magic, "/incoming/card.PNG", "id001");
|
||||
REQUIRE(r.isOk());
|
||||
CHECK(r.value() == "id001.PNG");
|
||||
|
||||
const std::filesystem::path dest =
|
||||
std::filesystem::path(cfg.current().dataStorage) / "magic" / "images" / "id001.PNG";
|
||||
REQUIRE(mem.exists(dest));
|
||||
auto body = mem.readText(dest);
|
||||
REQUIRE(body.isOk());
|
||||
CHECK(body.value() == "img-bytes");
|
||||
}
|
||||
|
||||
TEST_CASE("copyIn errors when source file is missing") {
|
||||
InMemoryFileSystem mem;
|
||||
ConfigService cfg{mem, "/app/config.json", "/coll"};
|
||||
REQUIRE(cfg.initialize().isOk());
|
||||
LocalImageStore store(mem, cfg, dirNameForGame);
|
||||
|
||||
auto r = store.copyIn(Game::Pokemon, "/nope/missing.jpg", "x");
|
||||
REQUIRE(r.isErr());
|
||||
}
|
||||
|
||||
TEST_CASE("remove deletes an existing image") {
|
||||
InMemoryFileSystem mem;
|
||||
ConfigService cfg{mem, "/app/config.json", "/coll"};
|
||||
REQUIRE(cfg.initialize().isOk());
|
||||
LocalImageStore store(mem, cfg, dirNameForGame);
|
||||
|
||||
const std::filesystem::path imagePath =
|
||||
std::filesystem::path(cfg.current().dataStorage) / "magic" / "images" / "a.png";
|
||||
REQUIRE(mem.ensureDirectory(imagePath.parent_path()).isOk());
|
||||
REQUIRE(mem.writeText(imagePath, "x").isOk());
|
||||
|
||||
REQUIRE(store.remove(Game::Magic, "a.png").isOk());
|
||||
CHECK_FALSE(mem.exists(imagePath));
|
||||
}
|
||||
|
||||
TEST_CASE("remove succeeds when file is already absent") {
|
||||
InMemoryFileSystem mem;
|
||||
ConfigService cfg{mem, "/app/config.json", "/coll"};
|
||||
REQUIRE(cfg.initialize().isOk());
|
||||
LocalImageStore store(mem, cfg, dirNameForGame);
|
||||
|
||||
REQUIRE(store.remove(Game::YuGiOh, "ghost.bin").isOk());
|
||||
}
|
||||
|
||||
TEST_CASE("resolvePath joins data storage game images and filename") {
|
||||
InMemoryFileSystem mem;
|
||||
ConfigService cfg{mem, "/app/config.json", "/coll"};
|
||||
REQUIRE(cfg.initialize().isOk());
|
||||
LocalImageStore store(mem, cfg, dirNameForGame);
|
||||
|
||||
const std::filesystem::path got = store.resolvePath(Game::Pokemon, "pic.jpg");
|
||||
CHECK(got.generic_string() == "/coll/pokemon/images/pic.jpg");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user