From cc1210729f36b252f097abbcdde10868b7872367 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 30 Jun 2023 15:15:23 +1200 Subject: [PATCH] add test for member state content --- d2m/actions/register-user.js | 1 + d2m/actions/register-user.test.js | 24 +++++++++++++++++ test/data.js | 45 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 d2m/actions/register-user.test.js diff --git a/d2m/actions/register-user.js b/d2m/actions/register-user.js index cc5f515c..1d1eb3d6 100644 --- a/d2m/actions/register-user.js +++ b/d2m/actions/register-user.js @@ -154,6 +154,7 @@ async function syncAllUsersInRoom(roomID) { } } +module.exports._memberToStateContent = memberToStateContent module.exports.ensureSim = ensureSim module.exports.ensureSimJoined = ensureSimJoined module.exports.syncUser = syncUser diff --git a/d2m/actions/register-user.test.js b/d2m/actions/register-user.test.js new file mode 100644 index 00000000..7e23450a --- /dev/null +++ b/d2m/actions/register-user.test.js @@ -0,0 +1,24 @@ +const {channelToKState} = require("./create-room") +const {_memberToStateContent} = require("./register-user") +const {test} = require("supertape") +const testData = require("../../test/data") + +test("member2state: general", async t => { + t.deepEqual( + await _memberToStateContent(testData.member.sheep.user, testData.member.sheep, testData.guild.general.id), + { + avatar_url: "mxc://cadence.moe/rfemHmAtcprjLEiPiEuzPhpl", + displayname: "The Expert's Submarine | aprilsong", + membership: "join", + "moe.cadence.ooye.member": { + avatar: "/guilds/112760669178241024/users/134826546694193153/avatars/38dd359aa12bcd52dd3164126c587f8c.png?size=1024" + }, + "uk.half-shot.discord.member": { + bot: false, + displayColor: null, + id: "134826546694193153", + username: "@aprilsong" + } + } + ) +}) diff --git a/test/data.js b/test/data.js index bb70cbe3..85b3cd40 100644 --- a/test/data.js +++ b/test/data.js @@ -93,6 +93,51 @@ module.exports = { system_channel_flags: 0|0 } }, + member: { + sheep: { + avatar: "38dd359aa12bcd52dd3164126c587f8c", + communication_disabled_until: null, + flags: 0, + joined_at: "2020-10-14T22:08:37.804000+00:00", + nick: "The Expert's Submarine", + pending: false, + premium_since: "2022-05-04T00:28:44.326000+00:00", + roles: [ + "112767366235959296", "118924814567211009", + "118923488755974146", "199995902742626304", + "204427286542417920", "217013981053845504", + "222168467627835392", "260993819204386816", + "265239342648131584", "271173313575780353", + "225744901915148298", "287733611912757249", + "318243902521868288", "348651574924541953", + "352291384021090304", "378402925128712193", + "392141548932038658", "393912152173576203", + "1123460940935991296", "872274377150980116", + "373336013109461013", "530220455085473813", + "768280323829137430", "842343433452257310", + "454567553738473472", "920107226528612383", + "1123528381514911745", "1040735082610167858", + "585531096071012409", "849737964090556488", + "660272211449479249" + ], + user: { + id: "134826546694193153", + username: "aprilsong", + avatar: "c754c120bce07ae3b3130e2b0e61d9dd", + discriminator: "0", + public_flags: 640, + flags: 640, + banner: "a3ad0693213f9dbf793b4159dbae0717", + accent_color: null, + global_name: "sheep", + avatar_decoration: null, + display_name: "sheep", + banner_color: null + }, + mute: false, + deaf: false + } + }, message: { // Display order is text content, attachments, then stickers sticker: {