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'), Post: require('./Post.js'),
Comment: require('./Comment.js'), Comment: require('./Comment.js'),
Category: require('./Category.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 let { author, authorId } = args
delete args.author delete args.author
delete args.authorId delete args.authorId
if (author && authorId) throw new Error('You provided both author and authorId') if (author && authorId) throw new Error('You provided both author and authorId')
if (authorId) author = await neodeInstance.find('User', authorId) if (authorId) author = await neodeInstance.find('User', authorId)
author = author || (await factoryInstance.create('User', args)) author = author || (await factoryInstance.create('User'))
const post = await neodeInstance.create('Post', args) const post = await neodeInstance.create('Post', args)
await post.relateTo(author, 'author') await post.relateTo(author, 'author')
await Promise.all(categories.map(c => c.relateTo(post, 'post'))) await Promise.all(categories.map(c => c.relateTo(post, 'post')))
await Promise.all(tags.map(t => t.relateTo(post, 'post')))
return post return post
}, },
} }

View File

@ -1,16 +1,12 @@
import uuid from 'uuid/v4' export default function create() {
export default function(params) {
const { id = uuid(), name = '#human-connection' } = params
return { return {
mutation: ` factory: async ({ args, neodeInstance }) => {
mutation($id: ID!) { const defaults = { name: '#human-connection' }
CreateTag(id: $id) { args = {
id ...defaults,
} ...args,
} }
`, return neodeInstance.create('Tag', args)
variables: { id, name }, },
} }
} }

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", () => { Given("we have a selection of tags and categories as well as posts", () => {
cy.createCategories("cat12") cy.createCategories("cat12")
.factory() .factory()
.authenticateAs(loginCredentials)
.create("Tag", { id: "Ecology" }) .create("Tag", { id: "Ecology" })
.create("Tag", { id: "Nature" }) .create("Tag", { id: "Nature" })
.create("Tag", { id: "Democracy" }); .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() cy.factory()
.create("User", someAuthor) .create("User", { id: 'a1' })
.authenticateAs(someAuthor) .create("Post", {authorId: 'a1', tagIds: [ "Ecology", "Nature", "Democracy" ], categoryIds: ["cat12"] })
.create("Post", { id: "p0", categoryIds: ["cat12"] }) .create("Post", {authorId: 'a1', tagIds: [ "Nature", "Democracy" ], categoryIds: ["cat121"] });
.create("Post", { id: "p1", categoryIds: ["cat121"] });
cy.factory() cy.factory()
.create("User", yetAnotherAuthor) .create("User", { id: 'a2'})
.authenticateAs(yetAnotherAuthor) .create("Post", { authorId: 'a2', tagIds: ['Nature', 'Democracy'], categoryIds: ["cat12"] });
.create("Post", { id: "p2", categoryIds: ["cat12"] });
cy.factory() cy.factory()
.authenticateAs(loginCredentials) .create("Post", { authorId: narratorParams.id, tagIds: ['Democracy'], categoryIds: ["cat122"] })
.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" });
}); });
Given("we have the following user accounts:", table => { 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 => { Given('"Spammy Spammer" wrote a post {string}', title => {
cy.createCategories("cat21") cy.createCategories("cat21")
.factory() .factory()
.authenticateAs({ .create("Post", { authorId: 'annoying-user', title, categoryIds: ["cat21"] });
email: "spammy-spammer@example.org",
password: "1234"
})
.create("Post", { title, categoryIds: ["cat21"] });
}); });
Then("the list of posts of this user is empty", () => { 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 => { Given("I wrote a post {string}", title => {
cy.createCategories(`cat213`, title) cy.createCategories(`cat213`, title)
.factory() .factory()
.authenticateAs(loginCredentials) .create("Post", { authorId: narratorParams.id, title, categoryIds: ["cat213"] });
.create("Post", { title, categoryIds: ["cat213"] });
}); });
When("I block the user {string}", name => { When("I block the user {string}", name => {

View File

@ -7,7 +7,6 @@ Feature: Block a User
Given I have a user account Given I have a user account
And there is an annoying user called "Spammy Spammer" And there is an annoying user called "Spammy Spammer"
And I am logged in And I am logged in
And we have a selection of categories
Scenario: Block a user Scenario: Block a user
Given I am on the profile page of the annoying user Given I am on the profile page of the annoying user