You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
* remove M_BEACON_INFO_VARIABLE Signed-off-by: Kerry Archibald <kerrya@element.io> * create beacon_info events with non-variable event type Signed-off-by: Kerry Archibald <kerrya@element.io> * remove isBeaconInfoEventType Signed-off-by: Kerry Archibald <kerrya@element.io> * refer to msc3673 instead of msc3489 Signed-off-by: Kerry Archibald <kerrya@element.io> * remove event type suffix Signed-off-by: Kerry Archibald <kerrya@element.io> * update beacon identifier to use state key Signed-off-by: Kerry Archibald <kerrya@element.io> * fix beacon spec Signed-off-by: Kerry Archibald <kerrya@element.io> * fix room-state tests Signed-off-by: Kerry Archibald <kerrya@element.io> * add beacon identifier Signed-off-by: Kerry Archibald <kerrya@element.io> * dont allow update to older beacon event Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * unnest beacon_info content Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * check redaction event id Signed-off-by: Kerry Archibald <kerrya@element.io>
125 lines
3.9 KiB
TypeScript
125 lines
3.9 KiB
TypeScript
/*
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { REFERENCE_RELATION } from "matrix-events-sdk";
|
|
|
|
import { LocationAssetType, M_ASSET, M_LOCATION, M_TIMESTAMP } from "../../src/@types/location";
|
|
import { makeBeaconContent, makeBeaconInfoContent } from "../../src/content-helpers";
|
|
|
|
describe('Beacon content helpers', () => {
|
|
describe('makeBeaconInfoContent()', () => {
|
|
const mockDateNow = 123456789;
|
|
beforeEach(() => {
|
|
jest.spyOn(global.Date, 'now').mockReturnValue(mockDateNow);
|
|
});
|
|
afterAll(() => {
|
|
jest.spyOn(global.Date, 'now').mockRestore();
|
|
});
|
|
it('create fully defined event content', () => {
|
|
expect(makeBeaconInfoContent(
|
|
1234,
|
|
true,
|
|
'nice beacon_info',
|
|
LocationAssetType.Pin,
|
|
)).toEqual({
|
|
description: 'nice beacon_info',
|
|
timeout: 1234,
|
|
live: true,
|
|
[M_TIMESTAMP.name]: mockDateNow,
|
|
[M_ASSET.name]: {
|
|
type: LocationAssetType.Pin,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('defaults timestamp to current time', () => {
|
|
expect(makeBeaconInfoContent(
|
|
1234,
|
|
true,
|
|
'nice beacon_info',
|
|
LocationAssetType.Pin,
|
|
)).toEqual(expect.objectContaining({
|
|
[M_TIMESTAMP.name]: mockDateNow,
|
|
}));
|
|
});
|
|
|
|
it('uses timestamp when provided', () => {
|
|
expect(makeBeaconInfoContent(
|
|
1234,
|
|
true,
|
|
'nice beacon_info',
|
|
LocationAssetType.Pin,
|
|
99999,
|
|
)).toEqual(expect.objectContaining({
|
|
[M_TIMESTAMP.name]: 99999,
|
|
}));
|
|
});
|
|
|
|
it('defaults asset type to self when not set', () => {
|
|
expect(makeBeaconInfoContent(
|
|
1234,
|
|
true,
|
|
'nice beacon_info',
|
|
// no assetType passed
|
|
)).toEqual(expect.objectContaining({
|
|
[M_ASSET.name]: {
|
|
type: LocationAssetType.Self,
|
|
},
|
|
}));
|
|
});
|
|
});
|
|
|
|
describe('makeBeaconContent()', () => {
|
|
it('creates event content without description', () => {
|
|
expect(makeBeaconContent(
|
|
'geo:foo',
|
|
123,
|
|
'$1234',
|
|
// no description
|
|
)).toEqual({
|
|
[M_LOCATION.name]: {
|
|
description: undefined,
|
|
uri: 'geo:foo',
|
|
},
|
|
[M_TIMESTAMP.name]: 123,
|
|
"m.relates_to": {
|
|
rel_type: REFERENCE_RELATION.name,
|
|
event_id: '$1234',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('creates event content with description', () => {
|
|
expect(makeBeaconContent(
|
|
'geo:foo',
|
|
123,
|
|
'$1234',
|
|
'test description',
|
|
)).toEqual({
|
|
[M_LOCATION.name]: {
|
|
description: 'test description',
|
|
uri: 'geo:foo',
|
|
},
|
|
[M_TIMESTAMP.name]: 123,
|
|
"m.relates_to": {
|
|
rel_type: REFERENCE_RELATION.name,
|
|
event_id: '$1234',
|
|
},
|
|
});
|
|
});
|
|
});
|
|
});
|