mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-01-17 10:21:25 +00:00
Create article before shouting in test and add "shouted" step + disable send Create Activity when creating a post
This commit is contained in:
parent
7ea4087775
commit
067371581d
@ -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
|
||||
} */
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user