0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-24 22:05:56 -05:00
logto/packages/toolkit/core-kit/src/regex.test.ts
2024-03-28 12:07:54 +08:00

27 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { domainRegEx } from './regex.js';
describe('Regular expressions should work as expected', () => {
it('should allow valid domains that consists of 3 parts. E.g. foo.bar.com', () => {
expect(domainRegEx.test('foo.bar.com')).toBe(true);
expect(domainRegEx.test('foo1.bar.com')).toBe(true);
expect(domainRegEx.test('foo.bar1.com')).toBe(true);
expect(domainRegEx.test('1foo.bar.com')).toBe(true);
expect(domainRegEx.test('f.bar.co')).toBe(true);
expect(domainRegEx.test('f.b.com')).toBe(true);
expect(domainRegEx.test('1.b.tk')).toBe(true);
});
it('should not allow domains that consists of 2 parts. E.g. bar.com', () => {
expect(domainRegEx.test('bar.com')).toBe(false);
expect(domainRegEx.test('b.co')).toBe(false);
});
it('should handle domains that contains dash in the middle. E.g. auth-gate.bar.com', () => {
expect(domainRegEx.test('auth-gate.bar.com')).toBe(true);
expect(domainRegEx.test('auth-.bar.com')).toBe(false);
expect(domainRegEx.test('-auth.bar.com')).toBe(false);
expect(domainRegEx.test('auth.bar-foo.com')).toBe(true);
});
});