2018-07-12 01:58:05 +02:00
|
|
|
import assert from 'assert'
|
2018-07-11 17:46:55 +02:00
|
|
|
import { domainFormat } from '../../src/renderer/utils/validator'
|
|
|
|
|
|
|
|
describe('validator', () => {
|
|
|
|
describe('domainFormat', () => {
|
|
|
|
context('string contains protocol', () => {
|
|
|
|
const domain = 'https://mastodon.social'
|
|
|
|
it('should not match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, -1)
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
context('string contains account name', () => {
|
|
|
|
const domain = 'h3_poteto@mastodon.social'
|
|
|
|
it('should not match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, -1)
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
context('string is gTLD domain', () => {
|
|
|
|
const domain = 'mastodon.social'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, 0)
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
context('string is subdomain', () => {
|
|
|
|
const domain = 'music.mastodon.social'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, 0)
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|
2018-07-13 00:59:10 +02:00
|
|
|
context('string is subdomain', () => {
|
|
|
|
const domain = 'social.tchncs.de'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, 0)
|
2018-07-13 00:59:10 +02:00
|
|
|
})
|
|
|
|
})
|
2018-07-11 17:46:55 +02:00
|
|
|
context('string is jp domain', () => {
|
|
|
|
const domain = 'mstdn.co.jp'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, 0)
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|
2018-07-12 01:58:05 +02:00
|
|
|
context('string contains hyphone', () => {
|
|
|
|
const domain = 'music-mastodon.social'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
2018-07-28 14:49:06 +02:00
|
|
|
assert.strictEqual(res, 0)
|
2018-07-12 01:58:05 +02:00
|
|
|
})
|
|
|
|
})
|
2018-08-20 15:01:10 +02:00
|
|
|
context('string is short domain', () => {
|
|
|
|
const domain = 'id.cc'
|
|
|
|
it('should match', () => {
|
|
|
|
const res = domain.search(domainFormat)
|
|
|
|
assert.strictEqual(res, 0)
|
|
|
|
})
|
|
|
|
})
|
2018-07-11 17:46:55 +02:00
|
|
|
})
|
|
|
|
})
|