diff --git a/src/utils/users.ts b/src/utils/users.ts index 967adf5..82bf65e 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -20,8 +20,6 @@ export function determineUserType(user: Member): UserType { return UserType.BOT; } else if (user.is_admin) { return UserType.ADMIN; - } else if (user.is_restricted) { - return UserType.RESTRICTED; } else if (user.is_ultra_restricted) { return UserType.ULTRA_RESTRICTED; } else if (user.is_restricted) { diff --git a/tests/fixtures/slackMember.ts b/tests/fixtures/slackMember.ts new file mode 100644 index 0000000..29d338b --- /dev/null +++ b/tests/fixtures/slackMember.ts @@ -0,0 +1,55 @@ +const slackMember = { + id: "U033TF4RSKX", + team_id: "T07MWHQKU", + name: "cwijesek", + deleted: false, + color: "9e3997", + real_name: "(Test) Chamath Wijesekera", + tz: "America/New_York", + tz_label: "Eastern Standard Time", + tz_offset: -18000, + profile: { + title: "", + phone: "", + skype: "", + real_name: "(Test) Chamath Wijesekera", + real_name_normalized: "(Test) Chamath Wijesekera", + display_name: "Hi, I'm a test", + display_name_normalized: "Hi, I'm a test", + fields: undefined, + status_text: "", + status_emoji: "", + status_emoji_display_info: [], + status_expiration: 0, + avatar_hash: "gfa68b739a0c", + guest_invited_by: "UMWGQ63D0", + first_name: "(Test)", + last_name: "Chamath Wijesekera", + image_24: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-24.png", + image_32: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-32.png", + image_48: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-48.png", + image_72: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-72.png", + image_192: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-192.png", + image_512: + "https://secure.gravatar.com/avatar/fa68b739a0cf06a30ed3e671cf22585e.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0014-512.png", + status_text_canonical: "", + team: "T07MWHQKU", + }, + is_admin: false, + is_owner: false, + is_primary_owner: false, + is_restricted: true, + is_ultra_restricted: true, + is_bot: false, + is_app_user: false, + updated: 1645370740, + is_email_confirmed: true, + who_can_share_contact_card: "EVERYONE", +}; + +export default slackMember; diff --git a/tests/unit/utils/users.test.ts b/tests/unit/utils/users.test.ts new file mode 100644 index 0000000..57f519e --- /dev/null +++ b/tests/unit/utils/users.test.ts @@ -0,0 +1,74 @@ +import { determineUserType } from "../../../src/utils/users"; +import { UserType } from "../../../src/classes/SlackUser"; +import { Member } from "@slack/web-api/dist/response/UsersListResponse"; + +import slackMember from "../../fixtures/slackMember"; + +describe("determineUserType", () => { + beforeEach(() => { + slackMember.is_owner = false; + slackMember.is_bot = false; + slackMember.is_admin = false; + slackMember.is_ultra_restricted = false; + slackMember.is_restricted = false; + }); + + it("should return the user type: owner", () => { + const member: Member = slackMember; + + member.is_owner = true; + + const result = determineUserType(member); + + expect(result).toBe(UserType.OWNER); + }); + + it("should return the user type: bot", () => { + const member: Member = slackMember; + + member.is_bot = true; + + const result = determineUserType(member); + + expect(result).toBe(UserType.BOT); + }); + + it("should return the user type: admin", () => { + const member: Member = slackMember; + + member.is_admin = true; + + const result = determineUserType(member); + + expect(result).toBe(UserType.ADMIN); + }); + + it("should return the user type: ultra_restricted", () => { + const member: Member = slackMember; + + member.is_restricted = true; + member.is_ultra_restricted = true; + + const result = determineUserType(member); + + expect(result).toBe(UserType.ULTRA_RESTRICTED); + }); + + it("should return the user type: restricted", () => { + const member: Member = slackMember; + + member.is_restricted = true; + + const result = determineUserType(member); + + expect(result).toBe(UserType.RESTRICTED); + }); + + it("should return the user type: full_member", () => { + const member: Member = slackMember; + + const result = determineUserType(member); + + expect(result).toBe(UserType.FULL_MEMBER); + }); +});