2022-07-04 14:05:55 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-07-04 14:05:55 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-07-04 14:05:55 +00:00
|
|
|
*/
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import { EventType, MatrixEvent, MsgType } from "matrix-js-sdk/src/matrix";
|
2022-07-04 14:05:55 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { getShareableLocationEvent } from "../../../../src/events";
|
2022-07-04 14:05:55 +00:00
|
|
|
import {
|
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
makeBeaconEvent,
|
|
|
|
makeBeaconInfoEvent,
|
|
|
|
makeLocationEvent,
|
|
|
|
makeRoomWithBeacons,
|
2024-10-15 13:57:26 +00:00
|
|
|
} from "../../../test-utils";
|
2022-07-04 14:05:55 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("getShareableLocationEvent()", () => {
|
|
|
|
const userId = "@alice:server.org";
|
|
|
|
const roomId = "!room:server.org";
|
2022-07-04 14:05:55 +00:00
|
|
|
const client = getMockClientWithEventEmitter({
|
|
|
|
getRoom: jest.fn(),
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns null for a non-location event", () => {
|
2022-07-04 14:05:55 +00:00
|
|
|
const alicesMessageEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
2022-12-12 11:24:14 +00:00
|
|
|
body: "Hello",
|
2022-07-04 14:05:55 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getShareableLocationEvent(alicesMessageEvent, client)).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns the event for a location event", () => {
|
|
|
|
const locationEvent = makeLocationEvent("geo:52,42");
|
2022-07-04 14:05:55 +00:00
|
|
|
|
|
|
|
expect(getShareableLocationEvent(locationEvent, client)).toBe(locationEvent);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("beacons", () => {
|
|
|
|
it("returns null for a beacon that is not live", () => {
|
2022-07-04 14:05:55 +00:00
|
|
|
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
|
|
|
makeRoomWithBeacons(roomId, client, [notLiveBeacon]);
|
|
|
|
|
|
|
|
expect(getShareableLocationEvent(notLiveBeacon, client)).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns null for a live beacon that does not have a location", () => {
|
2022-07-04 14:05:55 +00:00
|
|
|
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true });
|
|
|
|
makeRoomWithBeacons(roomId, client, [liveBeacon]);
|
|
|
|
|
|
|
|
expect(getShareableLocationEvent(liveBeacon, client)).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("returns the latest location event for a live beacon with location", () => {
|
|
|
|
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true }, "id");
|
2022-07-04 14:05:55 +00:00
|
|
|
const locationEvent = makeBeaconEvent(userId, {
|
|
|
|
beaconInfoId: liveBeacon.getId(),
|
2022-12-12 11:24:14 +00:00
|
|
|
geoUri: "geo:52,42",
|
2022-07-04 14:05:55 +00:00
|
|
|
// make sure its in live period
|
|
|
|
timestamp: Date.now() + 1,
|
|
|
|
});
|
|
|
|
makeRoomWithBeacons(roomId, client, [liveBeacon], [locationEvent]);
|
|
|
|
|
|
|
|
expect(getShareableLocationEvent(liveBeacon, client)).toBe(locationEvent);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|