compare-objectId.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Types } from 'mongoose';
  2. import { hasIntersection, includesObjectIds } from './compare-objectId';
  3. describe('Objectid comparison utils', () => {
  4. const id1 = new Types.ObjectId();
  5. const id2 = new Types.ObjectId();
  6. const id3 = new Types.ObjectId();
  7. const id4 = new Types.ObjectId();
  8. describe('includesObjectIds', () => {
  9. describe('When subset of array given', () => {
  10. const arr = [id1, id2, id3, id4];
  11. const subset = [id1, id4];
  12. it('returns true', () => {
  13. expect(includesObjectIds(arr, subset)).toBe(true);
  14. });
  15. });
  16. describe('When set that intersects with array given', () => {
  17. const arr = [id1, id2, id3];
  18. const subset = [id1, id4];
  19. it('returns false', () => {
  20. expect(includesObjectIds(arr, subset)).toBe(false);
  21. });
  22. });
  23. });
  24. describe('hasIntersection', () => {
  25. describe('When arrays have intersection', () => {
  26. const arr1 = [id1, id2, id3, id4];
  27. const arr2 = [id1, id4];
  28. it('returns true', () => {
  29. expect(hasIntersection(arr1, arr2)).toBe(true);
  30. });
  31. });
  32. describe("When arrays don't have intersection", () => {
  33. const arr1 = [id1, id2];
  34. const arr2 = [id3, id4];
  35. it('returns false', () => {
  36. expect(hasIntersection(arr1, arr2)).toBe(false);
  37. });
  38. });
  39. });
  40. });