tests: refactor ffVisibility tests
Using some closures to partly generate the tests to achieve better coverage
This commit is contained in:
parent
352851f23f
commit
3d4df807b0
1 changed files with 80 additions and 131 deletions
|
@ -9,159 +9,108 @@ describe('FF visibility', () => {
|
||||||
|
|
||||||
let alice: any;
|
let alice: any;
|
||||||
let bob: any;
|
let bob: any;
|
||||||
let carol: any;
|
let follower: any;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
p = await startServer();
|
p = await startServer();
|
||||||
alice = await signup({ username: 'alice' });
|
alice = await signup({ username: 'alice' });
|
||||||
bob = await signup({ username: 'bob' });
|
bob = await signup({ username: 'bob' });
|
||||||
carol = await signup({ username: 'carol' });
|
follower = await signup({ username: 'follower' });
|
||||||
|
|
||||||
|
await request('/following/create', { userId: alice.id }, follower);
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
await shutdownServer(p);
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ffVisibility が public なユーザーのフォロー/フォロワーを誰でも見れる', async(async () => {
|
const visible = (user) => {
|
||||||
|
return async () => {
|
||||||
|
const followingRes = await request('/users/following', {
|
||||||
|
userId: alice.id,
|
||||||
|
}, user);
|
||||||
|
const followersRes = await request('/users/followers', {
|
||||||
|
userId: alice.id,
|
||||||
|
}, user);
|
||||||
|
|
||||||
|
assert.strictEqual(followingRes.status, 200);
|
||||||
|
assert.ok(Array.isArray(followingRes.body));
|
||||||
|
assert.strictEqual(followersRes.status, 200);
|
||||||
|
assert.ok(Array.isArray(followersRes.body));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const hidden = (user) => {
|
||||||
|
return async () => {
|
||||||
|
const followingRes = await request('/users/following', {
|
||||||
|
userId: alice.id,
|
||||||
|
}, user);
|
||||||
|
const followersRes = await request('/users/followers', {
|
||||||
|
userId: alice.id,
|
||||||
|
}, user);
|
||||||
|
|
||||||
|
assert.strictEqual(followingRes.status, 403);
|
||||||
|
assert.strictEqual(followersRes.status, 403);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('public visibility', () => {
|
||||||
|
before(async () => {
|
||||||
await request('/i/update', {
|
await request('/i/update', {
|
||||||
ffVisibility: 'public',
|
ffVisibility: 'public',
|
||||||
}, alice);
|
}, alice);
|
||||||
|
});
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
it('shows followers and following to self', visible(alice));
|
||||||
userId: alice.id,
|
it('shows followers and following to a follower', visible(follower));
|
||||||
}, bob);
|
it('shows followers and following to a non-follower', visible(bob));
|
||||||
const followersRes = await request('/users/followers', {
|
it('shows followers and following when unauthenticated', visible(null));
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
||||||
assert.strictEqual(followersRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followersRes.body), true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('ffVisibility が followers なユーザーのフォロー/フォロワーを自分で見れる', async(async () => {
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'followers',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, alice);
|
|
||||||
const followersRes = await request('/users/followers', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
||||||
assert.strictEqual(followersRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followersRes.body), true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('ffVisibility が followers なユーザーのフォロー/フォロワーを非フォロワーが見れない', async(async () => {
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'followers',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
const followersRes = await request('/users/followers', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 400);
|
|
||||||
assert.strictEqual(followersRes.status, 400);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('ffVisibility が followers なユーザーのフォロー/フォロワーをフォロワーが見れる', async(async () => {
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'followers',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
await request('/following/create', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
const followersRes = await request('/users/followers', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
||||||
assert.strictEqual(followersRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followersRes.body), true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('ffVisibility が private なユーザーのフォロー/フォロワーを自分で見れる', async(async () => {
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'private',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, alice);
|
|
||||||
const followersRes = await request('/users/followers', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
||||||
assert.strictEqual(followersRes.status, 200);
|
|
||||||
assert.strictEqual(Array.isArray(followersRes.body), true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('ffVisibility が private なユーザーのフォロー/フォロワーを他人が見れない', async(async () => {
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'private',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
const followingRes = await request('/users/following', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
const followersRes = await request('/users/followers', {
|
|
||||||
userId: alice.id,
|
|
||||||
}, bob);
|
|
||||||
|
|
||||||
assert.strictEqual(followingRes.status, 400);
|
|
||||||
assert.strictEqual(followersRes.status, 400);
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('AP', () => {
|
|
||||||
it('ffVisibility が public 以外ならばAPからは取得できない', async(async () => {
|
|
||||||
{
|
|
||||||
await request('/i/update', {
|
|
||||||
ffVisibility: 'public',
|
|
||||||
}, alice);
|
|
||||||
|
|
||||||
|
it('provides followers in ActivityPub representation', async () => {
|
||||||
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json');
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json');
|
||||||
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json');
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json');
|
||||||
assert.strictEqual(followingRes.status, 200);
|
assert.strictEqual(followingRes.status, 200);
|
||||||
assert.strictEqual(followersRes.status, 200);
|
assert.strictEqual(followersRes.status, 200);
|
||||||
}
|
});
|
||||||
{
|
});
|
||||||
|
|
||||||
|
describe('followers visibility', () => {
|
||||||
|
before(async () => {
|
||||||
await request('/i/update', {
|
await request('/i/update', {
|
||||||
ffVisibility: 'followers',
|
ffVisibility: 'followers',
|
||||||
}, alice);
|
}, alice);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows followers and following to self', visible(alice));
|
||||||
|
it('shows followers and following to a follower', visible(follower));
|
||||||
|
it('hides followers and following from a non-follower', hidden(bob));
|
||||||
|
it('hides followers and following when unauthenticated', hidden(null));
|
||||||
|
|
||||||
|
it('hides followers from ActivityPub representation', async () => {
|
||||||
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
||||||
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
||||||
assert.strictEqual(followingRes.status, 403);
|
assert.strictEqual(followingRes.status, 403);
|
||||||
assert.strictEqual(followersRes.status, 403);
|
assert.strictEqual(followersRes.status, 403);
|
||||||
}
|
});
|
||||||
{
|
});
|
||||||
|
|
||||||
|
describe('private visibility', () => {
|
||||||
|
before(async () => {
|
||||||
await request('/i/update', {
|
await request('/i/update', {
|
||||||
ffVisibility: 'private',
|
ffVisibility: 'private',
|
||||||
}, alice);
|
}, alice);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows followers and following to self', visible(alice));
|
||||||
|
it('hides followers and following from a follower', hidden(follower));
|
||||||
|
it('hides followers and following from a non-follower', hidden(bob));
|
||||||
|
it('hides followers and following when unauthenticated', hidden(null));
|
||||||
|
|
||||||
|
it('hides followers from ActivityPub representation', async () => {
|
||||||
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
||||||
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
||||||
assert.strictEqual(followingRes.status, 403);
|
assert.strictEqual(followingRes.status, 403);
|
||||||
assert.strictEqual(followersRes.status, 403);
|
assert.strictEqual(followersRes.status, 403);
|
||||||
}
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue