forked from 1inch/shieldy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support silent bot messages 1inch#170
- Loading branch information
Showing
42 changed files
with
365 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import {findChatById} from '@root/helpers/find-chat'; | ||
import {getUniqueCounterValue} from '@root/util/id/unique-counter'; | ||
import {setupTest} from '../helpers/setup'; | ||
import {createMessage} from '../test-data/updates'; | ||
|
||
describe('/silent', () => { | ||
const botTest = setupTest(); | ||
|
||
afterEach(botTest.afterEach); | ||
|
||
it('should toggle silent notifications', async () => { | ||
const { | ||
appContext, | ||
handleUpdate, | ||
onIdle, | ||
popMessages, | ||
unixSeconds, | ||
user, | ||
groupChat, | ||
} = await botTest.init(); | ||
|
||
await findChatById(appContext, groupChat.id); | ||
await appContext.database.setChatProperty({ | ||
chatId: groupChat.id, | ||
property: 'silentMessages', | ||
value: false, | ||
}); | ||
|
||
const checkSilentPing = async (expectedSilent: boolean) => { | ||
await handleUpdate( | ||
createMessage({ | ||
messageId: getUniqueCounterValue(), | ||
user, | ||
chat: groupChat, | ||
unixSeconds, | ||
text: '/ping', | ||
isBotCommand: true, | ||
}), | ||
); | ||
await onIdle(); | ||
|
||
{ | ||
const messages = popMessages(); | ||
|
||
expect(messages.length).toBe(1); | ||
expect(messages[0].text).toBe('pong'); | ||
expect(Boolean(messages[0].isSilent)).toBe(expectedSilent); | ||
} | ||
}; | ||
|
||
await checkSilentPing(false); | ||
|
||
await handleUpdate( | ||
createMessage({ | ||
messageId: getUniqueCounterValue(), | ||
user, | ||
chat: groupChat, | ||
unixSeconds, | ||
text: '/silent', | ||
isBotCommand: true, | ||
}), | ||
); | ||
await onIdle(); | ||
|
||
{ | ||
// Should change to silent | ||
const messages = popMessages(); | ||
|
||
expect(messages.length).toBe(1); | ||
expect(messages[0].text).toBe( | ||
'Sesuritu will send messages without sound', | ||
); | ||
expect(messages[0].isSilent).toBeTruthy(); | ||
} | ||
|
||
await checkSilentPing(true); | ||
|
||
await handleUpdate( | ||
createMessage({ | ||
messageId: getUniqueCounterValue(), | ||
user, | ||
chat: groupChat, | ||
unixSeconds, | ||
text: '/silent', | ||
isBotCommand: true, | ||
}), | ||
); | ||
await onIdle(); | ||
|
||
{ | ||
// Should change to not silent | ||
const messages = popMessages(); | ||
|
||
expect(messages.length).toBe(1); | ||
expect(messages[0].text).toBe('Sesuritu will send messages with sound'); | ||
expect(messages[0].isSilent).toBeFalsy(); | ||
} | ||
|
||
await checkSilentPing(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.