2024-11-24 13:51:44 +00:00
|
|
|
import * as assert from 'assert';
|
|
|
|
import { Test } from '@nestjs/testing';
|
|
|
|
|
|
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
|
|
import { UtilityService } from '@/core/UtilityService.js';
|
|
|
|
import { GlobalModule } from '@/GlobalModule.js';
|
|
|
|
|
|
|
|
describe('UtilityService', () => {
|
|
|
|
let utilityService: UtilityService;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
const app = await Test.createTestingModule({
|
|
|
|
imports: [GlobalModule, CoreModule],
|
|
|
|
}).compile();
|
|
|
|
utilityService = app.get<UtilityService>(UtilityService);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('punyHost', () => {
|
|
|
|
test('simple', () => {
|
2024-11-24 14:04:03 +00:00
|
|
|
assert.equal(utilityService.punyHost('http://www.foo.com'), 'www.foo.com');
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
|
|
|
test('japanese', () => {
|
2024-11-24 14:04:03 +00:00
|
|
|
assert.equal(utilityService.punyHost('http://www.新聞.com'), 'www.xn--efvv70d.com');
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('punyHostPSLDomain', () => {
|
|
|
|
test('simple', () => {
|
2024-11-24 14:04:03 +00:00
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://www.foo.com'), 'foo.com');
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
|
|
|
test('japanese', () => {
|
2024-11-24 14:04:03 +00:00
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://www.新聞.com'), 'xn--efvv70d.com');
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
|
|
|
test('lower', () => {
|
2024-11-24 14:04:03 +00:00
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://foo.github.io'), 'foo.github.io');
|
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://foo.bar.github.io'), 'bar.github.io');
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
2024-11-27 14:44:33 +00:00
|
|
|
test('special', () => {
|
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://foo.masto.host'), 'foo.masto.host');
|
|
|
|
assert.equal(utilityService.punyHostPSLDomain('http://foo.bar.masto.host'), 'bar.masto.host');
|
|
|
|
});
|
2024-11-24 13:51:44 +00:00
|
|
|
});
|
|
|
|
});
|