From 067371581d7d95c0be30b16b99ad65015580d70c Mon Sep 17 00:00:00 2001 From: Armin Date: Thu, 28 Feb 2019 03:40:00 +0100 Subject: [PATCH] Create article before shouting in test and add "shouted" step + disable send Create Activity when creating a post --- src/graphql-schema.js | 69 ++++++++++++++------------- test/features/activity-delete.feature | 2 +- test/features/activity-like.feature | 26 ++++++++-- test/features/support/steps.js | 14 ++++++ 4 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/graphql-schema.js b/src/graphql-schema.js index 65dfc8cda..bdf72c0a0 100644 --- a/src/graphql-schema.js +++ b/src/graphql-schema.js @@ -6,8 +6,10 @@ import uuid from 'uuid/v4' import { fixUrl } from './middleware/fixImageUrlsMiddleware' import { AuthenticationError } from 'apollo-server' import { neo4jgraphql } from 'neo4j-graphql-js' +/* import as from 'activitystrea.ms' import request from 'request' +*/ const debug = require('debug')('backend:schema') @@ -179,19 +181,20 @@ export const resolvers = { postId: result.id }) debug(`author = ${JSON.stringify(author, null, 2)}`) - const actorId = author.records[0]._fields[0].properties.actorId - const createActivity = await new Promise((resolve, reject) => { - as.create() - .id(`${actorId}/status/${params.activityId}`) - .actor(`${actorId}`) - .object( - as.article() - .id(`${actorId}/status/${result.id}`) - .content(result.content) - .to('https://www.w3.org/ns/activitystreams#Public') - .publishedNow() - .attributedTo(`${actorId}`) - ).prettyWrite((err, doc) => { + /* if (Array.isArray(author.records) && author.records.length > 0) { + const actorId = author.records[0]._fields[0].properties.actorId + const createActivity = await new Promise((resolve, reject) => { + as.create() + .id(`${actorId}/status/${params.activityId}`) + .actor(`${actorId}`) + .object( + as.article() + .id(`${actorId}/status/${result.id}`) + .content(result.content) + .to('https://www.w3.org/ns/activitystreams#Public') + .publishedNow() + .attributedTo(`${actorId}`) + ).prettyWrite((err, doc) => { if (err) { reject(err) } else { @@ -201,27 +204,27 @@ export const resolvers = { resolve(JSON.stringify(parsedDoc)) } }) - }) - session.close() - // try sending post via ActivityPub - await new Promise((resolve) => { - const url = new URL(actorId) - request(`${url.origin}/activitypub/inbox`, { - method: 'POST', - headers: { - 'Content-Type': 'application/activity+json' - }, - body: createActivity - }, (err) => { - if (err) { - debug(`error = ${JSON.stringify(err, null, 2)}`) - resolve(err) - } - resolve(null) }) - }) - return result + session.close() + // try sending post via ActivityPub + await new Promise((resolve) => { + const url = new URL(actorId) + request(`${url.origin}/activitypub/inbox`, { + method: 'POST', + headers: { + 'Content-Type': 'application/activity+json' + }, + body: createActivity + }, (err) => { + if (err) { + debug(`error = ${JSON.stringify(err, null, 2)}`) + resolve(err) + } + resolve(null) + }) + }) + return result + } */ } - } } diff --git a/test/features/activity-delete.feature b/test/features/activity-delete.feature index 0e0d13253..ad33f1e4c 100644 --- a/test/features/activity-delete.feature +++ b/test/features/activity-delete.feature @@ -19,7 +19,7 @@ Feature: Delete an object "published": "2019-02-07T19:37:55.002Z", "attributedTo": "https://aronda.org/users/bernd-das-brot", "content": "Hi Max, how are you?", - "to": "https://localhost:4100/activitypub/users/moritz" + "to": "https://www.w3.org/ns/activitystreams#Public" } } """ diff --git a/test/features/activity-like.feature b/test/features/activity-like.feature index c605bdb76..d71a0396f 100644 --- a/test/features/activity-like.feature +++ b/test/features/activity-like.feature @@ -4,21 +4,39 @@ Feature: Like an object like an article or note I want to undo the follow. Background: - Given our own server runs at "http://localhost:4123" + Given our own server runs at "http://localhost:4100" And we have the following users in our database: | Slug | | karl-heinz | | peter-lustiger | + And I send a POST request with the following activity to "/activitypub/users/bernd-das-brot/inbox": + """ + { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://localhost:4100/activitypub/users/karl-heinz/status/faslkasa7dasfzkjn2398hsfd", + "type": "Create", + "actor": "https://localhost:4100/activitypub/users/karl-heinz", + "object": { + "id": "https://localhost:4100/activitypub/users/karl-heinz/status/dkasfljsdfaafg9843jknsdf", + "type": "Article", + "published": "2019-02-07T19:37:55.002Z", + "attributedTo": "https://localhost:4100/activitypub/users/karl-heinz", + "content": "Hi Max, how are you?", + "to": "https://www.w3.org/ns/activitystreams#Public" + } + } + """ Scenario: Send a like of a person to an users inbox and make sure it's added to the likes collection When I send a POST request with the following activity to "/activitypub/users/karl-heinz/inbox": """ { "@context": "https://www.w3.org/ns/activitystreams", - "id": "https://localhost:4123/activitypub/users/peter-lustiger/status/83J23549sda1k72fsa4567na42312455kad83", + "id": "https://localhost:4100/activitypub/users/peter-lustiger/status/83J23549sda1k72fsa4567na42312455kad83", "type": "Like", - "actor": "http://localhost:4123/activitypub/users/peter-lustiger - "object": "http://localhost:4123/activitypub/users/karl-heinz" + "actor": "http://localhost:4100/activitypub/users/peter-lustiger", + "object": "http://localhost:4100/activitypub/users/karl-heinz/status/dkasfljsdfaafg9843jknsdf" } """ Then I expect the status code to be 200 + And the post with id "dkasfljsdfaafg9843jknsdf" has been liked by "peter-lustiger" diff --git a/test/features/support/steps.js b/test/features/support/steps.js index 7f7bde455..f2aaf6ffd 100644 --- a/test/features/support/steps.js +++ b/test/features/support/steps.js @@ -124,3 +124,17 @@ Then('the object is removed from the outbox collection of {string}', async funct Then('I send a GET request to {string} and expect a ordered collection', () => { }) + +Then('the post with id {string} has been liked by {string}', async function (id, slug) { + const result = await client.request(` + query { + Post(id: "${id}") { + shoutedBy { + slug + } + } + } + `) + expect(result.data.Post[0].shoutedBy).to.be.an('array').that.is.not.empty // eslint-disable-line + expect(result.data.Post[0].shoutedBy[0].slug).to.equal(slug) +})