From d9b89a7de95979f51be56c57c44af7747ba6dc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 18 Mar 2024 15:57:13 +0200 Subject: [PATCH] Rename ThunderstorePackages to Deprecations All remaining code deals with calculating the deprecation status of packages based on the status of their dependencies, so the new name is more descriptive. The methods remain wrapped in a class to make it easier to spy on them in Jest test cases. --- src/store/modules/TsModsModule.ts | 4 +-- .../Deprecations.ts} | 4 +-- .../utils.getDeprecatedPackageMap.ts.spec.ts | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) rename src/{r2mm/data/ThunderstorePackages.ts => utils/Deprecations.ts} (97%) diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 0e99d7c2e..4abedc59e 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -6,7 +6,7 @@ import ThunderstoreCombo from '../../model/ThunderstoreCombo'; import ThunderstoreMod from '../../model/ThunderstoreMod'; import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider'; import * as PackageDb from '../../r2mm/manager/PackageDexieStore'; -import ThunderstorePackages from '../../r2mm/data/ThunderstorePackages'; +import { Deprecations } from '../../utils/Deprecations'; interface CachedMod { tsMod: ThunderstoreMod | undefined; @@ -126,7 +126,7 @@ export const TsModsModule = { state.exclusions = payload; }, updateDeprecated(state, allMods: ThunderstoreMod[]) { - state.deprecated = ThunderstorePackages.getDeprecatedPackageMap(allMods); + state.deprecated = Deprecations.getDeprecatedPackageMap(allMods); } }, diff --git a/src/r2mm/data/ThunderstorePackages.ts b/src/utils/Deprecations.ts similarity index 97% rename from src/r2mm/data/ThunderstorePackages.ts rename to src/utils/Deprecations.ts index 886e6e85b..fdcb02d85 100644 --- a/src/r2mm/data/ThunderstorePackages.ts +++ b/src/utils/Deprecations.ts @@ -1,6 +1,6 @@ -import ThunderstoreMod from '../../model/ThunderstoreMod'; +import ThunderstoreMod from '../model/ThunderstoreMod'; -export default class ThunderstorePackages { +export class Deprecations { public static getDeprecatedPackageMap(packages: ThunderstoreMod[]): Map { const packageMap = packages.reduce((map, pkg) => { diff --git a/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts b/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts index 2d1682c73..2d8b3bc42 100644 --- a/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts +++ b/test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts @@ -1,12 +1,12 @@ import ThunderstoreMod from "../../../../src/model/ThunderstoreMod"; import ThunderstoreVersion from "../../../../src/model/ThunderstoreVersion"; -import ThunderstorePackages from "../../../../src/r2mm/data/ThunderstorePackages"; +import { Deprecations } from "../../../../src/utils/Deprecations"; -describe("ThunderstorePackages.getDeprecatedPackageMap", () => { +describe("Deprecations.getDeprecatedPackageMap", () => { let spyedPopulator: jest.SpyInstance; beforeEach(() => { - spyedPopulator = jest.spyOn(ThunderstorePackages, '_populateDeprecatedPackageMapForModChain'); + spyedPopulator = jest.spyOn(Deprecations, '_populateDeprecatedPackageMapForModChain'); }); afterEach(() => { @@ -21,7 +21,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('TeamC-Mod1') ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); expect(actual.size).toBe(4); expect(actual.get('TeamA-Mod1')).toStrictEqual(false); @@ -38,7 +38,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('TeamC-Mod1') ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); expect(actual.size).toBe(4); expect(actual.get('TeamA-Mod1')).toStrictEqual(true); @@ -53,7 +53,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('Degrec-Alfie_Other_Knee', false, ['Degrec-Alfie_Knee']), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); expect(actual.size).toBe(2); expect(actual.get('Degrec-Alfie_Knee')).toStrictEqual(false); @@ -67,7 +67,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('Loop1-Mod3', false, ['Loop1-Mod1']), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); expect(actual.size).toBe(3); expect(actual.get('Loop1-Mod1')).toStrictEqual(false); @@ -83,7 +83,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('Loop2-Mod4', false, ['Loop2-Mod2']), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); expect(actual.size).toBe(4); expect(actual.get('Loop2-Mod1')).toStrictEqual(true); @@ -102,7 +102,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('X-ChainBottom'), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); // Each mod causes one call due to for-loop (6 calls). // Root1 causes three recursive calls down the chain (total 9 calls). @@ -129,7 +129,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('X-Root3', false, ['X-ChainTop']), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); // Each mod causes one call due to for-loop (6 calls). // Excluding ChainBottom, each mod should recursively call their @@ -154,7 +154,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('X-ChainBottom'), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); // Each mod causes one call due to for-loop (6 calls). // Each root mod recursively calls X-ChainTop, but the chain is @@ -180,7 +180,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('X-Root3', false, ['X-ChainTop']), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); // Each mod causes one call due to for-loop (6 calls). // Each mod recursively calls it's direct dependency, except for @@ -202,7 +202,7 @@ describe("ThunderstorePackages.getDeprecatedPackageMap", () => { createStubMod('Known-Mod2'), ]; - const actual = ThunderstorePackages.getDeprecatedPackageMap(mods); + const actual = Deprecations.getDeprecatedPackageMap(mods); // Both known mods cause one call due to for-loop (2 calls). // Known-Mod1 causes 1 recursive call (total 3 calls).