2023-12-29 16:11:08 +00:00
|
|
|
import { E2ESetupTestTimeout, E2ETestEnv } from "./util/e2e-test";
|
|
|
|
import { describe, it, beforeEach, afterEach } from "@jest/globals";
|
2024-01-02 15:52:43 +00:00
|
|
|
import { getBridgeApi } from "./util/bridge-api";
|
2023-12-29 16:11:08 +00:00
|
|
|
|
|
|
|
describe('Widgets', () => {
|
|
|
|
let testEnv: E2ETestEnv;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
const webhooksPort = 9500 + E2ETestEnv.workerId;
|
|
|
|
testEnv = await E2ETestEnv.createTestEnv({matrixLocalparts: ['user'], config: {
|
|
|
|
widgets: {
|
|
|
|
publicUrl: `http://localhost:${webhooksPort}`
|
|
|
|
},
|
|
|
|
listeners: [{
|
|
|
|
port: webhooksPort,
|
|
|
|
bindAddress: '0.0.0.0',
|
|
|
|
// Bind to the SAME listener to ensure we don't have conflicts.
|
|
|
|
resources: ['webhooks', 'widgets'],
|
|
|
|
}],
|
|
|
|
|
|
|
|
}});
|
|
|
|
await testEnv.setUp();
|
|
|
|
}, E2ESetupTestTimeout);
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
return testEnv?.tearDown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to authenticate with the widget API', async () => {
|
|
|
|
const user = testEnv.getUser('user');
|
2024-01-02 15:52:43 +00:00
|
|
|
const bridgeApi = await getBridgeApi(testEnv.opts.config?.widgets?.publicUrl!, user);
|
2023-12-29 16:11:08 +00:00
|
|
|
expect(await bridgeApi.verify()).toEqual({
|
|
|
|
"type": "widget",
|
|
|
|
"userId": "@user:hookshot",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|