-
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
133 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
Copyright 2022 Dominik Henneke | ||
Copyright 2022 Nordeck IT + Consulting GmbH. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import HttpBackend from "matrix-mock-request"; | ||
|
||
import { Direction, MatrixClient, MatrixScheduler } from "../../src/matrix"; | ||
import { TestClient } from "../TestClient"; | ||
|
||
describe("MatrixClient relations", () => { | ||
const userId = "@alice:localhost"; | ||
const accessToken = "aseukfgwef"; | ||
const roomId = "!room:here"; | ||
let client: MatrixClient | undefined; | ||
let httpBackend: HttpBackend | undefined; | ||
|
||
const setupTests = (): [MatrixClient, HttpBackend] => { | ||
const scheduler = new MatrixScheduler(); | ||
const testClient = new TestClient( | ||
userId, | ||
"DEVICE", | ||
accessToken, | ||
undefined, | ||
{ scheduler }, | ||
); | ||
const httpBackend = testClient.httpBackend; | ||
const client = testClient.client; | ||
|
||
return [client, httpBackend]; | ||
}; | ||
|
||
beforeEach(() => { | ||
[client, httpBackend] = setupTests(); | ||
}); | ||
|
||
afterEach(() => { | ||
httpBackend!.verifyNoOutstandingExpectation(); | ||
return httpBackend!.stop(); | ||
}); | ||
|
||
it("should read related events with the default options", async () => { | ||
const response = client!.relations(roomId, '$event-0', null, null); | ||
|
||
httpBackend! | ||
.when("GET", "/rooms/!room%3Ahere/relations/%24event-0?dir=b") | ||
.respond(200, { chunk: [], next_batch: 'NEXT' }); | ||
|
||
await httpBackend!.flushAllExpected(); | ||
|
||
expect(await response).toEqual({ "events": [], "nextBatch": "NEXT" }); | ||
}); | ||
|
||
it("should read related events with relation type", async () => { | ||
const response = client!.relations(roomId, '$event-0', 'm.reference', null); | ||
|
||
httpBackend! | ||
.when("GET", "/rooms/!room%3Ahere/relations/%24event-0/m.reference?dir=b") | ||
.respond(200, { chunk: [], next_batch: 'NEXT' }); | ||
|
||
await httpBackend!.flushAllExpected(); | ||
|
||
expect(await response).toEqual({ "events": [], "nextBatch": "NEXT" }); | ||
}); | ||
|
||
it("should read related events with relation type and event type", async () => { | ||
const response = client!.relations(roomId, '$event-0', 'm.reference', 'm.room.message'); | ||
|
||
httpBackend! | ||
.when( | ||
"GET", | ||
"/rooms/!room%3Ahere/relations/%24event-0/m.reference/m.room.message?dir=b", | ||
) | ||
.respond(200, { chunk: [], next_batch: 'NEXT' }); | ||
|
||
await httpBackend!.flushAllExpected(); | ||
|
||
expect(await response).toEqual({ "events": [], "nextBatch": "NEXT" }); | ||
}); | ||
|
||
it("should read related events with custom options", async () => { | ||
const response = client!.relations(roomId, '$event-0', null, null, { | ||
dir: Direction.Forward, | ||
from: 'FROM', | ||
limit: 10, | ||
to: 'TO', | ||
}); | ||
|
||
httpBackend! | ||
.when( | ||
"GET", | ||
"/rooms/!room%3Ahere/relations/%24event-0?dir=f&from=FROM&limit=10&to=TO", | ||
) | ||
.respond(200, { chunk: [], next_batch: 'NEXT' }); | ||
|
||
await httpBackend!.flushAllExpected(); | ||
|
||
expect(await response).toEqual({ "events": [], "nextBatch": "NEXT" }); | ||
}); | ||
|
||
it('should use default direction in the fetchRelations endpoint', async () => { | ||
const response = client!.fetchRelations(roomId, '$event-0', null, null); | ||
|
||
httpBackend! | ||
.when( | ||
"GET", | ||
"/rooms/!room%3Ahere/relations/%24event-0?dir=b", | ||
) | ||
.respond(200, { chunk: [], next_batch: 'NEXT' }); | ||
|
||
await httpBackend!.flushAllExpected(); | ||
|
||
expect(await response).toEqual({ "chunk": [], "next_batch": "NEXT" }); | ||
}); | ||
}); |
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