Skip to content

Commit

Permalink
Merge branch 'main' into feature/remove-standalone-mods-phase-5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Loe committed Sep 17, 2024
2 parents 4e00e76 + e05acf0 commit 82e438a
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 152 deletions.
168 changes: 84 additions & 84 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@datadog/browser-logs": "^5.26.0",
"@datadog/browser-rum": "^5.26.0",
"@deepgram/sdk": "^3.6.0",
"@floating-ui/dom": "^1.6.10",
"@floating-ui/dom": "^1.6.11",
"@fortawesome/fontawesome-svg-core": "1.2.36",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-regular-svg-icons": "^5.15.4",
Expand Down Expand Up @@ -107,7 +107,7 @@
"kbar": "^0.1.0-beta.45",
"lodash-es": "^4.17.21",
"mark.js": "^8.11.1",
"marked": "^14.1.1",
"marked": "^14.1.2",
"memoize-one": "^6.0.0",
"mustache": "^4.2.0",
"nunjucks": "^3.2.4",
Expand All @@ -133,7 +133,7 @@
"react-draggable": "^4.4.6",
"react-hot-toast": "^2.4.1",
"react-hotkeys": "^2.0.0",
"react-image-crop": "^11.0.6",
"react-image-crop": "^11.0.7",
"react-json-tree": "^0.19.0",
"react-outside-click-handler": "^1.3.0",
"react-redux": "^7.2.4",
Expand Down Expand Up @@ -183,26 +183,26 @@
"devDependencies": {
"@axe-core/playwright": "^4.10.0",
"@fortawesome/fontawesome-common-types": "^0.2.36",
"@playwright/test": "^1.47.0",
"@playwright/test": "^1.47.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@shopify/jest-dom-mocks": "^5.2.0",
"@sindresorhus/tsconfig": "^6.0.0",
"@sinonjs/fake-timers": "^13.0.1",
"@sinonjs/fake-timers": "^13.0.2",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-storyshots": "^7.6.17",
"@storybook/react": "^7.6.17",
"@storybook/react-webpack5": "^7.6.17",
"@svgr/webpack": "^8.1.0",
"@swc/core": "^1.7.24",
"@swc/core": "^1.7.26",
"@swc/jest": "^0.2.36",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@total-typescript/ts-reset": "^0.6.1",
"@types/chrome": "^0.0.270",
"@types/chrome": "^0.0.271",
"@types/diff": "^5.2.2",
"@types/dom-navigation": "^1.0.4",
"@types/dompurify": "^3.0.5",
Expand All @@ -225,7 +225,7 @@
"@types/lodash": "^4.17.7",
"@types/mark.js": "^8.11.12",
"@types/mustache": "^4.2.5",
"@types/node": "^22.5.4",
"@types/node": "^22.5.5",
"@types/nunjucks": "^3.2.6",
"@types/object-hash": "^2.1.1",
"@types/papaparse": "^5.3.14",
Expand Down
201 changes: 200 additions & 1 deletion src/activation/useActivateMod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { type WizardValues } from "@/activation/wizardTypes";
import { renderHook } from "@/pageEditor/testHelpers";
import useActivateMod from "./useActivateMod";
import { validateRegistryId } from "@/types/helpers";
import { uuidv4, validateRegistryId } from "@/types/helpers";
import { type StarterBrickDefinitionLike } from "@/starterBricks/types";
import { type ContextMenuDefinition } from "@/starterBricks/contextMenu/contextMenuTypes";
import { deactivateMod } from "@/store/deactivateUtils";
Expand All @@ -41,8 +41,17 @@ import { appApiMock } from "@/testUtils/appApiMock";
import type MockAdapter from "axios-mock-adapter";
import { StarterBrickTypes } from "@/types/starterBrickTypes";
import { API_PATHS } from "@/data/service/urlPaths";
import { waitForEffect } from "@/testUtils/testHelpers";
import { editablePackageMetadataFactory } from "@/testUtils/factories/registryFactories";
import notify from "@/utils/notify";
import {
type Deployment,
type EditablePackageMetadata,
} from "@/types/contract";

jest.mock("@/contentScript/messenger/api");
jest.mock("@/utils/notify");
const mockedNotifyError = jest.mocked(notify.error);

const checkPermissionsMock = jest.mocked(checkModDefinitionPermissions);
const deactivateModMock = jest.mocked(deactivateMod);
Expand Down Expand Up @@ -109,6 +118,7 @@ function setUserAcceptedPermissions(accepted: boolean) {
describe("useActivateMod", () => {
beforeEach(() => {
reactivateEveryTabMock.mockClear();
appApiMock.reset();
});

it("returns error if permissions are not granted", async () => {
Expand Down Expand Up @@ -332,4 +342,193 @@ describe("useActivateMod", () => {
expect(success).toBe(false);
expect(error).toBe(errorMessage);
});

describe("personal deployment functionality", () => {
const packageVersionId = "package-version-id";
const testDeployment = {
id: uuidv4(),
name: "test-user-deployment",
} as Deployment;
let formValues: WizardValues;
let editablePackage: EditablePackageMetadata;
let modDefinition: ModDefinition;

beforeEach(() => {
({ formValues, modDefinition } = setupInputs());

setModHasPermissions(true);
setUserAcceptedPermissions(true);

editablePackage = editablePackageMetadataFactory({
name: modDefinition.metadata.id,
});
});

it("handles personal deployment creation successfully", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(200, [editablePackage]);
appApiMock
.onGet(API_PATHS.BRICK_VERSIONS(editablePackage.id))
.reply(200, [
{ id: packageVersionId, version: modDefinition.metadata.version },
]);
appApiMock.onPost(API_PATHS.USER_DEPLOYMENTS).reply(201, testDeployment);

const { result, getReduxStore } = renderHook(
() => useActivateMod("marketplace"),
{
setupRedux(_dispatch, { store }) {
jest.spyOn(store, "dispatch");
},
},
);

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

const { dispatch } = getReduxStore();

expect(dispatch).toHaveBeenCalledWith(
modComponentSlice.actions.activateMod({
modDefinition,
configuredDependencies: [],
optionsArgs: formValues.optionsArgs,
screen: "marketplace",
isReactivate: false,
deployment: testDeployment,
}),
);

expect(
JSON.parse(
appApiMock.history.post!.find(
(request) => request.url === API_PATHS.USER_DEPLOYMENTS,
)!.data,
),
).toEqual({
package_version: packageVersionId,
name: `Personal deployment for ${modDefinition.metadata.name}, version ${modDefinition.metadata.version}`,
services: [],
options_config: formValues.optionsArgs,
});
});

it("notifies error when personal deployment was not created due to missing package", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(200, []);

const { result } = renderHook(() => useActivateMod("marketplace"));
await waitForEffect();

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

expect(mockedNotifyError).toHaveBeenCalledWith({
message: `Error setting up device synchronization for ${modDefinition.metadata.name}. Please try reactivating.`,
error: new Error(
`Failed to find editable package for mod: ${modDefinition.metadata.id}`,
),
});
});

it("notifies error when personal deployment was not created due to failed package call", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(500);

const { result } = renderHook(() => useActivateMod("marketplace"));

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

expect(mockedNotifyError).toHaveBeenCalledWith({
message: `Error setting up device synchronization for ${modDefinition.metadata.name}. Please try reactivating.`,
error: expect.objectContaining({
message: "Request failed with status code 500",
}),
});
});

it("notifies error when personal deployment was not created due to missing package version", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(200, [editablePackage]);
appApiMock
.onGet(API_PATHS.BRICK_VERSIONS(editablePackage.id))
.reply(200, []);

const { result } = renderHook(() => useActivateMod("marketplace"));

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

expect(mockedNotifyError).toHaveBeenCalledWith({
message: `Error setting up device synchronization for ${modDefinition.metadata.name}. Please try reactivating.`,
error: new Error("Failed to find package version: 1.0.0"),
});
});

it("notifies error when personal deployment was not created due to failed package versions call", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(200, [editablePackage]);
appApiMock.onGet(API_PATHS.BRICK_VERSIONS(editablePackage.id)).reply(500);

const { result } = renderHook(() => useActivateMod("marketplace"));

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

expect(mockedNotifyError).toHaveBeenCalledWith({
message: `Error setting up device synchronization for ${modDefinition.metadata.name}. Please try reactivating.`,
error: expect.objectContaining({
message: "Request failed with status code 500",
}),
});
});

it("notifies error when personal deployment was not created due to failed deployment call", async () => {
appApiMock.onGet(API_PATHS.BRICKS).reply(200, [editablePackage]);
appApiMock
.onGet(API_PATHS.BRICK_VERSIONS(editablePackage.id))
.reply(200, [
{ id: packageVersionId, version: modDefinition.metadata.version },
]);
appApiMock.onPost(API_PATHS.USER_DEPLOYMENTS).reply(500);

const { result } = renderHook(() => useActivateMod("marketplace"));

const { success, error } = await result.current(
{ ...formValues, personalDeployment: true },
modDefinition,
);

expect(success).toBe(true);
expect(error).toBeUndefined();

expect(mockedNotifyError).toHaveBeenCalledWith({
message: `Error setting up device synchronization for ${modDefinition.metadata.name}. Please try reactivating.`,
error: expect.objectContaining({
message: "Request failed with status code 500",
}),
});
});
});
});
Loading

0 comments on commit 82e438a

Please sign in to comment.