Add tests for account utils
This commit is contained in:
parent
ce19fc3cde
commit
9a327139fe
2 changed files with 35 additions and 1 deletions
34
app/gabsocial/utils/__tests__/accounts-test.js
Normal file
34
app/gabsocial/utils/__tests__/accounts-test.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { getDomain, acctFull } from '../accounts';
|
||||
import { fromJS } from 'immutable';
|
||||
|
||||
describe('getDomain', () => {
|
||||
const account = fromJS({
|
||||
acct: 'alice',
|
||||
url: 'https://party.com/users/alice',
|
||||
});
|
||||
it('returns the domain', () => {
|
||||
expect(getDomain(account)).toEqual('party.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('acctFull', () => {
|
||||
describe('with a local user', () => {
|
||||
const account = fromJS({
|
||||
acct: 'alice',
|
||||
url: 'https://party.com/users/alice',
|
||||
});
|
||||
it('returns the full acct', () => {
|
||||
expect(acctFull(account)).toEqual('alice@party.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a remote user', () => {
|
||||
const account = fromJS({
|
||||
acct: 'bob@pool.com',
|
||||
url: 'https://pool.com/users/bob',
|
||||
});
|
||||
it('returns the full acct', () => {
|
||||
expect(acctFull(account)).toEqual('bob@pool.com');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
const getDomain = account => {
|
||||
export const getDomain = account => {
|
||||
let re = /https?:\/\/(.*?)\//i;
|
||||
return re.exec(account.get('url'))[1];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue