mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made an interface that represents a game version provider
This commit is contained in:
parent
f67c962726
commit
d50f67b65c
2 changed files with 50 additions and 0 deletions
35
src/games/game-version-provider.ts
Normal file
35
src/games/game-version-provider.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { Awaitable } from "@/utils/types";
|
||||
import { GameVersion } from "./game-version";
|
||||
import { MINECRAFT, MINECRAFT_VERSION_PROVIDER } from "./minecraft";
|
||||
|
||||
/**
|
||||
* Represents a provider for game version.
|
||||
*/
|
||||
export interface GameVersionProvider {
|
||||
/**
|
||||
* Returns an array of game versions that satisfy the given version range.
|
||||
*
|
||||
* @param versions - A version range.
|
||||
*
|
||||
* @returns An array of game versions that satisfy the given version range.
|
||||
*/
|
||||
(versions: string[]): Awaitable<GameVersion[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A map of game version providers keyed by game name.
|
||||
*/
|
||||
const GAME_VERSION_PROVIDERS: ReadonlyMap<string, GameVersionProvider> = new Map([
|
||||
[MINECRAFT, MINECRAFT_VERSION_PROVIDER],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Returns the game version provider for the given game name.
|
||||
*
|
||||
* @param name - The name of the game.
|
||||
*
|
||||
* @returns The {@link GameVersionProvider} for the given game name, or `undefined` if it does not exist.
|
||||
*/
|
||||
export function getGameVersionProviderByName(name: string): GameVersionProvider | undefined {
|
||||
return GAME_VERSION_PROVIDERS.get(name);
|
||||
}
|
15
tests/unit/games/game-version-provider.spec.ts
Normal file
15
tests/unit/games/game-version-provider.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { getGameVersionProviderByName } from "@/games/game-version-provider";
|
||||
|
||||
describe("getGameVersionProviderByName", () => {
|
||||
test("returns the correct provider for a given game name", async () => {
|
||||
const provider = getGameVersionProviderByName("minecraft");
|
||||
|
||||
expect(provider).toBeDefined();
|
||||
});
|
||||
|
||||
test("returns undefined for a non-existing game name", async () => {
|
||||
const provider = getGameVersionProviderByName("unknown-game");
|
||||
|
||||
expect(provider).toBeUndefined();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue