mirror of
https://github.com/wassname/talk.git
synced 2026-08-08 11:28:12 +08:00
Merge branch 'master' into 142993479-tags
This commit is contained in:
@@ -24,7 +24,7 @@ describe('graph.loaders.Metrics', () => {
|
||||
describe('different comment states', () => {
|
||||
|
||||
beforeEach(() =>[
|
||||
CommentModel.create( {id: '1', body: 'a new comment!'}),
|
||||
CommentModel.create({id: '1', body: 'a new comment!'}),
|
||||
CommentModel.create({id: '2', body: 'a new comment!'}),
|
||||
CommentModel.create({id: '3', body: 'a new comment!'})
|
||||
]);
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('graph.mutations.editComment', () => {
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
body: `hello there! ${ String(Math.random()).slice(2)}`,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
});
|
||||
|
||||
// body_history should be there
|
||||
@@ -64,6 +64,9 @@ describe('graph.mutations.editComment', () => {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
if (response.data.editComment.errors && response.data.editComment.errors.length > 0) {
|
||||
console.error(response.data.editComment.errors);
|
||||
}
|
||||
expect(response.data.editComment.errors).to.be.null;
|
||||
|
||||
// assert body has changed
|
||||
@@ -81,7 +84,7 @@ describe('graph.mutations.editComment', () => {
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
body: `hello there! ${ String(Math.random()).slice(2)}`,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
@@ -97,9 +100,12 @@ describe('graph.mutations.editComment', () => {
|
||||
body: newBody
|
||||
}
|
||||
});
|
||||
if (response.errors && response.errors.length > 0) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
expect(response.data.editComment.errors).to.not.be.empty;
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('error.editWindowExpired');
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('EDIT_WINDOW_ENDED');
|
||||
const commentAfterEdit = await CommentsService.findById(comment.id);
|
||||
|
||||
// it *hasn't* changed from the original
|
||||
@@ -110,7 +116,7 @@ describe('graph.mutations.editComment', () => {
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
body: `hello there! ${ String(Math.random()).slice(2)}`,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
});
|
||||
|
||||
const userB = await UsersService.createLocalUser(
|
||||
@@ -144,6 +150,9 @@ describe('graph.mutations.editComment', () => {
|
||||
body: newBody
|
||||
}
|
||||
});
|
||||
if (response.errors && response.errors.length > 0) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('NOT_FOUND');
|
||||
});
|
||||
|
||||
@@ -18,9 +18,11 @@ const ignoreUserMutation = `
|
||||
|
||||
const getMyIgnoredUsersQuery = `
|
||||
query myIgnoredUsers {
|
||||
myIgnoredUsers {
|
||||
id,
|
||||
username
|
||||
me {
|
||||
ignoredUsers {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -31,25 +33,32 @@ describe('graph.mutations.ignoreUser', () => {
|
||||
});
|
||||
|
||||
it('users can ignoreUser', async () => {
|
||||
const user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
let currentUser = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
const userToIgnore = await UsersService.createLocalUser('usernameB@example.com', 'password', 'usernameB');
|
||||
const context = new Context({user});
|
||||
let context = new Context({user: currentUser});
|
||||
|
||||
const ignoreUserResponse = await graphql(schema, ignoreUserMutation, {}, context, {id: userToIgnore.id});
|
||||
if (ignoreUserResponse.errors && ignoreUserResponse.errors.length) {
|
||||
console.error(ignoreUserResponse.errors);
|
||||
}
|
||||
expect(ignoreUserResponse.errors).to.be.empty;
|
||||
|
||||
// Refresh the user from the database and create the new context for the
|
||||
// request.
|
||||
currentUser = await UsersService.findById(currentUser.id);
|
||||
context = new Context({user: currentUser});
|
||||
|
||||
// now check my ignored users
|
||||
const myIgnoredUsersResponse = await graphql(schema, getMyIgnoredUsersQuery, {}, context, {});
|
||||
if (myIgnoredUsersResponse.errors && myIgnoredUsersResponse.errors.length) {
|
||||
console.error(myIgnoredUsersResponse.errors);
|
||||
}
|
||||
expect(myIgnoredUsersResponse.errors).to.be.empty;
|
||||
const myIgnoredUsers = myIgnoredUsersResponse.data.myIgnoredUsers;
|
||||
expect(myIgnoredUsers.length).to.equal(1);
|
||||
expect(myIgnoredUsers[0].id).to.equal(userToIgnore.id);
|
||||
expect(myIgnoredUsers[0].username).to.equal(userToIgnore.username);
|
||||
|
||||
const ignoredUsers = myIgnoredUsersResponse.data.me.ignoredUsers;
|
||||
expect(ignoredUsers.length).to.equal(1);
|
||||
expect(ignoredUsers[0].id).to.equal(userToIgnore.id);
|
||||
expect(ignoredUsers[0].username).to.equal(userToIgnore.username);
|
||||
});
|
||||
|
||||
it('users cannot ignore themselves', async () => {
|
||||
@@ -64,7 +73,7 @@ describe('graph.mutations.ignoreUser', () => {
|
||||
console.error(myIgnoredUsersResponse.errors);
|
||||
}
|
||||
expect(myIgnoredUsersResponse.errors).to.be.empty;
|
||||
const myIgnoredUsers = myIgnoredUsersResponse.data.myIgnoredUsers;
|
||||
const myIgnoredUsers = myIgnoredUsersResponse.data.me.ignoredUsers;
|
||||
expect(myIgnoredUsers.length).to.equal(0);
|
||||
});
|
||||
|
||||
@@ -80,22 +89,27 @@ describe('graph.mutations.stopIgnoringUser', () => {
|
||||
// We're going to ignore 2 users,
|
||||
// then stopIgnoring 1 of them
|
||||
// then assert myIgnoredUsers only lists the one remaining
|
||||
const user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
let currentUser = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
const usersToIgnore = await Promise.all([
|
||||
UsersService.createLocalUser('usernameB@example.com', 'password', 'usernameB'),
|
||||
UsersService.createLocalUser('usernameC@example.com', 'password', 'usernameC'),
|
||||
]);
|
||||
const context = new Context({user});
|
||||
let context = new Context({user: currentUser});
|
||||
|
||||
// ignore two users
|
||||
const ignoreUserResponses = await Promise.all(usersToIgnore.map(u => graphql(schema, ignoreUserMutation, {}, context, {id: u.id})));
|
||||
ignoreUserResponses.forEach(response => {
|
||||
const ignoreUserResponses = await Promise.all(usersToIgnore.map((u) => graphql(schema, ignoreUserMutation, {}, context, {id: u.id})));
|
||||
ignoreUserResponses.forEach((response) => {
|
||||
if (response.errors && response.errors.length) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
});
|
||||
|
||||
// Refresh the user from the database and create the new context for the
|
||||
// request.
|
||||
currentUser = await UsersService.findById(currentUser.id);
|
||||
context = new Context({user: currentUser});
|
||||
|
||||
const stopIgnoringUserMutation = `
|
||||
mutation stopIgnoringUser ($id: ID!) {
|
||||
stopIgnoringUser(id:$id) {
|
||||
@@ -113,13 +127,18 @@ describe('graph.mutations.stopIgnoringUser', () => {
|
||||
}
|
||||
expect(stopIgnoringUserResponse.errors).to.be.empty;
|
||||
|
||||
// Refresh the user from the database and create the new context for the
|
||||
// request.
|
||||
currentUser = await UsersService.findById(currentUser.id);
|
||||
context = new Context({user: currentUser});
|
||||
|
||||
// now check my ignored users
|
||||
const myIgnoredUsersResponse = await graphql(schema, getMyIgnoredUsersQuery, {}, context, {});
|
||||
if (myIgnoredUsersResponse.errors && myIgnoredUsersResponse.errors.length) {
|
||||
console.error(myIgnoredUsersResponse.errors);
|
||||
}
|
||||
expect(myIgnoredUsersResponse.errors).to.be.empty;
|
||||
const myIgnoredUsers = myIgnoredUsersResponse.data.myIgnoredUsers;
|
||||
const myIgnoredUsers = myIgnoredUsersResponse.data.me.ignoredUsers;
|
||||
expect(myIgnoredUsers.length).to.equal(1);
|
||||
expect(myIgnoredUsers[0].id).to.equal(usersToIgnore[1].id);
|
||||
expect(myIgnoredUsers[0].username).to.equal(usersToIgnore[1].username);
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('graph.mutations.removeTag', () => {
|
||||
let asset, comment;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
|
||||
asset = new AssetModel({url: 'http://new.test.com/'});
|
||||
await asset.save();
|
||||
|
||||
|
||||
@@ -9,85 +9,90 @@ const Asset = require('../../../../models/asset');
|
||||
const CommentsService = require('../../../../services/comments');
|
||||
|
||||
describe('graph.queries.asset', () => {
|
||||
let asset, users;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
asset = await Asset.create({id: '1', url: 'https://example.com'});
|
||||
users = await UsersService.createLocalUsers([
|
||||
{
|
||||
email: 'usernameA@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameA'
|
||||
},
|
||||
{
|
||||
email: 'usernameB@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameB'
|
||||
},
|
||||
{
|
||||
email: 'usernameC@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameC'
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('can get comments edge', async () => {
|
||||
const assetId = 'fakeAssetId';
|
||||
const assetUrl = 'https://bengo.is';
|
||||
await Asset.create({id: assetId, url: assetUrl});
|
||||
|
||||
const user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
const context = new Context({user});
|
||||
const context = new Context({user: users[0]});
|
||||
|
||||
await CommentsService.publicCreate([1, 2].map(() => ({
|
||||
author_id: user.id,
|
||||
asset_id: assetId,
|
||||
body: `hello there! ${ String(Math.random()).slice(2)}`,
|
||||
author_id: users[0].id,
|
||||
asset_id: asset.id,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
})));
|
||||
|
||||
const assetCommentsQuery = `
|
||||
query assetCommentsQuery($assetId: ID!, $assetUrl: String!) {
|
||||
asset(id: $assetId, url: $assetUrl) {
|
||||
query assetCommentsQuery($id: ID!) {
|
||||
asset(id: $id) {
|
||||
comments(limit: 10) {
|
||||
id,
|
||||
body,
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const assetCommentsResponse = await graphql(schema, assetCommentsQuery, {}, context, {assetId, assetUrl});
|
||||
const comments = assetCommentsResponse.data.asset.comments;
|
||||
const res = await graphql(schema, assetCommentsQuery, {}, context, {id: asset.id});
|
||||
expect(res.erros).is.empty;
|
||||
const comments = res.data.asset.comments;
|
||||
expect(comments.length).to.equal(2);
|
||||
});
|
||||
|
||||
it('can query comments edge to exclude comments ignored by user', async () => {
|
||||
const assetId = 'fakeAssetId1';
|
||||
const assetUrl = 'https://bengo.is/1';
|
||||
await Asset.create({id: assetId, url: assetUrl});
|
||||
const context = new Context({user: users[0]});
|
||||
|
||||
const userA = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
const userB = await UsersService.createLocalUser('usernameB@example.com', 'password', 'usernameB');
|
||||
const userC = await UsersService.createLocalUser('usernameC@example.com', 'password', 'usernameC');
|
||||
const context = new Context({user: userA});
|
||||
|
||||
// create 2 comments each for userB, userC
|
||||
await Promise.all([userB, userC].map(user => CommentsService.publicCreate([1, 2].map(() => ({
|
||||
await Promise.all(users.slice(1, 3).map((user) => CommentsService.publicCreate({
|
||||
author_id: user.id,
|
||||
asset_id: assetId,
|
||||
body: `hello there! ${ String(Math.random()).slice(2)}`,
|
||||
})))));
|
||||
asset_id: asset.id,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
})));
|
||||
|
||||
// Add the second user to the list of ignored users.
|
||||
context.user.ignoresUsers.push(users[1].id);
|
||||
|
||||
// ignore userB
|
||||
const ignoreUserMutation = `
|
||||
mutation ignoreUser ($id: ID!) {
|
||||
ignoreUser(id:$id) {
|
||||
errors {
|
||||
translation_key
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const ignoreUserResponse = await graphql(schema, ignoreUserMutation, {}, context, {id: userB.id});
|
||||
if (ignoreUserResponse.errors && ignoreUserResponse.errors.length) {
|
||||
console.error(ignoreUserResponse.errors);
|
||||
}
|
||||
expect(ignoreUserResponse.errors).to.be.empty;
|
||||
|
||||
const assetCommentsWithoutIgnoredQuery = `
|
||||
query assetCommentsQuery($assetId: ID!, $assetUrl: String!, $excludeIgnored: Boolean!) {
|
||||
asset(id: $assetId, url: $assetUrl) {
|
||||
const query = `
|
||||
query assetCommentsQuery($id: ID!, $url: String!, $excludeIgnored: Boolean!) {
|
||||
asset(id: $id, url: $url) {
|
||||
comments(limit: 10, excludeIgnored: $excludeIgnored) {
|
||||
id,
|
||||
body,
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const assetCommentsResponse = await graphql(schema, assetCommentsWithoutIgnoredQuery, {}, context, {assetId, assetUrl, excludeIgnored: true});
|
||||
const comments = assetCommentsResponse.data.asset.comments;
|
||||
expect(comments.length).to.equal(2);
|
||||
|
||||
{
|
||||
const res = await graphql(schema, query, {}, context, {
|
||||
id: asset.id,
|
||||
url: asset.url,
|
||||
excludeIgnored: true
|
||||
});
|
||||
if (res.errors && res.errors.length) {
|
||||
console.error(res.errors);
|
||||
}
|
||||
expect(res.errors).is.empty;
|
||||
const comments = res.data.asset.comments;
|
||||
expect(comments.length).to.equal(1);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user