-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement tests for determineUserType
- Loading branch information
1 parent
d2f8361
commit 6fc6196
Showing
3 changed files
with
129 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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; |
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 |
---|---|---|
@@ -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); | ||
}); | ||
}); |