diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 4756544f3..ba1c94a29 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -417,6 +417,22 @@ describe("MatrixClient", function () { ]); }); + it("should fallback to unstable endpoint when stable endpoint 400s", async () => { + await assertRequestsMade([ + { + prefix: ClientPrefix.V1, + error: { + httpStatus: 400, + errcode: "M_UNRECOGNIZED", + }, + }, + { + prefix: unstableMSC3030Prefix, + data: { event_id: eventId }, + }, + ]); + }); + it("should fallback to unstable endpoint when stable endpoint 404s", async () => { await assertRequestsMade([ { @@ -449,7 +465,7 @@ describe("MatrixClient", function () { ]); }); - it("should not fallback to unstable endpoint when stable endpoint returns an error", async () => { + it("should not fallback to unstable endpoint when stable endpoint returns an error (500)", async () => { await assertRequestsMade( [ { @@ -463,6 +479,36 @@ describe("MatrixClient", function () { true, ); }); + + it("should not fallback to unstable endpoint when stable endpoint is rate-limiting (429)", async () => { + await assertRequestsMade( + [ + { + prefix: ClientPrefix.V1, + error: { + httpStatus: 429, + errcode: "M_UNRECOGNIZED", // Still refuses even if the errcode claims unrecognised + }, + }, + ], + true, + ); + }); + + it("should not fallback to unstable endpoint when stable endpoint says bad gateway (502)", async () => { + await assertRequestsMade( + [ + { + prefix: ClientPrefix.V1, + error: { + httpStatus: 502, + errcode: "Fake response error", + }, + }, + ], + true, + ); + }); }); describe("getSafeUserId()", () => {