<commit_before>import { createClient } from "fakeredis";
import { EncounterState } from "../common/EncounterState";
import { PlayerViewCombatantState } from "../common/PlayerViewCombatantState";
import { getDefaultSettings } from "../common/Settings";
import { InMemoryPlayerViewManager } from "./InMemoryPlayerViewManager";
import { RedisPlayerViewManager } from "./RedisPlayerViewManager";
import { PlayerViewManager } from "./playerviewmanager";

function TestPlayerViewManagerImplementation(
  managerName: string,
  playerViewManager: PlayerViewManager
) {
  describe(managerName, () => {
    it("Should return a default player view when not initialized", async () => {
      const playerView = await playerViewManager.Get("someId");
      expect(playerView).toEqual({
        encounterState: EncounterState.Default<PlayerViewCombatantState>(),
        settings: getDefaultSettings().PlayerView
      });
    });
  });
}

TestPlayerViewManagerImplementation(
  "InMemoryPlayerViewManager",
  new InMemoryPlayerViewManager()
);
TestPlayerViewManagerImplementation(
  "RedisPlayerViewManager",
  new RedisPlayerViewManager(createClient("test"))
);
<commit_msg>change instance parameter to factory<commit_after>import { createClient } from "fakeredis";
import { EncounterState } from "../common/EncounterState";
import { PlayerViewCombatantState } from "../common/PlayerViewCombatantState";
import { getDefaultSettings } from "../common/Settings";
import { InMemoryPlayerViewManager } from "./InMemoryPlayerViewManager";
import { RedisPlayerViewManager } from "./RedisPlayerViewManager";
import { PlayerViewManager } from "./playerviewmanager";

function TestPlayerViewManagerImplementation(
  managerName: string,
  makePlayerViewManager: () => PlayerViewManager
) {
  describe(managerName, () => {
    it("Should return a default player view when not initialized", async () => {
      const playerViewManager = makePlayerViewManager();
      const playerView = await playerViewManager.Get("someId");
      expect(playerView).toEqual({
        encounterState: EncounterState.Default<PlayerViewCombatantState>(),
        settings: getDefaultSettings().PlayerView
      });
    });
  });
}

TestPlayerViewManagerImplementation(
  "InMemoryPlayerViewManager",
  () => new InMemoryPlayerViewManager()
);
TestPlayerViewManagerImplementation(
  "RedisPlayerViewManager",
  () => new RedisPlayerViewManager(createClient("test"))
);

{'fraction_non_alphanumeric': 0.11449752883031301, 'fraction_numerical': 0.0, 'mean_word_length': 5.618528610354224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1057739', 'n_tokens_mistral': 628, 'n_tokens_neox': 629, 'n_words': 131}