the browser-facing portion of osu!

updated currentUser for tests

bakaneko 4a40d41a f6f5c841

+81 -40
+10
tests/karma/beatmapset-search-filters.spec.ts
··· 2 2 // See the LICENCE file in the repository root for full licence text. 3 3 4 4 import { BeatmapsetSearchFilters } from 'beatmapset-search-filters'; 5 + import core from 'osu-core-singleton'; 6 + import testCurrentUserJson from './test-current-user-json'; 5 7 6 8 describe('BeatmapsetSearchFilters', () => { 7 9 let subject: BeatmapsetSearchFilters; 8 10 9 11 describe('.query', () => { 12 + beforeAll(() => { 13 + core.setCurrentUser(testCurrentUserJson); 14 + }); 15 + 16 + afterAll(() => { 17 + core.setCurrentUser({ id: undefined }); 18 + }); 19 + 10 20 beforeEach(() => { 11 21 subject = new BeatmapsetSearchFilters('https://notarealdomain'); 12 22 });
+2 -17
tests/karma/globals.js
··· 1 - /** 2 - * Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 3 - * 4 - * This file is part of osu!web. osu!web is distributed with the hope of 5 - * attracting more community contributions to the core ecosystem of osu!. 6 - * 7 - * osu!web is free software: you can redistribute it and/or modify 8 - * it under the terms of the Affero GNU General Public License version 3 9 - * as published by the Free Software Foundation. 10 - * 11 - * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied 12 - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 - * See the GNU Affero General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU Affero General Public License 16 - * along with osu!web. If not, see <http://www.gnu.org/licenses/>. 17 - */ 1 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 2 + // See the LICENCE file in the repository root for full licence text. 18 3 19 4 'use strict'; 20 5
+64
tests/karma/test-current-user-json.ts
··· 1 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 2 + // See the LICENCE file in the repository root for full licence text. 3 + 4 + import CurrentUserJson from 'interfaces/current-user-json'; 5 + import { defaultUserPreferencesJson } from 'interfaces/user-preferences-json'; 6 + 7 + const testCurrentUserJson: CurrentUserJson = { 8 + avatar_url: '', 9 + blocks: [], 10 + country: { 11 + code: 'AU', 12 + name: 'Australia', 13 + }, 14 + country_code: 'AU', 15 + cover: { custom_url: null, id: null, url: null }, 16 + default_group: '', 17 + discord: null, 18 + follow_user_mapping: [], 19 + friends: [], 20 + groups: [], 21 + has_supported: false, 22 + id: 1, 23 + interests: null, 24 + is_active: true, 25 + is_admin: false, 26 + is_bng: false, 27 + is_bot: false, 28 + is_deleted: false, 29 + is_full_bn: false, 30 + is_gmt: false, 31 + is_limited_bn: false, 32 + is_moderator: false, 33 + is_nat: false, 34 + is_online: true, 35 + is_restricted: false, 36 + is_silenced: false, 37 + is_supporter: true, 38 + join_date: '2020-01-01T12:34:56+00:00', 39 + kudosu: { 40 + available: 0, 41 + total: 0, 42 + }, 43 + last_visit: null, 44 + location: null, 45 + max_blocks: 1, 46 + max_friends: 1, 47 + occupation: null, 48 + playmode: 'osu', 49 + playstyle: [], 50 + pm_friends_only: false, 51 + post_count: 0, 52 + profile_colour: null, 53 + profile_hue: null, 54 + profile_order: [], 55 + title: null, 56 + title_url: null, 57 + twitter: null, 58 + unread_pm_count: 0, 59 + user_preferences: defaultUserPreferencesJson, 60 + username: 'foo', 61 + website: null, 62 + }; 63 + 64 + export default testCurrentUserJson;
+5 -23
tests/karma/utils/beatmapset-discussion-helper.spec.ts
··· 5 5 import GameMode from 'interfaces/ruleset'; 6 6 import UserGroupJson from 'interfaces/user-group-json'; 7 7 import UserJson from 'interfaces/user-json'; 8 - import User from 'models/user'; 9 8 import * as moment from 'moment'; 9 + import core from 'osu-core-singleton'; 10 10 import { discussionMode, isUserFullNominator, maxLengthTimeline, nearbyDiscussions, validMessageLength } from 'utils/beatmapset-discussion-helper'; 11 + import testCurrentUserJson from '../test-current-user-json'; 11 12 12 13 interface TestCase<T> { 13 14 description: string; ··· 33 34 user_id: 1, 34 35 }); 35 36 36 - const currentUser = new User(1); 37 - currentUser.updateWithJson({ 38 - avatar_url: '', 39 - country_code: '', 40 - cover: { custom_url: null, id: null, url: null }, 41 - default_group: '', 42 - id: 1, 43 - is_active: true, 44 - is_bot: false, 45 - is_deleted: false, 46 - is_online: true, 47 - is_supporter: true, 48 - last_visit: null, 49 - pm_friends_only: false, 50 - profile_colour: null, 51 - username: 'foo', 52 - }); 53 - 54 37 describe('utils/beatmapset-discussion-helper', () => { 55 38 describe('.discussionMode', () => { 56 39 const cases = [ ··· 89 72 }); 90 73 91 74 describe('.isUserFullNominator', () => { 92 - const userTemplate = currentUser.toJson(); 75 + const userTemplate = structuredClone(testCurrentUserJson); 93 76 const groupsTemplate: UserGroupJson = { 94 77 colour: null, 95 78 has_listing: true, ··· 184 167 }, 185 168 ]; 186 169 187 - // FIXME: need a better way of setting user in osu-core for tests. 188 170 beforeAll(() => { 189 - $.publish('user:update', currentUser); 171 + core.setCurrentUser(testCurrentUserJson); 190 172 }); 191 173 192 174 afterAll(() => { 193 - $.publish('user:update', {}); 175 + core.setCurrentUser({ id: undefined }); 194 176 }); 195 177 196 178 cases.forEach((test) => {