0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 03:30:43 -05:00

Updated localeService test after recent PR merge

Linted test file
This commit is contained in:
Dev 2024-05-20 09:54:40 +01:00
parent fcabd68dfc
commit 2fd5c918ce

View File

@ -22,13 +22,13 @@ describe("LocaleService", () =>
it("should return 'en' globals data when no desired locale found and display warning'", () => it("should return 'en' globals data when no desired locale found and display warning'", () =>
{ {
vi.spyOn(localeService, "getDesiredGameLocale").mockReturnValue({ vi.spyOn(localeService, "getDesiredGameLocale").mockReturnValue({
undefined undefined,
}); });
const warningLogSpy = vi.spyOn(localeService.logger, "warning") const warningLogSpy = vi.spyOn(localeService.logger, "warning");
const result = localeService.getLocaleDb(); const result = localeService.getLocaleDb();
expect(result).equals(localeService.localesTable.global.en); expect(result["54cb50c76803fa8b248b4571 FirstName"]).equals("Pavel Yegorovich");
expect(warningLogSpy).toHaveBeenCalledTimes(1); expect(warningLogSpy).toHaveBeenCalledTimes(1);
}); });
@ -44,39 +44,39 @@ describe("LocaleService", () =>
}); });
it("should return desired value when gameLocale property from config is 'system'", () => it("should return desired value when gameLocale property from config is 'system'", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformForClientLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformForClientLocale").mockReturnValue(
"desiredLocale" "desiredLocale",
); );
localeService.localeConfig.gameLocale = "system"; localeService.localeConfig.gameLocale = "system";
expect(localeService.getDesiredGameLocale()).toBe("desiredLocale"); expect(localeService.getDesiredGameLocale()).toBe("desiredLocale");
}); });
}) });
describe("getDesiredServerLocale", () => describe("getDesiredServerLocale", () =>
{
it("should return serverLocale property from config when value is not 'system''", () =>
{ {
it("should return serverLocale property from config when value is not 'system''", () => localeService.localeConfig.serverLocale = "test";
{
localeService.localeConfig.serverLocale = "test"; expect(localeService.getDesiredServerLocale()).toBe("test");
});
expect(localeService.getDesiredServerLocale()).toBe("test");
}); it("should return desired value when serverLocale property from config is 'system'", () =>
{
it("should return desired value when serverLocale property from config is 'system'", () => // Override the get locale so we control what the input is
{ vi.spyOn(localeService, "getPlatformForServerLocale").mockReturnValue(
// Override the get locale so we control what the input is "desiredLocale",
vi.spyOn(localeService, "getPlatformForServerLocale").mockReturnValue( );
"desiredLocale"
); localeService.localeConfig.serverLocale = "system";
localeService.localeConfig.serverLocale = "system"; expect(localeService.getDesiredServerLocale()).toBe("desiredLocale");
});
expect(localeService.getDesiredServerLocale()).toBe("desiredLocale"); });
});
})
describe("getPlatformForServerLocale", () => describe("getPlatformForServerLocale", () =>
{ {
@ -84,7 +84,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
undefined undefined,
); );
const warningLogSpy = vi.spyOn(localeService.logger, "warning"); const warningLogSpy = vi.spyOn(localeService.logger, "warning");
@ -94,16 +94,16 @@ describe("LocaleService", () =>
}); });
it("should return 'en' when unsupported system local encountered and display warning'", () => it("should return 'en' when unsupported system local encountered and display warning'", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
{ baseName: "test_locale_that_doesnt_exist", language: "test_language" } { baseName: "test_locale_that_doesnt_exist", language: "test_language" },
); );
const warningLogSpy = vi.spyOn(localeService.logger, "warning") const warningLogSpy = vi.spyOn(localeService.logger, "warning");
expect(localeService.getPlatformForServerLocale()).toBe("en"); expect(localeService.getPlatformForServerLocale()).toBe("en");
expect(warningLogSpy).toHaveBeenCalledTimes(1); expect(warningLogSpy).toHaveBeenCalledTimes(1);
}); });
}); });
@ -113,26 +113,26 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
undefined undefined,
); );
const warningLogSpy = vi.spyOn(localeService.logger, "warning") const warningLogSpy = vi.spyOn(localeService.logger, "warning");
expect(localeService.getPlatformForClientLocale()).toBe("en"); expect(localeService.getPlatformForClientLocale()).toBe("en");
expect(warningLogSpy).toHaveBeenCalledTimes(1); expect(warningLogSpy).toHaveBeenCalledTimes(1);
}); });
it("should return 'en' when unsupported platform local encountered and display warning'", () => it("should return 'en' when unsupported platform local encountered and display warning'", () =>
{
// Override the get locale so we control what the input is
localeService.getPlatformLocale = () =>
{ {
// Override the get locale so we control what the input is return { baseName: "test_locale_that_doesnt_exist", language: "test_language" };
localeService.getPlatformLocale = () => };
{
return { baseName: "test_locale_that_doesnt_exist", language: "test_language" };
};
const warningLogSpy = vi.spyOn(localeService.logger, "warning") const warningLogSpy = vi.spyOn(localeService.logger, "warning");
expect(localeService.getPlatformForClientLocale()).toBe("en"); expect(localeService.getPlatformForClientLocale()).toBe("en");
expect(warningLogSpy).toHaveBeenCalledTimes(1); expect(warningLogSpy).toHaveBeenCalledTimes(1);
}); });
}); });
@ -142,7 +142,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("en-US") new Intl.Locale("en-US"),
); );
expect(localeService.getPlatformForServerLocale()).toBe("en"); expect(localeService.getPlatformForServerLocale()).toBe("en");
@ -152,7 +152,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("ko-KR") new Intl.Locale("ko-KR"),
); );
expect(localeService.getPlatformForServerLocale()).toBe("ko"); expect(localeService.getPlatformForServerLocale()).toBe("ko");
@ -162,7 +162,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("pt-PT") new Intl.Locale("pt-PT"),
); );
expect(localeService.getPlatformForServerLocale()).toBe("pt-pt"); expect(localeService.getPlatformForServerLocale()).toBe("pt-pt");
@ -172,7 +172,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("pt-BR") new Intl.Locale("pt-BR"),
); );
expect(localeService.getPlatformForServerLocale()).toBe("pt-br"); expect(localeService.getPlatformForServerLocale()).toBe("pt-br");
@ -185,7 +185,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("en-US") new Intl.Locale("en-US"),
); );
expect(localeService.getPlatformForClientLocale()).toBe("en"); expect(localeService.getPlatformForClientLocale()).toBe("en");
@ -195,7 +195,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("ko-KR") new Intl.Locale("ko-KR"),
); );
expect(localeService.getPlatformForClientLocale()).toBe("kr"); expect(localeService.getPlatformForClientLocale()).toBe("kr");
@ -205,7 +205,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("es-MX") new Intl.Locale("es-MX"),
); );
expect(localeService.getPlatformForClientLocale()).toBe("es-mx"); expect(localeService.getPlatformForClientLocale()).toBe("es-mx");
@ -215,7 +215,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("cs-CZ") new Intl.Locale("cs-CZ"),
); );
expect(localeService.getPlatformForClientLocale()).toBe("cz"); expect(localeService.getPlatformForClientLocale()).toBe("cz");
@ -225,7 +225,7 @@ describe("LocaleService", () =>
{ {
// Override the get locale so we control what the input is // Override the get locale so we control what the input is
vi.spyOn(localeService, "getPlatformLocale").mockReturnValue( vi.spyOn(localeService, "getPlatformLocale").mockReturnValue(
new Intl.Locale("de-DE") new Intl.Locale("de-DE"),
); );
expect(localeService.getPlatformForClientLocale()).toBe("ge"); expect(localeService.getPlatformForClientLocale()).toBe("ge");