diff --git a/search-index/characters_index.bin b/search-index/characters_index.bin index 59b3821b..553495c0 100644 Binary files a/search-index/characters_index.bin and b/search-index/characters_index.bin differ diff --git a/search-index/media_index.bin b/search-index/media_index.bin index 7ae5e2b1..c5ae7540 100644 Binary files a/search-index/media_index.bin and b/search-index/media_index.bin differ diff --git a/src/merge.ts b/src/merge.ts index 85eea2bf..79d5fc04 100644 --- a/src/merge.ts +++ b/src/merge.ts @@ -24,9 +24,19 @@ type CharacterWithId = WithId; async function getFilteredCharacters( { userId, guildId }: { userId: string; guildId: string }, ): Promise[]> { - const { user, party } = await db.getInventory(guildId, userId); + const mongo = await db.newMongo().connect(); - const characters = await db.getUserCharacters(userId, guildId); + const { user, party } = await db.getInventory(guildId, userId, mongo, true); + + const likesCharactersIds = user.likes + ?.map(({ characterId }) => characterId) + .filter(utils.nonNullable); + + const likesMediaIds = user.likes + ?.map(({ mediaId }) => mediaId) + .filter(utils.nonNullable); + + const characters = await db.getUserCharacters(userId, guildId, mongo, true); const partyIds = [ party.member1?.characterId, @@ -36,13 +46,7 @@ async function getFilteredCharacters( party.member5?.characterId, ]; - const likesCharactersIds = user.likes - ?.map(({ characterId }) => characterId) - .filter(utils.nonNullable); - - const likesMediaIds = user.likes - ?.map(({ mediaId }) => mediaId) - .filter(utils.nonNullable); + await mongo.close(); return characters .filter((char) => { diff --git a/src/user.ts b/src/user.ts index 535e290e..8b7acc65 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1180,18 +1180,20 @@ function sum({ .then(async () => { const mongo = await db.newMongo().connect(); - const { user, ...inventory } = await db.getInventory( + const { user, party } = await db.getInventory( guildId, userId, mongo, true, ); - const likesCharactersIds = (user.likes ?? []) - .map(({ characterId }) => characterId); + const likesCharactersIds = user.likes + ?.map(({ characterId }) => characterId) + .filter(utils.nonNullable); - const likesMediaIds = (user.likes ?? []) - .map(({ mediaId }) => mediaId); + const likesMediaIds = user.likes + ?.map(({ mediaId }) => mediaId) + .filter(utils.nonNullable); const characters = await db.getUserCharacters( userId, @@ -1201,11 +1203,11 @@ function sum({ ); const partyIds = [ - inventory.party.member1Id, - inventory.party.member2Id, - inventory.party.member3Id, - inventory.party.member4Id, - inventory.party.member5Id, + party.member1?.characterId, + party.member2?.characterId, + party.member3?.characterId, + party.member4?.characterId, + party.member5?.characterId, ]; const embed = new discord.Embed(); @@ -1232,7 +1234,7 @@ function sum({ const r = char.rating as keyof typeof sum; if ( - partyIds.includes(char._id) || + partyIds.includes(char.characterId) || likesCharactersIds.includes(char.characterId) || likesMediaIds.includes(char.mediaId) ) { diff --git a/src/utils.ts b/src/utils.ts index 3659ea51..1f879b89 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -450,7 +450,7 @@ async function proxy( url?: string, size?: ImageSize, ): Promise { - let filename = url ? encodeURIComponent(basename(url)) : 'default.webp'; + let filename = url ? basename(url) : 'default.webp'; const file = await _proxy(url ?? '', size); @@ -462,10 +462,15 @@ async function proxy( } } - filename = filename.replaceAll('_', '-'); + const asciiFilename = Array.from(filename) + .map((char) => char.charCodeAt(0)) + .map((code) => code < 128 ? String.fromCharCode(code) : '-') + .join('') + .replaceAll('_', '-') + .replace(/\s+/g, ''); return { - filename, + filename: asciiFilename, arrayBuffer: file.image, type: file.format, }; diff --git a/tests/__snapshots__/search-index.test.ts.snap b/tests/__snapshots__/search-index.test.ts.snap index 1f79be13..c72fb5e0 100644 --- a/tests/__snapshots__/search-index.test.ts.snap +++ b/tests/__snapshots__/search-index.test.ts.snap @@ -149,36 +149,36 @@ snapshot[`characters search > aqua 1`] = ` role: "SUPPORTING", }, { - id: "anilist:3157", + id: "anilist:3165", mediaId: "anilist:521", mediaTitle: [ "Mermaid Melody: Pichi Pichi Pitch", "マーメイドメロディー ぴちぴちピッチ", ], name: [ - "Hanon Houshou", - "宝生波音", - "Aqua Pearl Mermaid Princess", - "Hanon Hosho", + "Aqua Regina", + "アクア・レジーナ様", ], popularity: 14145, rating: 1, - role: "MAIN", + role: "SUPPORTING", }, { - id: "anilist:3165", + id: "anilist:3157", mediaId: "anilist:521", mediaTitle: [ "Mermaid Melody: Pichi Pichi Pitch", "マーメイドメロディー ぴちぴちピッチ", ], name: [ - "Aqua Regina", - "アクア・レジーナ様", + "Hanon Houshou", + "宝生波音", + "Aqua Pearl Mermaid Princess", + "Hanon Hosho", ], popularity: 14145, rating: 1, - role: "SUPPORTING", + role: "MAIN", }, { id: "anilist:329113", @@ -268,7 +268,7 @@ snapshot[`characters search > aqua 1`] = ` "水無月かれん", "Cure Aqua (キュアアクア)", ], - popularity: 7024, + popularity: 7103, rating: 1, role: "BACKGROUND", }, @@ -284,7 +284,7 @@ snapshot[`characters search > aqua 1`] = ` "Aqua", "アクア", ], - popularity: 3383, + popularity: 3417, rating: 1, role: "SUPPORTING", }, @@ -303,185 +303,184 @@ snapshot[`characters search > aqua 1`] = ` "Dark Aqua", "ダークアクア", ], - popularity: 2043, + popularity: 2066, rating: 1, role: "SUPPORTING", }, { - id: "anilist:302746", - mediaId: "anilist:1040", + id: "anilist:35850", + mediaId: "anilist:8937", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "A Certain Magical Index II", + "Toaru Majutsu no Index II", + "とある魔術の禁書目録II", + "Toaru Majutsu no Index 2", + "Toaru Majutsu no Kinsho Mokuroku 2", + "魔法禁书目录第二季", + "魔法禁书目录 2", + "อินเดกซ์คัมภีร์คาถาต้องห้าม ภาค 2", + "Cấm thư ma thuật Index II", + "Daftar Sihir Terlarang II", ], name: [ - "Atsuko Kawai", - "河合厚子", + "William Orwell", + "ウィリアム=オルウェル (後方のアックア)", + "Acqua of the Back", + "Flere210", ], - popularity: 1331, - rating: 1, + popularity: 83410, + rating: 2, role: "SUPPORTING", }, { - id: "anilist:302741", - mediaId: "anilist:1040", + id: "anilist:122432", + mediaId: "anilist:21517", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "Love Tyrant", + "Renai Boukun", + "恋愛暴君", + "The very lovely tyrant of love♥", ], name: [ - "Toshiko Kawai", - "河合敏子", + "Akua Aino", + "藍野あくあ", ], - popularity: 1331, - rating: 1, + popularity: 71328, + rating: 2, role: "SUPPORTING", }, { - id: "anilist:167676", - mediaId: "anilist:1040", + id: "anilist:18866", + mediaId: "anilist:10080", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "The World God Only Knows II", + "Kami nomi zo Shiru Sekai II", + "神のみぞ知るセカイⅡ", + "Kami nomi zo Shiru Sekai 2", + "Kaminomi II", + "The World God Only Knows 2", ], name: [ - "Hiroshi Naganuma", - "長沼博士", + "Haqua du Lot Herminium", + "ハクア・ド・ロット・ヘルミニウム", + "Haq-chan", ], - popularity: 1331, - rating: 1, - role: "MAIN", + popularity: 64447, + rating: 2, + role: "SUPPORTING", }, { - id: "anilist:168479", - mediaId: "anilist:1040", + id: "anilist:37096", + mediaId: "anilist:8086", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "The Legend of the Legendary Heroes", + "Densetsu no Yuusha no Densetsu", + "伝説の勇者の伝説", + "DenYuDen", + "DenYuuDen", + "Densetsu no Yusha no Densetsu", + "LOLH", + "传说的勇者的传说", ], name: [ - "Rumiko Hirayama", - "平山るみ子", + "Arua", + "アルア", ], - popularity: 1331, + popularity: 43652, rating: 1, role: "SUPPORTING", }, { - id: "anilist:302745", - mediaId: "anilist:1040", + id: "anilist:227577", + mediaId: "anilist:113290", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "Scissor Seven Season 2", + "Wu Liuqi: Zui Qiang Faxingshi", + "伍六七之最强发型师", + "Killer Seven Season 2", + "Киллер с ножницами 2", ], name: [ - "Mari Sengawa", - "仙川万里", - "Maririn", + "Chiya", + "赤牙", + "Redtooth", + "Aquan (阿权)", + "Crimson Fang", ], - popularity: 1331, + popularity: 19179, rating: 1, role: "SUPPORTING", }, { - id: "anilist:302747", - mediaId: "anilist:1040", + id: "anilist:232854", + mediaId: "anilist:110810", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "Kandagawa Jet Girls", + "Kandagawa JET GIRLS", + "神田川JET GIRLS", ], name: [ - "Shikito Hashimoto", - "橋本識人", - "Hashimo", + "Akua Manjou", + "万条あくあ", ], - popularity: 1331, + popularity: 12501, rating: 1, role: "SUPPORTING", }, { - id: "anilist:167677", - mediaId: "anilist:1040", + id: "anilist:31949", + mediaId: "anilist:33403", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "Rosario+Vampire: Season II", + "Rosario to Vampire: Season II", + "ロザリオとバンパイア SeasonⅡ", + "Rosario and Vampire: Season 2", + "Rosario+Vampire - Tılsımlı Kolye ve Vampir - Sezon 2", + "Rosario to Vampire II", ], name: [ - "Takako Takahata", - "高幡多可子", - "Rika", + "Akua Shuzen", + "朱染 亞愛", + "Black Devil", ], - popularity: 1331, + popularity: 11747, rating: 1, - role: "MAIN", + role: "SUPPORTING", }, { - id: "anilist:167675", - mediaId: "anilist:1040", + id: "anilist:326120", + mediaId: "anilist:164857", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "Surviving the Game as a Barbarian", + "Game Sok Babarian-euro Saranamgi", + "게임 속 바바리안으로 살아남기", + "Surviving The Game as a Barbarian", ], name: [ - "Yuuko Kawai", - "河合優子", - "Yumi", + "Arua Raven", + "아루아 레이븐", + "Aru", ], - popularity: 1331, + popularity: 5806, rating: 1, - role: "MAIN", + role: "SUPPORTING", }, { - id: "anilist:302744", - mediaId: "anilist:1040", + id: "anilist:263083", + mediaId: "anilist:143289", mediaTitle: [ - "Mizuiro Jidai", - "水色時代", - "Aqua Age", - "Blue Green Years", - "Temi d'amore", - "Temi d'amore tra i banchi di scuola", + "ESTAB LIFE: Great Escape", + "Estab-Life: Great Escape", + "エスタブライフ グレイトエスケープ", + "エスタブライフ", ], name: [ - "Fuyuki Miyauchi", - "宮内冬紀", - "Miyau", + "Equa", + "エクア", ], - popularity: 1331, + popularity: 3601, rating: 1, - role: "SUPPORTING", + role: "MAIN", }, ] `; @@ -1022,7 +1021,7 @@ snapshot[`characters search > sayuri haruno 1`] = ` role: "MAIN", }, { - id: "anilist:145", + id: "anilist:67289", mediaId: "anilist:20", mediaTitle: [ "Naruto", @@ -1035,15 +1034,15 @@ snapshot[`characters search > sayuri haruno 1`] = ` "Наруто", ], name: [ - "Sakura Haruno", - "春野サクラ", + "Mebuki Haruno", + "春野メブキ", ], popularity: 536323, - rating: 5, - role: "MAIN", + rating: 4, + role: "SUPPORTING", }, { - id: "anilist:67289", + id: "anilist:145", mediaId: "anilist:20", mediaTitle: [ "Naruto", @@ -1056,12 +1055,12 @@ snapshot[`characters search > sayuri haruno 1`] = ` "Наруто", ], name: [ - "Mebuki Haruno", - "春野メブキ", + "Sakura Haruno", + "春野サクラ", ], popularity: 536323, - rating: 4, - role: "SUPPORTING", + rating: 5, + role: "MAIN", }, { id: "anilist:67287", @@ -1490,6 +1489,447 @@ snapshot[`characters search > sayuri haruno 1`] = ` ] `; +snapshot[`characters search > jahy 1`] = ` +[ + { + id: "anilist:124618", + mediaId: "anilist:132456", + mediaTitle: [ + "The Great Jahy Will Not Be Defeated!", + "Jahy-sama wa Kujikenai!", + "ジャヒー様はくじけない!", + "ท่านปีศาจจาฮี ชีวิตนี้ไม่มีถอย!", + "Niepokonana Jahy", + ], + name: [ + "Jahy", + "ジャヒー", + "Hy-chan", + "Ja-ko", + "Sweet-hy", + "Best-hy", + ], + popularity: 66461, + rating: 3, + role: "MAIN", + }, + { + id: "anilist:257292", + mediaId: "anilist:111764", + mediaTitle: [ + "Maou no Musume wa Yasashi Sugiru!!", + "魔王の娘は優しすぎる!!", + "The Demon King’s Daughter is too kind", + ], + name: [ + "Jahy", + "ジャヒー", + ], + popularity: 4945, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:299038", + mediaId: "anilist:21", + mediaTitle: [ + "ONE PIECE", + "ワンピース", + "海贼王", + "וואן פיס", + "ون بيس", + "วันพีซ", + "Vua Hải Tặc", + "All'arrembaggio!", + "Tutti all'arrembaggio!", + "Ντρέηκ, το Κυνήγι του Θησαυρού", + ], + name: [ + "Saint Jaygarcia Saturn", + "ジェイガルシア・サターン聖", + "Jaygarcia Saturn", + "Jay Garcia Saturn", + "Saturn", + ], + popularity: 523387, + rating: 4, + role: "SUPPORTING", + }, + { + id: "anilist:23080", + mediaId: "anilist:1735", + mediaTitle: [ + "Naruto: Shippuden", + "NARUTO: Shippuuden", + "NARUTO -ナルト- 疾風伝", + "Naruto Shippuuden", + "Naruto Shippuden", + "נארוטו שיפודן", + "火影忍者 疾风传", + "นารูโตะ ตำนานวายุสลาตัน", + "ناروتو شيبودن", + ], + name: [ + "Jei", + "ジェイ", + "Jay", + ], + popularity: 456856, + rating: 4, + role: "SUPPORTING", + }, + { + id: "anilist:306519", + mediaId: "anilist:105398", + mediaTitle: [ + "Solo Leveling", + "Na Honjaman Level Up", + "나 혼자만 레벨업", + "I Level Up Alone", + "Only I Level Up", + "俺だけレベルアップな件", + "我獨自升級", + "Тільки я візьму новий рівень", + "Ore dake Level Up na Ken", + ], + name: [ + "Jay Mills", + "제이밀스", + ], + popularity: 207751, + rating: 1, + role: "BACKGROUND", + }, + { + id: "anilist:9476", + mediaId: "anilist:20574", + mediaTitle: [ + "Hi Score Girl", + "ハイスコアガール", + ], + name: [ + "Dee Jay", + ], + popularity: 58142, + rating: 1, + role: "BACKGROUND", + }, + { + id: "anilist:288290", + mediaId: "anilist:125828", + mediaTitle: [ + "Sakamoto Days", + "SAKAMOTO DAYS", + "Дни Сакамото", + "SAKAMOTO DAYS 坂本日常", + ], + name: [ + "Yanaya Shi", + "ヤナヤ・ツー", + "Jay Erk", + "Kill Baby (キルベイビー)", + ], + popularity: 52895, + rating: 2, + role: "SUPPORTING", + }, + { + id: "anilist:83649", + mediaId: "anilist:30564", + mediaTitle: [ + "Gantz", + "GANTZ", + "ガンツ", + "Gantz/Osaka", + ], + name: [ + "Jay Jay", + "ジェイジェイ", + "JJ", + ], + popularity: 52740, + rating: 2, + role: "SUPPORTING", + }, + { + id: "anilist:83925", + mediaId: "anilist:12431", + mediaTitle: [ + "Space Brothers", + "Uchuu Kyoudai", + "宇宙兄弟", + "Uchu Kyodai", + "Space Bros", + ], + name: [ + "Brian Jay", + ], + popularity: 39838, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:126850", + mediaId: "anilist:12431", + mediaTitle: [ + "Space Brothers", + "Uchuu Kyoudai", + "宇宙兄弟", + "Uchu Kyodai", + "Space Bros", + ], + name: [ + "Eddie Jay", + ], + popularity: 39838, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:249142", + mediaId: "anilist:138060", + mediaTitle: [ + "Star Wars: Visions", + "スター・ウォーズ:ビジョンズ", + "Star Wars ビジョンズ", + "Gwiezdne wojny: Wizje", + ], + name: [ + "Jay", + "ジェイ", + ], + popularity: 32957, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:137282", + mediaId: "anilist:86099", + mediaTitle: [ + "Wind Breaker", + "윈드브레이커", + ], + name: [ + "Ja-Hyeon Jo", + "조자현", + "Ja-Hyun Jo", + "Jay Jo", + "Lord Jay", + "Lord Of The Bike", + "God of Drifting", + "Super Rookie", + ], + popularity: 31142, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:140381", + mediaId: "anilist:86848", + mediaTitle: [ + "Lookism", + "Oemojisangjuui", + "외모지상주의", + "外見至上主義", + "APARI3NCIAS", + ], + name: [ + "Jae-Yeol Hong", + "홍재열", + "Jay Hong", + ], + popularity: 29409, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:174317", + mediaId: "anilist:119174", + mediaTitle: [ + "The Boxer", + "더 복서", + "El boxeador", + "ザ・ボクサー", + "拳击手", + ], + name: [ + "Jay", + "인재", + "Injae", + ], + popularity: 27447, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:314605", + mediaId: "anilist:158530", + mediaTitle: [ + "The Gene of AI", + "AI no Idenshi", + "AIの遺電子", + "Ген ИИ", + ], + name: [ + "Jay", + "ジェイ", + ], + popularity: 13449, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:321372", + mediaId: "anilist:170935", + mediaTitle: [ + "GREAT PRETENDER razbliuto", + "GREAT PRETENDER: razbliuto", + "グレートプリテンダー ラズブリウト", + "グレプリrazbliuto", + "GrePre razbliuto", + ], + name: [ + "Pinjue Jiang", + "江品爵", + "Jay (ジェイ)", + "Chiang P'in Chüeh", + ], + popularity: 12867, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:176280", + mediaId: "anilist:100341", + mediaTitle: [ + "LAST HOPE", + "Juushinki Pandora", + "重神機パンドーラ", + "الأمل الأخير", + "重神机潘多拉", + ], + name: [ + "Jay Yun", + "ジェイ・ユン", + ], + popularity: 9096, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:6525", + mediaId: "anilist:548", + mediaTitle: [ + "Sky Blue", + "Wonderful Days", + "원더풀 데이즈", + "Tage der Hoffnung", + ], + name: [ + "Jay", + "ジェイ", + ], + popularity: 5001, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:135722", + mediaId: "anilist:100083", + mediaTitle: [ + "Butlers x Battlers", + "Butlers: Chitose Momotose Monogatari", + "Butlers~千年百年物語~", + ], + name: [ + "Kouma Jinguuji", + "神宮司高馬", + "ジェイ", + "Jay", + ], + popularity: 4602, + rating: 1, + role: "MAIN", + }, + { + id: "anilist:3945", + mediaId: "anilist:447", + mediaTitle: [ + "Knight Hunters", + "Weiß kreuz", + "Weiß kreuz ヴァイス クロイツ", + "Weiss Kreuz", + "White Cross", + ], + name: [ + "Farfarello", + "ファルファレロ", + "Jei", + "Jay", + ], + popularity: 2643, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:37036", + mediaId: "anilist:2705", + mediaTitle: [ + "Bakusou Kyoudai Let's & Go!!", + "爆走兄弟レッツ&ゴー!!", + "Bakuso Kyodai Let's & Go", + "The Racing Brothers", + "سابق ولاحق", + ], + name: [ + "J", + "Jay", + ], + popularity: 2290, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:13248", + mediaId: "anilist:2592", + mediaTitle: [ + "Kimera", + "祈明羅", + "Ki*Me*Ra", + ], + name: [ + "Jay", + ], + popularity: 1667, + rating: 1, + role: "SUPPORTING", + }, + { + id: "anilist:18764", + mediaId: "anilist:34218", + mediaTitle: [ + "Megami Ibunroku: Persona", + "女神異聞録ペルソナ", + "Shin Megami Tensei: Persona", + "Persona - Be Your True Mind", + "Megami Inbun Roku Persona", + "女神異聞録 ~ペルソナ~ BE YOUR TRUE MIND", + ], + name: [ + "Naoya Toudou", + "藤堂尚也", + "Nao", + "Boy With The Pierced Ear", + "Jihei Suzakuin", + "Jay", + ], + popularity: 1573, + rating: 1, + role: "MAIN", + }, +] +`; + snapshot[`media search > konosuba 1`] = ` [ { @@ -1595,7 +2035,7 @@ snapshot[`media search > konosuba 1`] = ` }, { id: "anilist:97080", - popularity: 3068, + popularity: 3094, title: [ "Konosuba: An Explosion on This Wonderful World!", "Kono Subarashii Sekai ni Bakuen wo!", diff --git a/tests/merge.test.ts b/tests/merge.test.ts index 8c9ab41c..1d751e46 100644 --- a/tests/merge.test.ts +++ b/tests/merge.test.ts @@ -1407,6 +1407,17 @@ Deno.test('/merge', async (test) => { const timeStub = new FakeTime(); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const fetchStub = stub( utils, 'fetchWithRetry', @@ -1613,6 +1624,7 @@ Deno.test('/merge', async (test) => { fetchStub.restore(); listStub.restore(); + mongoClientStub.restore(); isDisabledStub.restore(); timeStub.restore(); charactersStub.restore(); @@ -1676,6 +1688,17 @@ Deno.test('/merge', async (test) => { () => undefined as any, ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -1871,6 +1894,7 @@ Deno.test('/merge', async (test) => { fetchStub.restore(); listStub.restore(); + mongoClientStub.restore(); isDisabledStub.restore(); timeStub.restore(); charactersStub.restore(); @@ -1934,6 +1958,17 @@ Deno.test('/merge', async (test) => { () => undefined as any, ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -2106,6 +2141,7 @@ Deno.test('/merge', async (test) => { delete config.synthesis; fetchStub.restore(); + mongoClientStub.restore(); listStub.restore(); isDisabledStub.restore(); timeStub.restore(); @@ -2127,6 +2163,17 @@ Deno.test('/merge', async (test) => { ] as any), ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -2280,6 +2327,7 @@ Deno.test('/merge', async (test) => { delete config.synthesis; fetchStub.restore(); + mongoClientStub.restore(); listStub.restore(); timeStub.restore(); @@ -2299,6 +2347,17 @@ Deno.test('/merge', async (test) => { ] as any), ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -2446,6 +2505,7 @@ Deno.test('/merge', async (test) => { delete config.synthesis; fetchStub.restore(); + mongoClientStub.restore(); listStub.restore(); timeStub.restore(); @@ -2465,6 +2525,17 @@ Deno.test('/merge', async (test) => { ] as any), ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -2604,6 +2675,7 @@ Deno.test('/merge', async (test) => { delete config.synthesis; fetchStub.restore(); + mongoClientStub.restore(); listStub.restore(); timeStub.restore(); @@ -2635,6 +2707,17 @@ Deno.test('/merge', async (test) => { ]), ); + const mongoClientStub = stub( + db, + 'newMongo', + () => + ({ + connect: () => ({ + close: () => undefined, + }), + }) as any, + ); + const getGuildStub = stub( db, 'getGuild', @@ -2723,6 +2806,7 @@ Deno.test('/merge', async (test) => { delete config.synthesis; fetchStub.restore(); + mongoClientStub.restore(); listStub.restore(); timeStub.restore(); diff --git a/tests/party.test.ts b/tests/party.test.ts index bae2b8ad..e91cee0a 100644 --- a/tests/party.test.ts +++ b/tests/party.test.ts @@ -464,11 +464,11 @@ Deno.test('/party view', async (test) => { { components: [], attachments: [ - { filename: 'image%201.webp', id: '0' }, - { filename: 'image%202.webp', id: '1' }, - { filename: 'image%203.webp', id: '2' }, - { filename: 'image%204.webp', id: '3' }, - { filename: 'image%205.webp', id: '4' }, + { filename: 'image1.webp', id: '0' }, + { filename: 'image2.webp', id: '1' }, + { filename: 'image3.webp', id: '2' }, + { filename: 'image4.webp', id: '3' }, + { filename: 'image5.webp', id: '4' }, ], embeds: [ { @@ -480,7 +480,7 @@ Deno.test('/party view', async (test) => { }, ], thumbnail: { - url: 'attachment://image%201.webp', + url: 'attachment://image1.webp', }, footer: { text: 'LVL 1' }, description: @@ -495,7 +495,7 @@ Deno.test('/party view', async (test) => { }, ], thumbnail: { - url: 'attachment://image%202.webp', + url: 'attachment://image2.webp', }, footer: { text: 'LVL 1' }, description: @@ -510,7 +510,7 @@ Deno.test('/party view', async (test) => { }, ], thumbnail: { - url: 'attachment://image%203.webp', + url: 'attachment://image3.webp', }, footer: { text: 'LVL 1' }, description: @@ -525,7 +525,7 @@ Deno.test('/party view', async (test) => { }, ], thumbnail: { - url: 'attachment://image%204.webp', + url: 'attachment://image4.webp', }, footer: { text: 'LVL 1' }, description: @@ -540,7 +540,7 @@ Deno.test('/party view', async (test) => { }, ], thumbnail: { - url: 'attachment://image%205.webp', + url: 'attachment://image5.webp', }, footer: { text: 'LVL 1' }, description: @@ -1913,11 +1913,11 @@ Deno.test('/party swap', async (test) => { { components: [], attachments: [ - { filename: 'image%201.webp', id: '0' }, - { filename: 'image%202.webp', id: '1' }, - { filename: 'image%203.webp', id: '2' }, - { filename: 'image%204.webp', id: '3' }, - { filename: 'image%205.webp', id: '4' }, + { filename: 'image1.webp', id: '0' }, + { filename: 'image2.webp', id: '1' }, + { filename: 'image3.webp', id: '2' }, + { filename: 'image4.webp', id: '3' }, + { filename: 'image5.webp', id: '4' }, ], embeds: [ { @@ -1929,7 +1929,7 @@ Deno.test('/party swap', async (test) => { }, ], thumbnail: { - url: 'attachment://image%201.webp', + url: 'attachment://image1.webp', }, footer: { text: 'LVL 1' }, description: @@ -1944,7 +1944,7 @@ Deno.test('/party swap', async (test) => { }, ], thumbnail: { - url: 'attachment://image%202.webp', + url: 'attachment://image2.webp', }, footer: { text: 'LVL 1' }, description: @@ -1959,7 +1959,7 @@ Deno.test('/party swap', async (test) => { }, ], thumbnail: { - url: 'attachment://image%203.webp', + url: 'attachment://image3.webp', }, footer: { text: 'LVL 1' }, description: @@ -1974,7 +1974,7 @@ Deno.test('/party swap', async (test) => { }, ], thumbnail: { - url: 'attachment://image%204.webp', + url: 'attachment://image4.webp', }, footer: { text: 'LVL 1' }, description: @@ -1989,7 +1989,7 @@ Deno.test('/party swap', async (test) => { }, ], thumbnail: { - url: 'attachment://image%205.webp', + url: 'attachment://image5.webp', }, footer: { text: 'LVL 1' }, description: diff --git a/tests/search-index.test.ts b/tests/search-index.test.ts index c66ff839..715aec45 100644 --- a/tests/search-index.test.ts +++ b/tests/search-index.test.ts @@ -82,6 +82,22 @@ Deno.test('characters search', async (test) => { } }); + await test.step('jahy', async (test) => { + const listStub = stub(packs, 'all', () => + Promise.resolve([ + { manifest: { id: 'anilist' } }, + ] as any)); + + try { + await assertSnapshot( + test, + await toString(searchIndex.searchCharacters('jahy', '')), + ); + } finally { + listStub.restore(); + } + }); + // await test.step('konosuba', async (test) => { // const listStub = stub(packs, 'all', () => // Promise.resolve([ diff --git a/tests/search.test.ts b/tests/search.test.ts index b403e7d6..d9dfd455 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -891,7 +891,7 @@ Deno.test('/media', async (test) => { value: 'main character description', }], thumbnail: { - url: 'attachment://main%20character%20url.webp', + url: 'attachment://maincharacterurl.webp', }, }, { type: 'rich', @@ -900,7 +900,7 @@ Deno.test('/media', async (test) => { value: 'supporting character description', }], thumbnail: { - url: 'attachment://supporting%20character%20url.webp', + url: 'attachment://supportingcharacterurl.webp', }, }], components: [{ @@ -914,8 +914,8 @@ Deno.test('/media', async (test) => { }], attachments: [ { filename: 'image-url.webp', id: '0' }, - { filename: 'main%20character%20url.webp', id: '1' }, - { filename: 'supporting%20character%20url.webp', id: '2' }, + { filename: 'maincharacterurl.webp', id: '1' }, + { filename: 'supportingcharacterurl.webp', id: '2' }, ], }, ); diff --git a/tests/user.test.ts b/tests/user.test.ts index c299e161..6497ed24 100644 --- a/tests/user.test.ts +++ b/tests/user.test.ts @@ -23,7 +23,8 @@ import { MediaRelation, MediaType, } from '~/src/types.ts'; -import { DisaggregatedMedia } from '~/src/types.ts'; + +import type { DisaggregatedMedia } from '~/src/types.ts'; Deno.test('/now', async (test) => { await test.step('with pulls', async () => { @@ -5975,7 +5976,7 @@ Deno.test('/collection sum', async (test) => { 'getInventory', () => ({ - party: { member1Id: '1' }, + party: { member1: { characterId: 'anilist:1' } }, user: { likes: [{ characterId: 'anilist:2' }] }, }) as any, );