5180 fichiers 38.5 Mo 0 téléchargements 221 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / wired / WiredUserVariableHolders.test.ts
WiredUserVariableHolders.test.ts 1.7 Ko Télécharger le fichier
import { describe, expect, it } from 'vitest';
import { decodeUserVariableHolder, findUserVariableHolderData, userVariableHolderKey } from './WiredUserVariableHolders';

describe('user variable holder keys', () => {
    it('matches the server keys for users, pets and bots', () => {
        expect(userVariableHolderKey('user', 7)).toBe(7);
        expect(userVariableHolderKey('pet', 7)).toBe(-14);
        expect(userVariableHolderKey('bot', 7)).toBe(-15);
        expect(userVariableHolderKey('rentable_bot', 7)).toBe(-15);
        expect(userVariableHolderKey('bot', -7)).toBe(-15);
        expect(userVariableHolderKey('pet', -7)).toBe(0);
        expect(userVariableHolderKey('pet', 0)).toBe(0);
    });

    it('decodes a key back to its holder', () => {
        expect(decodeUserVariableHolder(7)).toEqual({ kind: 'user', id: 7 });
        expect(decodeUserVariableHolder(-14)).toEqual({ kind: 'pet', id: 7 });
        expect(decodeUserVariableHolder(-15)).toEqual({ kind: 'bot', id: 7 });
        expect(decodeUserVariableHolder(0)).toBeNull();
    });

    it('looks the holder up with the getter of its kind', () => {
        const source = {
            getUserData: (id: number) => (id === 7 ? 'user 7' : null),
            getPetData: (id: number) => (id === 7 ? 'pet 7' : null),
            getBotData: () => null,
            getRentableBotData: (id: number) => (id === -7 ? 'rentable 7' : null)
        };

        expect(findUserVariableHolderData(source, 7)).toBe('user 7');
        expect(findUserVariableHolderData(source, -14)).toBe('pet 7');
        expect(findUserVariableHolderData(source, -15)).toBe('rentable 7');
        expect(findUserVariableHolderData(null, 7)).toBeNull();
    });
});
15Sujets
1Dépôts
20Membres
2En 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