-
-
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.
Merge branch 'develop' into travis/msc3916
- Loading branch information
Showing
3 changed files
with
139 additions
and
9 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 |
---|---|---|
|
@@ -19,7 +19,16 @@ import { Mocked } from "jest-mock"; | |
import * as utils from "../test-utils/test-utils"; | ||
import { CRYPTO_ENABLED, IStoredClientOpts, MatrixClient } from "../../src/client"; | ||
import { MatrixEvent } from "../../src/models/event"; | ||
import { Filter, KnockRoomOpts, MemoryStore, Method, Room, SERVICE_TYPES } from "../../src/matrix"; | ||
import { | ||
Filter, | ||
JoinRule, | ||
KnockRoomOpts, | ||
MemoryStore, | ||
Method, | ||
Room, | ||
RoomSummary, | ||
SERVICE_TYPES, | ||
} from "../../src/matrix"; | ||
import { TestClient } from "../TestClient"; | ||
import { THREAD_RELATION_TYPE } from "../../src/models/thread"; | ||
import { IFilterDefinition } from "../../src/filter"; | ||
|
@@ -1710,6 +1719,102 @@ describe("MatrixClient", function () { | |
await Promise.all([client.unbindThreePid("email", "[email protected]"), httpBackend.flushAllExpected()]); | ||
}); | ||
}); | ||
|
||
describe("getRoomSummary", () => { | ||
const roomId = "!foo:bar"; | ||
const encodedRoomId = encodeURIComponent(roomId); | ||
|
||
const roomSummary: RoomSummary = { | ||
"room_id": roomId, | ||
"name": "My Room", | ||
"avatar_url": "", | ||
"topic": "My room topic", | ||
"world_readable": false, | ||
"guest_can_join": false, | ||
"num_joined_members": 1, | ||
"room_type": "", | ||
"join_rule": JoinRule.Public, | ||
"membership": "leave", | ||
"im.nheko.summary.room_version": "6", | ||
"im.nheko.summary.encryption": "algo", | ||
}; | ||
|
||
const prefix = "/_matrix/client/unstable/im.nheko.summary/"; | ||
const suffix = `summary/${encodedRoomId}`; | ||
const deprecatedSuffix = `rooms/${encodedRoomId}/summary`; | ||
|
||
const errorUnrecogStatus = 404; | ||
const errorUnrecogBody = { | ||
errcode: "M_UNRECOGNIZED", | ||
error: "Unsupported endpoint", | ||
}; | ||
|
||
const errorBadreqStatus = 400; | ||
const errorBadreqBody = { | ||
errcode: "M_UNKNOWN", | ||
error: "Invalid request", | ||
}; | ||
|
||
it("should respond with a valid room summary object", () => { | ||
httpBackend.when("GET", prefix + suffix).respond(200, roomSummary); | ||
|
||
const prom = client.getRoomSummary(roomId).then((response) => { | ||
expect(response).toEqual(roomSummary); | ||
}); | ||
|
||
httpBackend.flush(""); | ||
return prom; | ||
}); | ||
|
||
it("should allow fallback to the deprecated endpoint", () => { | ||
httpBackend.when("GET", prefix + suffix).respond(errorUnrecogStatus, errorUnrecogBody); | ||
httpBackend.when("GET", prefix + deprecatedSuffix).respond(200, roomSummary); | ||
|
||
const prom = client.getRoomSummary(roomId).then((response) => { | ||
expect(response).toEqual(roomSummary); | ||
}); | ||
|
||
httpBackend.flush(""); | ||
return prom; | ||
}); | ||
|
||
it("should respond to unsupported path with error", () => { | ||
httpBackend.when("GET", prefix + suffix).respond(errorUnrecogStatus, errorUnrecogBody); | ||
httpBackend.when("GET", prefix + deprecatedSuffix).respond(errorUnrecogStatus, errorUnrecogBody); | ||
|
||
const prom = client.getRoomSummary(roomId).then( | ||
function (response) { | ||
throw Error("request not failed"); | ||
}, | ||
function (error) { | ||
expect(error.httpStatus).toEqual(errorUnrecogStatus); | ||
expect(error.errcode).toEqual(errorUnrecogBody.errcode); | ||
expect(error.message).toEqual(`MatrixError: [${errorUnrecogStatus}] ${errorUnrecogBody.error}`); | ||
}, | ||
); | ||
|
||
httpBackend.flush(""); | ||
return prom; | ||
}); | ||
|
||
it("should respond to invalid path arguments with error", () => { | ||
httpBackend.when("GET", prefix).respond(errorBadreqStatus, errorBadreqBody); | ||
|
||
const prom = client.getRoomSummary("notAroom").then( | ||
function (response) { | ||
throw Error("request not failed"); | ||
}, | ||
function (error) { | ||
expect(error.httpStatus).toEqual(errorBadreqStatus); | ||
expect(error.errcode).toEqual(errorBadreqBody.errcode); | ||
expect(error.message).toEqual(`MatrixError: [${errorBadreqStatus}] ${errorBadreqBody.error}`); | ||
}, | ||
); | ||
|
||
httpBackend.flush(""); | ||
return prom; | ||
}); | ||
}); | ||
}); | ||
|
||
function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent { | ||
|
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