1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

Pass analyticsID to the elementCall iFrame (#9637)

Co-authored-by: Robin <robin@robin.town>
Co-authored-by: Timo K <timok@element.io>
This commit is contained in:
Timo
2022-12-22 13:09:57 +01:00
committed by GitHub
parent b81582d045
commit ce75d3381f
4 changed files with 63 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Widget } from "matrix-widget-api";
import { GroupCallIntent } from "matrix-js-sdk/src/webrtc/groupCall";
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { Mocked } from "jest-mock";
import type { MatrixClient, IMyDevice } from "matrix-js-sdk/src/client";
@ -40,6 +41,7 @@ import { ElementWidgetActions } from "../../src/stores/widgets/ElementWidgetActi
import SettingsStore from "../../src/settings/SettingsStore";
import Modal, { IHandle } from "../../src/Modal";
import PlatformPeg from "../../src/PlatformPeg";
import { PosthogAnalytics } from "../../src/PosthogAnalytics";
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
[MediaDeviceKindEnum.AudioInput]: [
@ -622,6 +624,53 @@ describe("ElementCall", () => {
SettingsStore.getValue = originalGetValue;
});
it("passes analyticsID through widget URL", async () => {
client.getAccountData.mockImplementation((eventType: string) => {
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
return new MatrixEvent({ content: { id: "123456789987654321", pseudonymousAnalyticsOptIn: true } });
}
return undefined;
});
await ElementCall.create(room);
const call = Call.get(room);
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
expect(urlParams.get("analyticsID")).toBe("123456789987654321");
});
it("does not pass analyticsID if `pseudonymousAnalyticsOptIn` set to false", async () => {
client.getAccountData.mockImplementation((eventType: string) => {
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
return new MatrixEvent({
content: { id: "123456789987654321", pseudonymousAnalyticsOptIn: false },
});
}
return undefined;
});
await ElementCall.create(room);
const call = Call.get(room);
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
expect(urlParams.get("analyticsID")).toBe("");
});
it("passes empty analyticsID if the id is not in the account data", async () => {
client.getAccountData.mockImplementation((eventType: string) => {
if (eventType === PosthogAnalytics.ANALYTICS_EVENT_TYPE) {
return new MatrixEvent({ content: {} });
}
return undefined;
});
await ElementCall.create(room);
const call = Call.get(room);
if (!(call instanceof ElementCall)) throw new Error("Failed to create call");
const urlParams = new URLSearchParams(new URL(call.widget.url).hash.slice(1));
expect(urlParams.get("analyticsID")).toBe("");
});
});
describe("instance in a non-video room", () => {

View File

@ -136,7 +136,7 @@ export function createTestClient(): MatrixClient {
getTurnServers: jest.fn().mockReturnValue([]),
getTurnServersExpiry: jest.fn().mockReturnValue(2 ^ 32),
getThirdpartyUser: jest.fn().mockResolvedValue([]),
getAccountData: (type) => {
getAccountData: jest.fn().mockImplementation((type) => {
return mkEvent({
user: undefined,
room: undefined,
@ -144,7 +144,7 @@ export function createTestClient(): MatrixClient {
event: true,
content: {},
});
},
}),
mxcUrlToHttp: (mxc) => `http://this.is.a.url/${mxc.substring(6)}`,
setAccountData: jest.fn(),
setRoomAccountData: jest.fn(),