test suite for bot
This commit is contained in:
@@ -2,6 +2,7 @@ require('dotenv').config()
|
||||
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
import * as fs from "fs";
|
||||
import waitForExpect from 'wait-for-expect'
|
||||
|
||||
import {
|
||||
@@ -59,6 +60,7 @@ describe('OcrccBot', () => {
|
||||
mockKick.mockClear()
|
||||
mockGetJoinedRoomMembers.mockClear()
|
||||
mockGetUser.mockClear()
|
||||
mockSendTextMessage.mockClear()
|
||||
})
|
||||
|
||||
test('constructor should inititialize matrix client', () => {
|
||||
@@ -175,15 +177,70 @@ describe('OcrccBot', () => {
|
||||
})
|
||||
|
||||
test('#handleBotCrash should notify rooms', () => {
|
||||
const bot = new OcrccBot()
|
||||
bot.start()
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockStartClient).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
bot.handleBotCrash('test_room_id', 'test error message')
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockSendTextMessage).toHaveBeenCalledWith('test_room_id', "Something went wrong on our end, please restart the chat and try again.")
|
||||
})
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockSendTextMessage).toHaveBeenCalledWith(process.env.FACILITATOR_ROOM_ID, `The Help Bot ran into an error: test error message. Please verify that the chat service is working.`)
|
||||
})
|
||||
})
|
||||
|
||||
test('#writeToTranscript should parse event and write to transcript file', () => {
|
||||
const appendFileSyncSpy = jest.spyOn(fs, 'appendFileSync')
|
||||
const bot = new OcrccBot()
|
||||
bot.start()
|
||||
|
||||
bot.activeChatrooms['test_room_id'] = { transcriptFile: 'test filepath' }
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockStartClient).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
const mockEvent = {
|
||||
getSender: () => 'test_sender',
|
||||
getRoomId: () => 'test_room_id',
|
||||
getContent: () => { return { body: 'test content' }},
|
||||
getDate: () => { return new Date(2020,2,17,0,0,0,0) }
|
||||
}
|
||||
|
||||
bot.writeToTranscript(mockEvent)
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(appendFileSyncSpy).toHaveBeenCalledWith('test filepath', 'test_sender [00:00:00]: test content', 'utf8')
|
||||
})
|
||||
})
|
||||
|
||||
test('#deleteOldDevices should delete old sessions', () => {
|
||||
const bot = new OcrccBot()
|
||||
bot.start()
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockStartClient).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
bot.deleteOldDevices()
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockGetDevices).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(mockGetDevicdId).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
waitForExpect(() => {
|
||||
expect(deleteMultipleDevices).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
// TODO test listeners for membership events and message events
|
||||
|
||||
Reference in New Issue
Block a user