Fix cypress tests and factories

This commit is contained in:
roschaefer 2019-09-02 16:03:15 +02:00
parent 76acebbb73
commit 4d5769fbc6
6 changed files with 43 additions and 43 deletions

View File

@ -79,6 +79,7 @@ export default function Factory(options = {}) {
this.lastResponse = await factory({
args,
neodeInstance,
factoryInstance: this,
})
return this.lastResponse
} else {

View File

@ -4,10 +4,9 @@ import uuid from 'uuid/v4'
export default function create() {
return {
factory: async ({ args, neodeInstance }) => {
factory: async ({ args, neodeInstance, factoryInstance }) => {
const defaults = {
id: uuid(),
slug: '',
title: faker.lorem.sentence(),
content: [
faker.lorem.sentence(),
@ -21,11 +20,13 @@ export default function create() {
deleted: false,
categoryIds: [],
}
defaults.slug = slugify(defaults.title, { lower: true })
args = {
...defaults,
...args,
}
args.slug = args.slug || slugify(args.title, { lower: true })
args.contentExcerpt = args.contentExcerpt || args.content
const { categoryIds } = args
if (!categoryIds.length) throw new Error('CategoryIds are empty!')
const categories = await Promise.all(
@ -33,8 +34,14 @@ export default function create() {
return neodeInstance.find('Category', c)
}),
)
const author = args.author || (await neodeInstance.create('User', args))
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))
const post = await neodeInstance.create('Post', args)
await post.relateTo(author, 'author')
await Promise.all(categories.map(c => c.relateTo(post, 'post')))

View File

@ -1,6 +1,5 @@
import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";
import helpers from "../../support/helpers";
import slugify from "slug";
/* global cy */
@ -11,6 +10,7 @@ let loginCredentials = {
password: "1234"
};
const narratorParams = {
id: 'id-of-peter-pan',
name: "Peter Pan",
slug: "peter-pan",
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/nerrsoft/128.jpg",
@ -158,40 +158,28 @@ When("I press {string}", label => {
cy.contains(label).click();
});
Given("we have this user in our database:", table => {
const [firstRow] = table.hashes()
cy.factory().create('User', firstRow)
})
Given("we have the following posts in our database:", table => {
table.hashes().forEach(({ Author, ...postAttributes }, i) => {
Author = Author || `author-${i}`;
const userAttributes = {
name: Author,
email: `${slugify(Author, { lower: true })}@example.org`,
password: "1234"
};
postAttributes.deleted = Boolean(postAttributes.deleted);
const disabled = Boolean(postAttributes.disabled);
postAttributes.categoryIds = [`cat${i}${new Date()}`];
postAttributes;
cy.factory()
.create("User", userAttributes)
.authenticateAs(userAttributes)
.create("Category", {
id: `cat${i}${new Date()}`,
cy.factory().create('Category', {
id: `cat-456`,
name: "Just For Fun",
slug: `just-for-fun-${i}`,
slug: `just-for-fun`,
icon: "smile"
})
.create("Post", postAttributes);
if (disabled) {
const moderatorParams = {
email: "moderator@example.org",
role: "moderator",
password: "1234"
};
cy.factory()
.create("User", moderatorParams)
.authenticateAs(moderatorParams)
.mutate("mutation($id: ID!) { disable(id: $id) }", postAttributes);
table.hashes().forEach(({ ...postAttributes }, i) => {
postAttributes = {
...postAttributes,
deleted: Boolean(postAttributes.deleted),
disabled: Boolean(postAttributes.disabled),
categoryIds: ['cat-456']
}
});
cy.factory().create("Post", postAttributes);
})
});
Then("I see a success message:", message => {
@ -210,11 +198,11 @@ When(
);
Given("I previously created a post", () => {
lastPost.authorId = narratorParams.id
lastPost.title = "previously created post";
lastPost.content = "with some content";
lastPost.categoryIds = "cat0";
lastPost.categoryIds = ["cat0"];
cy.factory()
.authenticateAs(loginCredentials)
.create("Post", lastPost);
});

View File

@ -8,9 +8,12 @@ Feature: Report and Moderate
So I can look into it and decide what to do
Background:
Given we have this user in our database:
| id | name |
| u67 | David Irving|
Given we have the following posts in our database:
| Author | id | title | content |
| David Irving | p1 | The Truth about the Holocaust | It never existed! |
| authorId | id | title | content |
| u67 | p1 | The Truth about the Holocaust | It never existed! |
Scenario Outline: Report a post from various pages

View File

@ -27,8 +27,8 @@ Feature: Block a User
Scenario: Posts of blocked users are filtered from search results
Given we have the following posts in our database:
| Author | id | title | content |
| Some unblocked user | im-not-blocked | Post that should be seen | cause I'm not blocked |
| id | title | content |
| im-not-blocked | Post that should be seen | cause I'm not blocked |
Given "Spammy Spammer" wrote a post "Spam Spam Spam"
When I search for "Spam"
Then I should see the following posts in the select dropdown:

View File

@ -54,6 +54,7 @@ services:
- SMTP_HOST=mailserver
- SMTP_PORT=25
- SMTP_IGNORE_TLS=true
- "DEBUG=${DEBUG}"
neo4j:
environment:
- NEO4J_AUTH=none