Support for reading m.call status (#34295)
* Support for reading m.call status (well, the prefixed version) * Abstract the details away in userStatusFromProfile make the validate functions non-exported * Add test * format the oxen * Remove set function should be in the other PR
This commit is contained in:
@@ -12,11 +12,49 @@ import {
|
||||
clearUserStatus,
|
||||
fetchUserStatus,
|
||||
setUserStatus,
|
||||
userStatusFromProfile,
|
||||
userStatusTextWithinMaxLength,
|
||||
} from "../../../src/utils/userStatus";
|
||||
import { stubClient } from "../../test-utils";
|
||||
|
||||
describe("userStatus utils", () => {
|
||||
describe("userStatusFromProfile", () => {
|
||||
it("returns the user status if it is valid", () => {
|
||||
expect(userStatusFromProfile({ emoji: "🐳", text: "Feeling a little blue" }, undefined)).toEqual({
|
||||
emoji: "🐳",
|
||||
text: "Feeling a little blue",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined if the user status is invalid and there is no call status", () => {
|
||||
expect(userStatusFromProfile({ text: "Feeling a little blue" }, undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns the call status if the user status is invalid but the call status is valid", () => {
|
||||
expect(userStatusFromProfile({ text: "Feeling a little blue" }, { call_joined_ts: 12345 })).toEqual({
|
||||
emoji: "📞",
|
||||
text: "On a call",
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers the user status over the call status if both are valid", () => {
|
||||
expect(
|
||||
userStatusFromProfile({ emoji: "🐳", text: "Feeling a little blue" }, { call_joined_ts: 12345 }),
|
||||
).toEqual({
|
||||
emoji: "🐳",
|
||||
text: "Feeling a little blue",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined if the call status has a non-positive call_joined_ts", () => {
|
||||
expect(userStatusFromProfile(undefined, { call_joined_ts: 0 })).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined if neither status is valid", () => {
|
||||
expect(userStatusFromProfile(undefined, undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("userStatusTextWithinMaxLength", () => {
|
||||
it("returns true for text within the max length", () => {
|
||||
const text = "a".repeat(256);
|
||||
|
||||
Reference in New Issue
Block a user