5180 fichiers 38.5 Mo 0 téléchargements 426 vues mis à jour il y a 7 heures ui
index.test.ts 2.1 Ko Télécharger le fichier
import { existsSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import { GetRewardTrackTaskIconUrl } from '.';

/** The emulator is a sibling checkout whose folder name differs between setups; the first one that holds the migrations is used. */
const MIGRATIONS = ['Gameserver', 'emulatore', 'Polaris-Emulator', 'polaris']
    .map(folder => resolve(process.cwd(), '..', folder, 'Emulator/src/main/resources/db/migration'))
    .find(folder => existsSync(folder));

/** The action types the seeded tracks send, read from their INSERT rows ('track','task','action',...). */
const seededActions = (file: string): string[] => {
    const sql = readFileSync(resolve(MIGRATIONS as string, file), 'utf8');
    const actions = new Set<string>();

    for (const match of sql.matchAll(/INSERT IGNORE INTO `?reward_track_tasks`?[^;]*;/g)) {
        for (const row of match[0].matchAll(/\(\s*'[^']*'\s*,\s*'[^']*'\s*,\s*'([^']*)'/g)) actions.add(row[1]);
    }

    return [...actions];
};

describe('reward track task icons', () => {
    // Without the emulator checkout next to the client (as in this repository's CI) there is nothing to read the seeds from.
    it.skipIf(!MIGRATIONS)('has an icon for every task the Introduction track seeds', () => {
        const actions = seededActions('V20260927120000__reward_track_introduction.sql');

        expect(actions).toHaveLength(30);

        for (const action of actions) expect(GetRewardTrackTaskIconUrl(action), action).toBeTruthy();
    });

    it.skipIf(!MIGRATIONS)('has an icon for every task the demo season seeds', () => {
        for (const action of seededActions('V20260907220000__quests_daily_tasks_reward_tracks.sql')) {
            expect(GetRewardTrackTaskIconUrl(action), action).toBeTruthy();
        }
    });

    it('matches the action name case-insensitively and returns null for unknown actions', () => {
        expect(GetRewardTrackTaskIconUrl('CHAT_WITH_SOMEONE')).toBe(GetRewardTrackTaskIconUrl('chat_with_someone'));
        expect(GetRewardTrackTaskIconUrl('nope')).toBeNull();
        expect(GetRewardTrackTaskIconUrl(null)).toBeNull();
    });
});
15Sujets
1Dépôts
20Membres
3En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser