74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
apiBaseUrl,
|
|
applicationsUrl,
|
|
authorizationHeader,
|
|
integrationKey,
|
|
normalizeGiteaUrl,
|
|
notificationsCountUrl,
|
|
unreadCountFromResponse,
|
|
} from 'dashtab/config/gitea';
|
|
|
|
module('Unit | Config | gitea', function () {
|
|
test('normalizeGiteaUrl normalizes input and rejects junk', function (assert) {
|
|
assert.strictEqual(
|
|
normalizeGiteaUrl('git.example.com'),
|
|
'https://git.example.com'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeGiteaUrl('https://git.example.com/'),
|
|
'https://git.example.com'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeGiteaUrl('http://gitea.example.com'),
|
|
'http://gitea.example.com'
|
|
);
|
|
assert.strictEqual(normalizeGiteaUrl(''), null);
|
|
assert.strictEqual(normalizeGiteaUrl(' '), null);
|
|
assert.strictEqual(normalizeGiteaUrl('not a valid url'), null);
|
|
});
|
|
|
|
test('apiBaseUrl appends the /api/v1 prefix', function (assert) {
|
|
assert.strictEqual(
|
|
apiBaseUrl('https://git.example.com'),
|
|
'https://git.example.com/api/v1'
|
|
);
|
|
assert.strictEqual(apiBaseUrl(''), null);
|
|
});
|
|
|
|
test('endpoint URLs build on the instance origin', function (assert) {
|
|
assert.strictEqual(
|
|
notificationsCountUrl('https://git.example.com'),
|
|
'https://git.example.com/api/v1/notifications/new'
|
|
);
|
|
assert.strictEqual(
|
|
applicationsUrl('https://git.example.com'),
|
|
'https://git.example.com/user/settings/applications'
|
|
);
|
|
assert.strictEqual(applicationsUrl(''), null);
|
|
});
|
|
|
|
test('authorizationHeader prefixes the token', function (assert) {
|
|
assert.strictEqual(authorizationHeader('abc123'), 'token abc123');
|
|
});
|
|
|
|
test('unreadCountFromResponse reads the new count', function (assert) {
|
|
assert.strictEqual(unreadCountFromResponse({ new: 4 }), 4);
|
|
assert.strictEqual(unreadCountFromResponse({ new: 0 }), 0);
|
|
assert.strictEqual(unreadCountFromResponse({}), 0);
|
|
assert.strictEqual(unreadCountFromResponse(null), 0);
|
|
});
|
|
|
|
test('integrationKey is unique per host', function (assert) {
|
|
assert.strictEqual(
|
|
integrationKey('https://git.example.com'),
|
|
'gitea-git.example.com'
|
|
);
|
|
assert.strictEqual(
|
|
integrationKey('https://git.example.com:3000'),
|
|
'gitea-git.example.com:3000'
|
|
);
|
|
assert.strictEqual(integrationKey(''), null);
|
|
});
|
|
});
|