mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Fix cypress tests and factories
This commit is contained in:
parent
76acebbb73
commit
4d5769fbc6
@ -79,6 +79,7 @@ export default function Factory(options = {}) {
|
|||||||
this.lastResponse = await factory({
|
this.lastResponse = await factory({
|
||||||
args,
|
args,
|
||||||
neodeInstance,
|
neodeInstance,
|
||||||
|
factoryInstance: this,
|
||||||
})
|
})
|
||||||
return this.lastResponse
|
return this.lastResponse
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -4,10 +4,9 @@ import uuid from 'uuid/v4'
|
|||||||
|
|
||||||
export default function create() {
|
export default function create() {
|
||||||
return {
|
return {
|
||||||
factory: async ({ args, neodeInstance }) => {
|
factory: async ({ args, neodeInstance, factoryInstance }) => {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
id: uuid(),
|
id: uuid(),
|
||||||
slug: '',
|
|
||||||
title: faker.lorem.sentence(),
|
title: faker.lorem.sentence(),
|
||||||
content: [
|
content: [
|
||||||
faker.lorem.sentence(),
|
faker.lorem.sentence(),
|
||||||
@ -21,11 +20,13 @@ export default function create() {
|
|||||||
deleted: false,
|
deleted: false,
|
||||||
categoryIds: [],
|
categoryIds: [],
|
||||||
}
|
}
|
||||||
defaults.slug = slugify(defaults.title, { lower: true })
|
|
||||||
args = {
|
args = {
|
||||||
...defaults,
|
...defaults,
|
||||||
...args,
|
...args,
|
||||||
}
|
}
|
||||||
|
args.slug = args.slug || slugify(args.title, { lower: true })
|
||||||
|
args.contentExcerpt = args.contentExcerpt || args.content
|
||||||
|
|
||||||
const { categoryIds } = args
|
const { categoryIds } = args
|
||||||
if (!categoryIds.length) throw new Error('CategoryIds are empty!')
|
if (!categoryIds.length) throw new Error('CategoryIds are empty!')
|
||||||
const categories = await Promise.all(
|
const categories = await Promise.all(
|
||||||
@ -33,8 +34,14 @@ export default function create() {
|
|||||||
return neodeInstance.find('Category', c)
|
return neodeInstance.find('Category', c)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const author = args.author || (await neodeInstance.create('User', args))
|
|
||||||
|
let { author, authorId } = args
|
||||||
delete args.author
|
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)
|
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')))
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";
|
import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";
|
||||||
import helpers from "../../support/helpers";
|
import helpers from "../../support/helpers";
|
||||||
import slugify from "slug";
|
|
||||||
|
|
||||||
/* global cy */
|
/* global cy */
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ let loginCredentials = {
|
|||||||
password: "1234"
|
password: "1234"
|
||||||
};
|
};
|
||||||
const narratorParams = {
|
const narratorParams = {
|
||||||
|
id: 'id-of-peter-pan',
|
||||||
name: "Peter Pan",
|
name: "Peter Pan",
|
||||||
slug: "peter-pan",
|
slug: "peter-pan",
|
||||||
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/nerrsoft/128.jpg",
|
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/nerrsoft/128.jpg",
|
||||||
@ -158,40 +158,28 @@ When("I press {string}", label => {
|
|||||||
cy.contains(label).click();
|
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 => {
|
Given("we have the following posts in our database:", table => {
|
||||||
table.hashes().forEach(({ Author, ...postAttributes }, i) => {
|
cy.factory().create('Category', {
|
||||||
Author = Author || `author-${i}`;
|
id: `cat-456`,
|
||||||
const userAttributes = {
|
name: "Just For Fun",
|
||||||
name: Author,
|
slug: `just-for-fun`,
|
||||||
email: `${slugify(Author, { lower: true })}@example.org`,
|
icon: "smile"
|
||||||
password: "1234"
|
})
|
||||||
};
|
|
||||||
postAttributes.deleted = Boolean(postAttributes.deleted);
|
table.hashes().forEach(({ ...postAttributes }, i) => {
|
||||||
const disabled = Boolean(postAttributes.disabled);
|
postAttributes = {
|
||||||
postAttributes.categoryIds = [`cat${i}${new Date()}`];
|
...postAttributes,
|
||||||
postAttributes;
|
deleted: Boolean(postAttributes.deleted),
|
||||||
cy.factory()
|
disabled: Boolean(postAttributes.disabled),
|
||||||
.create("User", userAttributes)
|
categoryIds: ['cat-456']
|
||||||
.authenticateAs(userAttributes)
|
|
||||||
.create("Category", {
|
|
||||||
id: `cat${i}${new Date()}`,
|
|
||||||
name: "Just For Fun",
|
|
||||||
slug: `just-for-fun-${i}`,
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
cy.factory().create("Post", postAttributes);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
Then("I see a success message:", message => {
|
Then("I see a success message:", message => {
|
||||||
@ -210,11 +198,11 @@ When(
|
|||||||
);
|
);
|
||||||
|
|
||||||
Given("I previously created a post", () => {
|
Given("I previously created a post", () => {
|
||||||
|
lastPost.authorId = narratorParams.id
|
||||||
lastPost.title = "previously created post";
|
lastPost.title = "previously created post";
|
||||||
lastPost.content = "with some content";
|
lastPost.content = "with some content";
|
||||||
lastPost.categoryIds = "cat0";
|
lastPost.categoryIds = ["cat0"];
|
||||||
cy.factory()
|
cy.factory()
|
||||||
.authenticateAs(loginCredentials)
|
|
||||||
.create("Post", lastPost);
|
.create("Post", lastPost);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,12 @@ Feature: Report and Moderate
|
|||||||
So I can look into it and decide what to do
|
So I can look into it and decide what to do
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
|
Given we have this user in our database:
|
||||||
|
| id | name |
|
||||||
|
| u67 | David Irving|
|
||||||
Given we have the following posts in our database:
|
Given we have the following posts in our database:
|
||||||
| Author | id | title | content |
|
| authorId | id | title | content |
|
||||||
| David Irving | p1 | The Truth about the Holocaust | It never existed! |
|
| u67 | p1 | The Truth about the Holocaust | It never existed! |
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: Report a post from various pages
|
Scenario Outline: Report a post from various pages
|
||||||
|
|||||||
@ -27,8 +27,8 @@ Feature: Block a User
|
|||||||
|
|
||||||
Scenario: Posts of blocked users are filtered from search results
|
Scenario: Posts of blocked users are filtered from search results
|
||||||
Given we have the following posts in our database:
|
Given we have the following posts in our database:
|
||||||
| Author | id | title | content |
|
| id | title | content |
|
||||||
| Some unblocked user | im-not-blocked | Post that should be seen | cause I'm not blocked |
|
| im-not-blocked | Post that should be seen | cause I'm not blocked |
|
||||||
Given "Spammy Spammer" wrote a post "Spam Spam Spam"
|
Given "Spammy Spammer" wrote a post "Spam Spam Spam"
|
||||||
When I search for "Spam"
|
When I search for "Spam"
|
||||||
Then I should see the following posts in the select dropdown:
|
Then I should see the following posts in the select dropdown:
|
||||||
|
|||||||
@ -54,6 +54,7 @@ services:
|
|||||||
- SMTP_HOST=mailserver
|
- SMTP_HOST=mailserver
|
||||||
- SMTP_PORT=25
|
- SMTP_PORT=25
|
||||||
- SMTP_IGNORE_TLS=true
|
- SMTP_IGNORE_TLS=true
|
||||||
|
- "DEBUG=${DEBUG}"
|
||||||
neo4j:
|
neo4j:
|
||||||
environment:
|
environment:
|
||||||
- NEO4J_AUTH=none
|
- NEO4J_AUTH=none
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user