Fix one more cypress test, implement a factory

This commit is contained in:
roschaefer 2019-09-02 16:56:56 +02:00
parent 4d5769fbc6
commit 784e1fd911
6 changed files with 47 additions and 50 deletions

17
backend/src/models/Tag.js Normal file
View File

@ -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',
},
}

View File

@ -9,4 +9,5 @@ export default {
Post: require('./Post.js'),
Comment: require('./Comment.js'),
Category: require('./Category.js'),
Tag: require('./Tag.js'),
}

View File

@ -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
},
}

View File

@ -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)
},
}
}

View File

@ -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 => {

View File

@ -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