60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
authenticationUrl,
|
|
apiBaseUrl,
|
|
encodeBasicToken,
|
|
normalizeFeedbinUrl,
|
|
unreadCountUrl,
|
|
} from 'dashtab/config/feedbin';
|
|
|
|
module('Unit | Config | feedbin', function () {
|
|
test('normalizeFeedbinUrl normalizes input and rejects junk', function (assert) {
|
|
assert.strictEqual(
|
|
normalizeFeedbinUrl('feedbin.com'),
|
|
'https://feedbin.com'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeFeedbinUrl('https://feedbin.com/'),
|
|
'https://feedbin.com'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeFeedbinUrl('http://feedbin.example.com'),
|
|
'http://feedbin.example.com'
|
|
);
|
|
assert.strictEqual(normalizeFeedbinUrl(''), null);
|
|
assert.strictEqual(normalizeFeedbinUrl(' '), null);
|
|
assert.strictEqual(normalizeFeedbinUrl('http://'), null);
|
|
assert.strictEqual(normalizeFeedbinUrl('not a valid url'), null);
|
|
});
|
|
|
|
test('apiBaseUrl derives the api subdomain of the instance', function (assert) {
|
|
assert.strictEqual(apiBaseUrl(), 'https://api.feedbin.com');
|
|
assert.strictEqual(
|
|
apiBaseUrl('https://feedbin.example.com'),
|
|
'https://api.feedbin.example.com'
|
|
);
|
|
assert.strictEqual(
|
|
apiBaseUrl('https://api.example.com'),
|
|
'https://api.example.com'
|
|
);
|
|
});
|
|
|
|
test('endpoint URLs build on the derived api host', function (assert) {
|
|
assert.strictEqual(
|
|
authenticationUrl('https://feedbin.example.com'),
|
|
'https://api.feedbin.example.com/v2/authentication.json'
|
|
);
|
|
assert.strictEqual(
|
|
unreadCountUrl(),
|
|
'https://api.feedbin.com/v2/entries.json?read=false&per_page=1'
|
|
);
|
|
});
|
|
|
|
test('encodeBasicToken encodes the email and password pair', function (assert) {
|
|
assert.strictEqual(
|
|
encodeBasicToken('me@example.com', 'secret'),
|
|
btoa('me@example.com:secret')
|
|
);
|
|
});
|
|
});
|