objectid-utils.test.ts 909 B

123456789101112131415161718192021222324252627
  1. import ObjectId from 'bson-objectid';
  2. import { isValidObjectId } from '~/utils/objectid-utils';
  3. describe('isValidObjectId', () => {
  4. /* eslint-disable indent */
  5. describe.each`
  6. arg | expected
  7. ${undefined} | ${false}
  8. ${null} | ${false}
  9. ${'geeks'} | ${false}
  10. ${'toptoptoptop'} | ${false}
  11. ${'geeksfogeeks'} | ${false}
  12. ${'594ced02ed345b2b049222c5'} | ${true}
  13. ${new ObjectId('594ced02ed345b2b049222c5')} | ${true}
  14. `('should return $expected', ({ arg, expected }) => {
  15. test(`when the argument is '${arg}'`, async() => {
  16. // when:
  17. const result = isValidObjectId(arg);
  18. // then:
  19. expect(result).toBe(expected);
  20. });
  21. });
  22. });