diff --git a/backend/src/models/Tag.js b/backend/src/models/Tag.js new file mode 100644 index 000000000..90b5f8772 --- /dev/null +++ b/backend/src/models/Tag.js @@ -0,0 +1,17 @@ +module.exports = { + id: { type: 'string', primary: true }, + deleted: { type: 'boolean', default: false }, + disabled: { type: 'boolean', default: false }, + updatedAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString(), + }, + post: { + type: 'relationship', + relationship: 'TAGGED', + target: 'Post', + direction: 'in', + }, +} diff --git a/backend/src/models/index.js b/backend/src/models/index.js index 4f0b40cee..a5323678b 100644 --- a/backend/src/models/index.js +++ b/backend/src/models/index.js @@ -9,4 +9,5 @@ export default { Post: require('./Post.js'), Comment: require('./Comment.js'), Category: require('./Category.js'), + Tag: require('./Tag.js'), } diff --git a/backend/src/seed/factories/posts.js b/backend/src/seed/factories/posts.js index 334a95489..cb3c163d8 100644 --- a/backend/src/seed/factories/posts.js +++ b/backend/src/seed/factories/posts.js @@ -35,16 +35,25 @@ export default function create() { }), ) + const { tagIds = [] } = args + delete args.tags + const tags = await Promise.all( + tagIds.map(t => { + return neodeInstance.find('Tag', t) + }), + ) + let { author, authorId } = args delete args.author delete args.authorId if (author && authorId) throw new Error('You provided both author and authorId') - if (authorId) author = await neodeInstance.find('User', authorId) - author = author || (await factoryInstance.create('User', args)) + if (authorId) author = await neodeInstance.find('User', authorId) + author = author || (await factoryInstance.create('User')) const post = await neodeInstance.create('Post', args) await post.relateTo(author, 'author') await Promise.all(categories.map(c => c.relateTo(post, 'post'))) + await Promise.all(tags.map(t => t.relateTo(post, 'post'))) return post }, } diff --git a/backend/src/seed/factories/tags.js b/backend/src/seed/factories/tags.js index 4a135e051..9005d1406 100644 --- a/backend/src/seed/factories/tags.js +++ b/backend/src/seed/factories/tags.js @@ -1,16 +1,12 @@ -import uuid from 'uuid/v4' - -export default function(params) { - const { id = uuid(), name = '#human-connection' } = params - +export default function create() { return { - mutation: ` - mutation($id: ID!) { - CreateTag(id: $id) { - id - } + factory: async ({ args, neodeInstance }) => { + const defaults = { name: '#human-connection' } + args = { + ...defaults, + ...args, } - `, - variables: { id, name }, + return neodeInstance.create('Tag', args) + }, } } diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 558feed69..f7ab18707 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -28,40 +28,20 @@ Given("we have a selection of categories", () => { Given("we have a selection of tags and categories as well as posts", () => { cy.createCategories("cat12") .factory() - .authenticateAs(loginCredentials) .create("Tag", { id: "Ecology" }) .create("Tag", { id: "Nature" }) .create("Tag", { id: "Democracy" }); - const someAuthor = { - id: "authorId", - email: "author@example.org", - password: "1234" - }; - const yetAnotherAuthor = { - id: "yetAnotherAuthor", - email: "yet-another-author@example.org", - password: "1234" - }; + cy.factory() - .create("User", someAuthor) - .authenticateAs(someAuthor) - .create("Post", { id: "p0", categoryIds: ["cat12"] }) - .create("Post", { id: "p1", categoryIds: ["cat121"] }); + .create("User", { id: 'a1' }) + .create("Post", {authorId: 'a1', tagIds: [ "Ecology", "Nature", "Democracy" ], categoryIds: ["cat12"] }) + .create("Post", {authorId: 'a1', tagIds: [ "Nature", "Democracy" ], categoryIds: ["cat121"] }); + cy.factory() - .create("User", yetAnotherAuthor) - .authenticateAs(yetAnotherAuthor) - .create("Post", { id: "p2", categoryIds: ["cat12"] }); + .create("User", { id: 'a2'}) + .create("Post", { authorId: 'a2', tagIds: ['Nature', 'Democracy'], categoryIds: ["cat12"] }); cy.factory() - .authenticateAs(loginCredentials) - .create("Post", { id: "p3", categoryIds: ["cat122"] }) - .relate("Post", "Tags", { from: "p0", to: "Ecology" }) - .relate("Post", "Tags", { from: "p0", to: "Nature" }) - .relate("Post", "Tags", { from: "p0", to: "Democracy" }) - .relate("Post", "Tags", { from: "p1", to: "Nature" }) - .relate("Post", "Tags", { from: "p1", to: "Democracy" }) - .relate("Post", "Tags", { from: "p2", to: "Nature" }) - .relate("Post", "Tags", { from: "p2", to: "Democracy" }) - .relate("Post", "Tags", { from: "p3", to: "Democracy" }); + .create("Post", { authorId: narratorParams.id, tagIds: ['Democracy'], categoryIds: ["cat122"] }) }); Given("we have the following user accounts:", table => { @@ -410,11 +390,7 @@ Given("I follow the user {string}", name => { Given('"Spammy Spammer" wrote a post {string}', title => { cy.createCategories("cat21") .factory() - .authenticateAs({ - email: "spammy-spammer@example.org", - password: "1234" - }) - .create("Post", { title, categoryIds: ["cat21"] }); + .create("Post", { authorId: 'annoying-user', title, categoryIds: ["cat21"] }); }); Then("the list of posts of this user is empty", () => { @@ -433,8 +409,7 @@ Then("nobody is following the user profile anymore", () => { Given("I wrote a post {string}", title => { cy.createCategories(`cat213`, title) .factory() - .authenticateAs(loginCredentials) - .create("Post", { title, categoryIds: ["cat213"] }); + .create("Post", { authorId: narratorParams.id, title, categoryIds: ["cat213"] }); }); When("I block the user {string}", name => { diff --git a/cypress/integration/user_profile/blocked-users/Blocking.feature b/cypress/integration/user_profile/blocked-users/Blocking.feature index 6ff81f4dc..9b27f82a3 100644 --- a/cypress/integration/user_profile/blocked-users/Blocking.feature +++ b/cypress/integration/user_profile/blocked-users/Blocking.feature @@ -7,7 +7,6 @@ Feature: Block a User Given I have a user account And there is an annoying user called "Spammy Spammer" And I am logged in - And we have a selection of categories Scenario: Block a user Given I am on the profile page of the annoying user