1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-30 02:21:17 +03:00

Do not create account data event for guests (#9407)

* Do not create account data event for guests

* fix test
This commit is contained in:
Germain
2022-10-13 13:15:34 +01:00
committed by GitHub
parent 7a1c47a23e
commit 714ba6db94
2 changed files with 24 additions and 12 deletions

View File

@ -30,21 +30,23 @@ jest.mock("../../src/settings/SettingsStore");
describe('notifications', () => {
let accountDataStore = {};
const mockClient = getMockClientWithEventEmitter({
isGuest: jest.fn().mockReturnValue(false),
getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]),
setAccountData: jest.fn().mockImplementation((eventType, content) => {
accountDataStore[eventType] = new MatrixEvent({
type: eventType,
content,
});
}),
});
const accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId);
let mockClient;
let accountDataEventKey;
beforeEach(() => {
jest.clearAllMocks();
mockClient = getMockClientWithEventEmitter({
isGuest: jest.fn().mockReturnValue(false),
getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]),
setAccountData: jest.fn().mockImplementation((eventType, content) => {
accountDataStore[eventType] = new MatrixEvent({
type: eventType,
content,
});
}),
});
accountDataStore = {};
accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId);
mocked(SettingsStore).getValue.mockReturnValue(false);
});
@ -55,6 +57,13 @@ describe('notifications', () => {
expect(event?.getContent().is_silenced).toBe(true);
});
it('does not do anything for guests', async () => {
mockClient.isGuest.mockReset().mockReturnValue(true);
await createLocalNotificationSettingsIfNeeded(mockClient);
const event = mockClient.getAccountData(accountDataEventKey);
expect(event).toBeFalsy();
});
it.each(deviceNotificationSettingsKeys)(
'unsilenced for existing sessions when %s setting is truthy',
async (settingKey) => {