Skip to content

Commit

Permalink
add unit tests for scheduled event structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Aug 1, 2024
1 parent 5f8489d commit 5b1fd17
Show file tree
Hide file tree
Showing 3 changed files with 458 additions and 3 deletions.
68 changes: 68 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,72 @@ export const TEST_DATA = {
request_to_speak_timestamp: "2021-03-31T18:45:31.297561+00:00",
joined: 1722533062,
},
SCHEDULED_EVENT: {
id: "123409989012345678",
guild_id: "619434557472505857",
channel_id: "333456789012345678",
creator_id: "301655085954367490",
name: "test event",
description: "test description",
scheduled_start_time: "2021-01-01T00:00:00.000Z",
scheduled_end_time: "2021-01-02T01:00:00.000Z",
privacy_level: 1,
status: 1,
entity_type: 2,
entity_id: "333456789012345678",
entity_metadata: {
location: undefined,
},
creator: {
id: "301655085954367490",
username: "test",
discriminator: "0001",
avatar: null,
bot: false,
system: false,
mfa_enabled: false,
locale: "en-US",
verified: false,
email: null,
flags: 0,
premium_type: 0,
public_flags: 0,
},
user_count: 10,
image: "000000000000000000000000deadbeef",
},
SCHEDULED_EVENT_EXTERNAL: {
id: "123409989012345678",
guild_id: "619434557472505857",
channel_id: "333456789012345678",
creator_id: "301655085954367490",
name: "test event",
description: "test description",
scheduled_start_time: "2021-01-01T00:00:00.000Z",
scheduled_end_time: "2021-01-02T01:00:00.000Z",
privacy_level: 1,
status: 1,
entity_type: 3,
entity_id: "333456789012345678",
entity_metadata: {
location: "test location",
},
creator: {
id: "301655085954367490",
username: "test",
discriminator: "0001",
avatar: null,
bot: false,
system: false,
mfa_enabled: false,
locale: "en-US",
verified: false,
email: null,
flags: 0,
premium_type: 0,
public_flags: 0,
},
user_count: 10,
image: "000000000000000000000000deadbeef",
},
};
37 changes: 34 additions & 3 deletions src/structures/ScheduledEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ScheduledEvent {
#user_count;
#_attributes;
#location;
#description;
/**
*
* @param {Client} client The client instance.
Expand Down Expand Up @@ -98,6 +99,8 @@ class ScheduledEvent {
*/
this.#_image = data.image ? BigInt(`0x${data.image}`) : null;

if (data.description) this.#description = data.description;

/**
* The number of users who have signed up for the event.
* @type {Number}
Expand Down Expand Up @@ -219,6 +222,16 @@ class ScheduledEvent {
return this.#creator;
}

/**
* The description of the event.
* @type {String}
* @readonly
* @public
*/
get description() {
return this.#description;
}

/**
* The hash of the event's image, as it was received from Discord.
* @readonly
Expand Down Expand Up @@ -271,6 +284,13 @@ class ScheduledEvent {
else return "UNKNOWN";
}

get #rawEntityType() {
if ((this.#_attributes & (0b1 << 0)) == 0b1 << 0) return 1;
else if ((this.#_attributes & (0b1 << 1)) == 0b1 << 1) return 2;
else if ((this.#_attributes & (0b1 << 2)) == 0b1 << 2) return 3;
else return 0;
}

/**
* The status of the event.
* @readonly
Expand All @@ -285,6 +305,14 @@ class ScheduledEvent {
else return "UNKNOWN";
}

get #rawStatus() {
if ((this.#_attributes & (0b1 << 3)) == 0b1 << 3) return 1;
else if ((this.#_attributes & (0b1 << 4)) == 0b1 << 4) return 2;
else if ((this.#_attributes & (0b1 << 5)) == 0b1 << 5) return 3;
else if ((this.#_attributes & (0b1 << 6)) == 0b1 << 6) return 4;
else return 0;
}

/**
* The guild that this event belongs to.
* @type {Guild?}
Expand Down Expand Up @@ -352,6 +380,7 @@ class ScheduledEvent {
id: this.id,
guild_id: this.guildId,
name: this.name,
description: this.description,
creator_id: this.creatorId ?? undefined,
creator: this.creator,
scheduled_start_time: this.scheduledStartTime * 1000,
Expand All @@ -360,9 +389,11 @@ class ScheduledEvent {
: undefined,
image: this.#_originalImageHash,
user_count: this.userCount,
entity_type: this.entityType,
status: this.status,
location: this.location,
entity_type: this.#rawEntityType,
status: this.#rawStatus,
entity_metadata: {
location: this.location,
},
};
}
}
Expand Down
Loading

0 comments on commit 5b1fd17

Please sign in to comment.