forked from matrix-org/matrix-hookshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add End to End testing (matrix-org#868)
* Ensure connection state always explicitly states all keys, even if some are undefined. * changelog * Fix type * fix test types * Add support for E2E testing * Add CI job for e2e test * Ensure integration test only runs when regular tests complete * Add homerunner image * Disallow concurrent runs * Add concurrency to other expensive steps * changelog * Fix mq test * Cache rust deps * Drop only * Use a shared key
- Loading branch information
Showing
14 changed files
with
1,927 additions
and
78 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
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 @@ | ||
Integrate end to end testing. |
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,21 @@ | ||
/** | ||
* For a detailed explanation regarding each configuration property, visit: | ||
* https://jestjs.io/docs/configuration | ||
*/ | ||
|
||
import type {Config} from 'jest'; | ||
|
||
const config: Config = { | ||
// The root directory that Jest should scan for tests and modules within | ||
rootDir: "spec", | ||
testTimeout: 60000, | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default config; |
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,62 @@ | ||
import { MessageEventContent } from "matrix-bot-sdk"; | ||
import { E2ESetupTestTimeout, E2ETestEnv } from "./util/e2e-test"; | ||
import { describe, it, beforeEach, afterEach } from "@jest/globals"; | ||
import { expect } from "chai"; | ||
|
||
describe('Basic test setup', () => { | ||
let testEnv: E2ETestEnv; | ||
|
||
beforeEach(async () => { | ||
testEnv = await E2ETestEnv.createTestEnv({matrixLocalparts: ['user']}); | ||
await testEnv.setUp(); | ||
}, E2ESetupTestTimeout); | ||
|
||
afterEach(() => { | ||
return testEnv?.tearDown(); | ||
}); | ||
|
||
it('should be able to invite the bot to a room', async () => { | ||
const user = testEnv.getUser('user'); | ||
const roomId = await user.createRoom({ name: 'Test room', invite:[testEnv.botMxid] }); | ||
await user.waitForRoomJoin({sender: testEnv.botMxid, roomId }); | ||
await user.sendText(roomId, "!hookshot help"); | ||
const msg = await user.waitForRoomEvent<MessageEventContent>({ | ||
eventType: 'm.room.message', sender: testEnv.botMxid, roomId | ||
}); | ||
// Expect help text. | ||
expect(msg.data.content.body).to.include('!hookshot help` - This help text\n'); | ||
}); | ||
|
||
// TODO: Move test to it's own generic connections file. | ||
it('should be able to setup a webhook', async () => { | ||
const user = testEnv.getUser('user'); | ||
const testRoomId = await user.createRoom({ name: 'Test room', invite:[testEnv.botMxid] }); | ||
await user.waitForRoomJoin({sender: testEnv.botMxid, roomId: testRoomId }); | ||
await user.setUserPowerLevel(testEnv.botMxid, testRoomId, 50); | ||
await user.sendText(testRoomId, "!hookshot webhook test-webhook"); | ||
const inviteResponse = await user.waitForRoomInvite({sender: testEnv.botMxid}); | ||
await user.waitForRoomEvent<MessageEventContent>({ | ||
eventType: 'm.room.message', sender: testEnv.botMxid, roomId: testRoomId, | ||
body: 'Room configured to bridge webhooks. See admin room for secret url.' | ||
}); | ||
const webhookUrlMessage = user.waitForRoomEvent<MessageEventContent>({ | ||
eventType: 'm.room.message', sender: testEnv.botMxid, roomId: inviteResponse.roomId | ||
}); | ||
await user.joinRoom(inviteResponse.roomId); | ||
const msgData = (await webhookUrlMessage).data.content.body; | ||
const webhookUrl = msgData.split('\n')[2]; | ||
const webhookNotice = user.waitForRoomEvent<MessageEventContent>({ | ||
eventType: 'm.room.message', sender: testEnv.botMxid, roomId: testRoomId, body: 'Hello world!' | ||
}); | ||
|
||
// Send a webhook | ||
await fetch(webhookUrl, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({text: 'Hello world!'}) | ||
}); | ||
|
||
// And await the notice. | ||
await webhookNotice; | ||
}); | ||
}); |
Oops, something went wrong.