Skip to content

Commit

Permalink
Rename _recipe and _deployment fields on ModComponent (#9253)
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller authored Oct 9, 2024
1 parent 986ba71 commit 6012381
Show file tree
Hide file tree
Showing 61 changed files with 451 additions and 345 deletions.
2 changes: 1 addition & 1 deletion end-to-end-tests/pageObjects/pageEditor/pageEditorPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PageEditorPage extends BasePageObject {
}

/**
* Save the current active mod. Prefer saveStandaloneMod for standalone mods.
* Save the current active mod
*/
async saveActiveMod() {
// TODO: this method is currently meant for mods that aren't meant to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function mapModComponentDefinitionToActivatedModComponent<
id: uuidv4(),
// Default to `v1` for backward compatability
apiVersion: modDefinition.apiVersion ?? "v1",
_recipe: pickModDefinitionMetadata(modDefinition),
modMetadata: pickModDefinitionMetadata(modDefinition),
// Definitions are pushed down into the mod components. That's OK because `resolveDefinitions` determines
// uniqueness based on the content of the definition. Therefore, bricks will be re-used as necessary
definitions: modDefinition.definitions ?? {},
Expand All @@ -99,7 +99,7 @@ export function mapModComponentDefinitionToActivatedModComponent<
// here makes testing harder because we then have to account for the normalized value in assertions.

if (deployment) {
activatedModComponent._deployment = {
activatedModComponent.deploymentMetadata = {
id: deployment.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- This should be defined in practice
timestamp: deployment.updated_at!,
Expand Down
39 changes: 20 additions & 19 deletions src/background/deploymentUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ describe("syncDeployments", () => {
// A mod without a deployment. Exclude _deployment entirely to handle the case where the property is missing
const manualModComponent = activatedModComponentFactory({
extensionPointId: starterBrick.metadata!.id,
_recipe: modMetadataFactory(),
modMetadata: modMetadataFactory(),
});
delete manualModComponent._deployment;
delete manualModComponent.deploymentMetadata;

await saveModComponentState({
activatedModComponents: [manualModComponent],
Expand Down Expand Up @@ -433,17 +433,16 @@ describe("syncDeployments", () => {
const { deployment, modDefinition } = activatableDeploymentFactory();
const registryId = deployment.package.package_id;

// A mod component without a recipe. Exclude _recipe entirely to handle the case where the property is missing
const modComponent = modComponentFactory({
_recipe: {
const modComponent = activatedModComponentFactory({
deploymentMetadata: undefined,
modMetadata: {
id: deployment.package.package_id,
name: deployment.package.name,
version: normalizeSemVerString("0.0.1"),
updated_at: deployment.updated_at!,
sharing: personalSharingDefinitionFactory(),
},
}) as ActivatedModComponent;
delete modComponent._deployment;
});

await saveModComponentState({
activatedModComponents: [modComponent],
Expand All @@ -466,7 +465,7 @@ describe("syncDeployments", () => {

const { activatedModComponents } = await getModComponentState();
expect(activatedModComponents).toBeArrayOfSize(1);
expect(activatedModComponents[0]!._recipe!.version).toBe(
expect(activatedModComponents[0]!.modMetadata.version).toBe(
deployment.package.version,
);
});
Expand All @@ -484,18 +483,17 @@ describe("syncDeployments", () => {
};
registryFindMock.mockResolvedValue(brick);

// A mod component without a recipe. Exclude _recipe entirely to handle the case where the property is missing
const modComponent = modComponentFactory({
const modComponent = activatedModComponentFactory({
extensionPointId: starterBrick.metadata!.id,
_recipe: {
deploymentMetadata: undefined,
modMetadata: {
id: deployment.package.package_id,
name: deployment.package.name,
version: normalizeSemVerString("0.0.1"),
updated_at: deployment.updated_at!,
sharing: personalSharingDefinitionFactory(),
},
}) as ActivatedModComponent;
delete modComponent._deployment;
});

await saveModComponentState({
activatedModComponents: [modComponent],
Expand Down Expand Up @@ -527,7 +525,7 @@ describe("syncDeployments", () => {
const { modComponentFormStates } = (await getEditorState()) ?? {};
// Expect draft mod component to be removed
expect(modComponentFormStates).toBeArrayOfSize(0);
expect(activatedModComponents[0]!._recipe!.version).toBe(
expect(activatedModComponents[0]!.modMetadata.version).toBe(
deployment.package.version,
);
});
Expand Down Expand Up @@ -761,7 +759,7 @@ describe("syncDeployments", () => {
};

const manuallyActivatedModComponent = activatedModComponentFactory({
_recipe: modMetadataFactory(),
modMetadata: modMetadataFactory(),
});

const deploymentStarterBrickDefinition = starterBrickDefinitionFactory();
Expand All @@ -774,8 +772,11 @@ describe("syncDeployments", () => {

const deploymentModComponent = modComponentFactory({
extensionPointId: deploymentStarterBrickDefinition.metadata!.id,
_deployment: { id: uuidv4(), timestamp: "2021-10-07T12:52:16.189Z" },
_recipe: modMetadataFactory(),
deploymentMetadata: {
id: uuidv4(),
timestamp: "2021-10-07T12:52:16.189Z",
},
modMetadata: modMetadataFactory(),
}) as ActivatedModComponent;

registryFindMock.mockImplementation(async (id) => {
Expand Down Expand Up @@ -863,7 +864,7 @@ describe("syncDeployments", () => {
await syncDeployments();
const { activatedModComponents } = await getModComponentState();
expect(activatedModComponents).toHaveLength(1);
expect(activatedModComponents[0]!._recipe!.id).toBe(
expect(activatedModComponents[0]!.modMetadata.id).toBe(
deployment.package.package_id,
);

Expand Down Expand Up @@ -894,7 +895,7 @@ describe("syncDeployments", () => {
const { activatedModComponents: expectedModComponents } =
await getModComponentState();
expect(expectedModComponents).toHaveLength(1);
expect(expectedModComponents[0]!._recipe!.id).toBe(
expect(expectedModComponents[0]!.modMetadata.id).toBe(
updatedDeployment.package.package_id,
);
});
Expand Down
50 changes: 27 additions & 23 deletions src/background/modUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import type { ModDefinition } from "@/types/modDefinitionTypes";
import type { ActivatedModComponent } from "@/types/modComponentTypes";
import { uninstallContextMenu } from "@/background/contextMenus/uninstallContextMenu";
import { TEST_deleteFeatureFlagsCache } from "@/auth/featureFlagStorage";
import {
personalDeploymentMetadataFactory,
teamDeploymentMetadataFactory,
} from "@/testUtils/factories/modInstanceFactories";

const axiosMock = new MockAdapter(axios);
jest.mock("@/telemetry/reportError");
Expand All @@ -69,29 +73,29 @@ describe("getActivatedMarketplaceModVersions function", () => {
await saveModComponentState({ activatedModComponents: [] });

publicActivatedMod = activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: publicSharingDefinitionFactory(),
}),
});

privateActivatedMod = activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: personalSharingDefinitionFactory(),
}),
});

publicActivatedDeployment = activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: publicSharingDefinitionFactory(),
}),
_deployment: {} as ActivatedModComponent["_deployment"],
deploymentMetadata: teamDeploymentMetadataFactory(),
});

privateActivatedDeployment = activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: personalSharingDefinitionFactory(),
}),
_deployment: {} as ActivatedModComponent["_deployment"],
deploymentMetadata: personalDeploymentMetadataFactory(),
});
});

Expand All @@ -113,15 +117,15 @@ describe("getActivatedMarketplaceModVersions function", () => {
const result = await getActivatedMarketplaceModVersions();
expect(result).toEqual([
{
name: publicActivatedMod._recipe!.id,
version: publicActivatedMod._recipe!.version,
name: publicActivatedMod.modMetadata.id,
version: publicActivatedMod.modMetadata.version,
},
]);
});

it("returns expected object with registry id keys and version number values", async () => {
const anotherPublicActivatedMod = activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: publicSharingDefinitionFactory(),
}),
});
Expand All @@ -134,12 +138,12 @@ describe("getActivatedMarketplaceModVersions function", () => {

expect(result).toEqual([
{
name: publicActivatedMod._recipe!.id,
version: publicActivatedMod._recipe!.version,
name: publicActivatedMod.modMetadata.id,
version: publicActivatedMod.modMetadata.version,
},
{
name: anotherPublicActivatedMod._recipe!.id,
version: anotherPublicActivatedMod._recipe!.version,
name: anotherPublicActivatedMod.modMetadata.id,
version: anotherPublicActivatedMod.modMetadata.version,
},
]);
});
Expand All @@ -151,12 +155,12 @@ describe("fetchModUpdates function", () => {
beforeEach(async () => {
activatedMods = [
activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: publicSharingDefinitionFactory(),
}),
}),
activatedModComponentFactory({
_recipe: modMetadataFactory({
modMetadata: modMetadataFactory({
sharing: publicSharingDefinitionFactory(),
}),
}),
Expand All @@ -176,12 +180,12 @@ describe("fetchModUpdates function", () => {
expect(payload).toEqual({
versions: [
{
name: activatedMods[0]!._recipe!.id,
version: activatedMods[0]!._recipe!.version,
name: activatedMods[0]!.modMetadata.id,
version: activatedMods[0]!.modMetadata.version,
},
{
name: activatedMods[1]!._recipe!.id,
version: activatedMods[1]!._recipe!.version,
name: activatedMods[1]!.modMetadata.id,
version: activatedMods[1]!.modMetadata.version,
},
],
});
Expand All @@ -205,10 +209,10 @@ describe("updateMod function", () => {
beforeEach(async () => {
const modToDeactivate = modMetadataFactory(modToUpdate.metadata);
modComponentToDeactivate1 = activatedModComponentFactory({
_recipe: modToDeactivate,
modMetadata: modToDeactivate,
});
modComponentToDeactivate2 = activatedModComponentFactory({
_recipe: modToDeactivate,
modMetadata: modToDeactivate,
});
const anotherMod = modMetadataFactory({});

Expand All @@ -217,7 +221,7 @@ describe("updateMod function", () => {
modComponentToDeactivate1,
modComponentToDeactivate2,
activatedModComponentFactory({
_recipe: anotherMod,
modMetadata: anotherMod,
}),
],
});
Expand Down Expand Up @@ -339,7 +343,7 @@ describe("updateModsIfUpdatesAvailable", () => {
const resultingOptionsState = await getModComponentState();
expect(resultingOptionsState.activatedModComponents).toHaveLength(1);
expect(
resultingOptionsState.activatedModComponents[0]!._recipe!.version,
resultingOptionsState.activatedModComponents[0]!.modMetadata.version,
).toBe("2.0.1");
});
});
4 changes: 2 additions & 2 deletions src/background/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { compact, debounce, throttle, uniq } from "lodash";
import { debounce, throttle, uniq } from "lodash";
import { getModComponentState } from "@/store/modComponents/modComponentStorage";
import {
getLinkedApiClient,
Expand Down Expand Up @@ -294,7 +294,7 @@ async function collectUserSummary(): Promise<UserSummary> {
const { activatedModComponents } = await getModComponentState();
numActiveExtensions = activatedModComponents.length;
numActiveBlueprints = uniq(
compact(activatedModComponents.map((x) => x._recipe?.id)),
activatedModComponents.map((x) => x.modMetadata.id),
).length;
numActiveExtensionPoints = uniq(
activatedModComponents.map((x) => x.extensionPointId),
Expand Down
4 changes: 2 additions & 2 deletions src/background/utils/deactivateMod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("deactivateMod", () => {
activatedModComponents: [
...mapModInstanceToActivatedModComponents(modToDeactivate),
activatedModComponentFactory({
_recipe: anotherMod,
modMetadata: anotherMod,
}),
],
});
Expand All @@ -60,7 +60,7 @@ describe("deactivateMod", () => {

expect(nextModComponentState.activatedModComponents).toHaveLength(1);
expect(
nextModComponentState.activatedModComponents[0]!._recipe!.id,
nextModComponentState.activatedModComponents[0]!.modMetadata.id,
).not.toEqual(modToDeactivate.definition.metadata.id);
});
});
Loading

0 comments on commit 6012381

Please sign in to comment.