isBambuLabSpool.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Tests for isBambuLabSpool helper.
  3. *
  4. * The function is permissive: any non-empty non-zero value of tray_uuid OR
  5. * tag_uid returns true. It does NOT validate hex-length or character set —
  6. * its job is solely to suppress assign/unassign actions on RFID-managed slots
  7. * whose state is owned by the printer firmware.
  8. */
  9. import { describe, it, expect } from 'vitest';
  10. import { isBambuLabSpool } from '../../utils/amsHelpers';
  11. describe('isBambuLabSpool', () => {
  12. it('returns false for null', () => {
  13. expect(isBambuLabSpool(null)).toBe(false);
  14. });
  15. it('returns false for undefined', () => {
  16. expect(isBambuLabSpool(undefined)).toBe(false);
  17. });
  18. it('returns false for an empty object', () => {
  19. expect(isBambuLabSpool({})).toBe(false);
  20. });
  21. it('returns true for a valid 32-hex non-zero tray_uuid', () => {
  22. expect(
  23. isBambuLabSpool({ tray_uuid: '11223344556677880011223344556677' }),
  24. ).toBe(true);
  25. });
  26. it('returns false for the zero-string 32-char tray_uuid', () => {
  27. expect(
  28. isBambuLabSpool({ tray_uuid: '00000000000000000000000000000000' }),
  29. ).toBe(false);
  30. });
  31. it('returns true for a valid 16-hex non-zero tag_uid', () => {
  32. expect(isBambuLabSpool({ tag_uid: 'AABBCC1122334400' })).toBe(true);
  33. });
  34. it('returns false for the zero-string 16-char tag_uid', () => {
  35. expect(isBambuLabSpool({ tag_uid: '0000000000000000' })).toBe(false);
  36. });
  37. it('returns false when both fields are explicitly null', () => {
  38. expect(isBambuLabSpool({ tray_uuid: null, tag_uid: null })).toBe(false);
  39. });
  40. it('returns true when only tag_uid is set and tray_uuid is null', () => {
  41. expect(
  42. isBambuLabSpool({ tray_uuid: null, tag_uid: 'AABBCC1122334400' }),
  43. ).toBe(true);
  44. });
  45. it('returns true when only tray_uuid is set and tag_uid is null', () => {
  46. expect(
  47. isBambuLabSpool({
  48. tray_uuid: '11223344556677880011223344556677',
  49. tag_uid: null,
  50. }),
  51. ).toBe(true);
  52. });
  53. });