Determining UUIDs of players for Minecraft servers.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.test.ts 1.5 KiB

il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {describe, it, expect, vi} from 'vitest';
  2. import { getUsernameUuid } from '../src';
  3. import { EventEmitter } from 'events';
  4. describe('minecraft-uuid', () => {
  5. it('returns result (default offline mode)', async () => {
  6. vi.mock('crypto', () => ({
  7. createHash: (algo) => {
  8. return {
  9. update: () => {
  10. // noop
  11. },
  12. digest: () => Buffer.alloc(16, 0),
  13. };
  14. },
  15. }));
  16. const uuid = await getUsernameUuid({ username: 'username' });
  17. expect(uuid).toEqual('00000000-0000-3000-8000-000000000000');
  18. });
  19. it('returns result (explicit offline mode)', async () => {
  20. vi.mock('crypto', () => ({
  21. createHash: (algo) => {
  22. return {
  23. update: () => {
  24. // noop
  25. },
  26. digest: () => Buffer.alloc(16, 0),
  27. };
  28. },
  29. }));
  30. const uuid = await getUsernameUuid({ username: 'username', onlineMode: false });
  31. expect(uuid).toEqual('00000000-0000-3000-8000-000000000000');
  32. });
  33. it('returns result (explicit online mode)', async () => {
  34. vi.mock('https', () => ({
  35. get: (url, cb) => {
  36. const emitter = new EventEmitter();
  37. if (typeof cb === 'function') {
  38. (cb as unknown as (...args: unknown[]) => unknown)(emitter);
  39. }
  40. emitter.emit('data', Buffer.from(JSON.stringify({
  41. id: '82c683b548333d6b8a2606352cd6f327',
  42. name: 'username'
  43. })));
  44. emitter.emit('end');
  45. return emitter;
  46. },
  47. }));
  48. const uuid = await getUsernameUuid({ username: 'username', onlineMode: true });
  49. expect(uuid).toEqual('82c683b5-4833-3d6b-8a26-06352cd6f327');
  50. });
  51. });