Commit 3dec0f11 authored by Randall Leeds's avatar Randall Leeds

Persona filter tests and pass-through behavior

Allow the persona filter to pass invalid account URIs through unharmed.
parent a4ce9479
......@@ -26,8 +26,12 @@ momentFilter = ->
persona = (user, part='username') ->
part = ['term', 'username', 'provider'].indexOf(part)
(user?.match /^acct:([^@]+)@(.+)/)?[part]
index = ['term', 'username', 'provider'].indexOf(part)
groups = user?.match /^acct:([^@]+)@(.+)/
if groups
groups[index]
else if part != 'provider'
user
angular.module('h')
......
assert = chai.assert
sinon.assert.expose assert, prefix: null
describe 'persona', ->
filter = null
term = 'acct:hacker@example.com'
beforeEach module('h')
beforeEach inject ($filter) ->
filter = $filter('persona')
it 'should return the whole term by request', ->
assert.equal filter('acct:hacker@example.com', 'term'), 'acct:hacker@example.com'
it 'should return the requested part', ->
assert.equal filter(term), 'hacker'
assert.equal filter(term, 'term'), term,
assert.equal filter(term, 'username'), 'hacker'
assert.equal filter(term, 'provider'), 'example.com'
it 'should pass through unrecognized terms as username or term', ->
assert.equal filter('bogus'), 'bogus'
assert.equal filter('bogus', 'username'), 'bogus'
it 'should handle error cases', ->
assert.notOk filter()
assert.notOk filter('bogus', 'provider')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment