Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with single-channel guests not being identified #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/utils/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 55 additions & 0 deletions tests/fixtures/slackMember.ts
Original file line number Diff line number Diff line change
@@ -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;
74 changes: 74 additions & 0 deletions tests/unit/utils/users.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading