Skip to content

Commit

Permalink
test: fix call of translation service
Browse files Browse the repository at this point in the history
Signed-off-by: Eiko Wagenknecht <[email protected]>
  • Loading branch information
eikowagenknecht committed Jan 2, 2025
1 parent 4aef921 commit 772600a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/services/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,26 @@ export class TranslationService {
}
}

public checkInitialized(): void {
if (!this.initialized) {
throw new Error(
"Translation service not initialized. Call initialize() first.",
);
}
}

public getSourceDisplay(source: OfferSource): string {
this.checkInitialized();
return i18next.t(`sources.${source}`);
}

public getTypeDisplay(type: OfferType, count = 1): string {
this.checkInitialized();
return i18next.t(`types.${type}`, { count });
}

public getDurationDisplay(duration: OfferDuration): string {
this.checkInitialized();
return i18next.t(`durations.${duration}`);
}

Expand All @@ -94,6 +105,7 @@ export class TranslationService {
type?: OfferType,
duration?: OfferDuration,
): string {
this.checkInitialized();
if (!source || !type) {
return i18next.t("feed.titleAll");
}
Expand Down
9 changes: 7 additions & 2 deletions src/utils/names.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { translationService } from "@/services/translation";
import { OfferDuration, OfferType } from "@/types/basic";
import { OfferSource } from "@/types/basic";
import { describe, expect, test } from "vitest";
import { beforeAll, describe, expect, test } from "vitest";
import {
type FilenameOptions,
generateFeedTitle,
generateFilename,
} from "./names";

beforeAll(async () => {
await translationService.initialize();
});

describe("generateFilename", () => {
const baseOptions: FilenameOptions = {
prefix: "lootscraper",
Expand Down Expand Up @@ -53,6 +58,6 @@ describe("generateFeedTitle", () => {
type: OfferType.GAME,
duration: OfferDuration.TEMPORARY,
}),
).toBe("Free Epic Games (TEMPORARY)");
).toBe("Free Epic Games Games (Temporary)");
});
});

0 comments on commit 772600a

Please sign in to comment.