mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Update cypress tests, post query
This commit is contained in:
parent
7bbbf40bcc
commit
8735045d11
@ -83,17 +83,14 @@ export default {
|
||||
|
||||
await session.run(cypherDeletePreviousRelations, { params })
|
||||
|
||||
let updatePostCypher = `MATCH (post:Post {id: $params.id})
|
||||
const updatePostCypher = `MATCH (post:Post {id: $params.id})
|
||||
SET post = $params
|
||||
`
|
||||
if (categoryIds && categoryIds.length) {
|
||||
updatePostCypher += `WITH post
|
||||
UNWIND $categoryIds AS categoryId
|
||||
MATCH (category:Category {id: categoryId})
|
||||
MERGE (post)-[:CATEGORIZED]->(category)
|
||||
`
|
||||
}
|
||||
updatePostCypher += `RETURN post`
|
||||
WITH post
|
||||
UNWIND $categoryIds AS categoryId
|
||||
MATCH (category:Category {id: categoryId})
|
||||
MERGE (post)-[:CATEGORIZED]->(category)
|
||||
RETURN post`
|
||||
|
||||
const updatePostVariables = { categoryIds, params }
|
||||
|
||||
const transactionRes = await session.run(updatePostCypher, updatePostVariables)
|
||||
@ -110,22 +107,18 @@ export default {
|
||||
const { categoryIds } = params
|
||||
delete params.categoryIds
|
||||
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
|
||||
|
||||
params.id = params.id || uuid()
|
||||
|
||||
let createPostCypher = `CREATE (post:Post {params})
|
||||
WITH post
|
||||
MATCH (author:User {id: $userId})
|
||||
MERGE (post)<-[:WROTE]-(author)
|
||||
`
|
||||
if (categoryIds) {
|
||||
createPostCypher += `WITH post
|
||||
const createPostCypher = `CREATE (post:Post {params})
|
||||
WITH post
|
||||
MATCH (author:User {id: $userId})
|
||||
MERGE (post)<-[:WROTE]-(author)
|
||||
WITH post
|
||||
UNWIND $categoryIds AS categoryId
|
||||
MATCH (category:Category {id: categoryId})
|
||||
MERGE (post)-[:CATEGORIZED]->(category)
|
||||
`
|
||||
}
|
||||
createPostCypher += `RETURN post`
|
||||
RETURN post`
|
||||
|
||||
const createPostVariables = { userId: context.user.id, categoryIds, params }
|
||||
|
||||
const session = context.driver.session()
|
||||
|
||||
@ -74,22 +74,22 @@ beforeEach(async () => {
|
||||
}
|
||||
await factory.create('User', userParams)
|
||||
await Promise.all([
|
||||
factory.create('Category', {
|
||||
instance.create('Category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
}),
|
||||
factory.create('Category', {
|
||||
instance.create('Category', {
|
||||
id: 'cat4',
|
||||
name: 'Environment & Nature',
|
||||
icon: 'tree',
|
||||
}),
|
||||
factory.create('Category', {
|
||||
instance.create('Category', {
|
||||
id: 'cat15',
|
||||
name: 'Consumption & Sustainability',
|
||||
icon: 'shopping-cart',
|
||||
}),
|
||||
factory.create('Category', {
|
||||
instance.create('Category', {
|
||||
id: 'cat27',
|
||||
name: 'Animal Protection',
|
||||
icon: 'paw',
|
||||
|
||||
@ -15,7 +15,9 @@ Feature: Tags and Categories
|
||||
|
||||
Background:
|
||||
Given my user account has the role "admin"
|
||||
And we have a selection of tags and categories as well as posts
|
||||
And we have a selection of categories
|
||||
And we have a selection of tags
|
||||
And we have a selection of posts
|
||||
And I am logged in
|
||||
|
||||
Scenario: See an overview of categories
|
||||
@ -24,8 +26,8 @@ Feature: Tags and Categories
|
||||
Then I can see the following table:
|
||||
| | Name | Posts |
|
||||
| | Just For Fun | 2 |
|
||||
| | Happyness & Values | 1 |
|
||||
| | Health & Wellbeing | 0 |
|
||||
| | Happiness & Values | 1 |
|
||||
| | Health & Wellbeing | 1 |
|
||||
|
||||
Scenario: See an overview of tags
|
||||
When I navigate to the administration dashboard
|
||||
|
||||
@ -20,20 +20,19 @@ const narratorParams = {
|
||||
Given("I am logged in", () => {
|
||||
cy.login(loginCredentials);
|
||||
});
|
||||
|
||||
Given("we have a selection of tags and categories as well as posts", () => {
|
||||
Given("we have a selection of categories", () => {
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Category", {
|
||||
id: "cat1",
|
||||
name: "Just For Fun",
|
||||
slug: "justforfun",
|
||||
slug: "just-for-fun",
|
||||
icon: "smile"
|
||||
})
|
||||
.create("Category", {
|
||||
id: "cat2",
|
||||
name: "Happyness & Values",
|
||||
slug: "happyness-values",
|
||||
name: "Happiness & Values",
|
||||
slug: "happiness-values",
|
||||
icon: "heart-o"
|
||||
})
|
||||
.create("Category", {
|
||||
@ -41,11 +40,18 @@ Given("we have a selection of tags and categories as well as posts", () => {
|
||||
name: "Health & Wellbeing",
|
||||
slug: "health-wellbeing",
|
||||
icon: "medkit"
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Given("we have a selection of tags", () => {
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Tag", { id: "Ecology" })
|
||||
.create("Tag", { id: "Nature" })
|
||||
.create("Tag", { id: "Democracy" });
|
||||
});
|
||||
|
||||
Given("we have a selection of posts", () => {
|
||||
const someAuthor = {
|
||||
id: "authorId",
|
||||
email: "author@example.org",
|
||||
@ -59,18 +65,15 @@ Given("we have a selection of tags and categories as well as posts", () => {
|
||||
cy.factory()
|
||||
.create("User", someAuthor)
|
||||
.authenticateAs(someAuthor)
|
||||
.create("Post", { id: "p0" })
|
||||
.create("Post", { id: "p1" });
|
||||
.create("Post", { id: "p0", categoryIds: ["cat1"] })
|
||||
.create("Post", { id: "p1", categoryIds: ["cat2"] });
|
||||
cy.factory()
|
||||
.create("User", yetAnotherAuthor)
|
||||
.authenticateAs(yetAnotherAuthor)
|
||||
.create("Post", { id: "p2" });
|
||||
.create("Post", { id: "p2", categoryIds: ["cat1"] });
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Post", { id: "p3" })
|
||||
.relate("Post", "Categories", { from: "p0", to: "cat1" })
|
||||
.relate("Post", "Categories", { from: "p1", to: "cat2" })
|
||||
.relate("Post", "Categories", { from: "p2", to: "cat1" })
|
||||
.create("Post", { id: "p3", categoryIds: ["cat3"] })
|
||||
.relate("Post", "Tags", { from: "p0", to: "Ecology" })
|
||||
.relate("Post", "Tags", { from: "p0", to: "Nature" })
|
||||
.relate("Post", "Tags", { from: "p0", to: "Democracy" })
|
||||
@ -182,9 +185,17 @@ Given("we have the following posts in our database:", table => {
|
||||
};
|
||||
postAttributes.deleted = Boolean(postAttributes.deleted);
|
||||
const disabled = Boolean(postAttributes.disabled);
|
||||
postAttributes.categoryIds = [`cat${i}`];
|
||||
postAttributes;
|
||||
cy.factory()
|
||||
.create("User", userAttributes)
|
||||
.authenticateAs(userAttributes)
|
||||
.create("Category", {
|
||||
id: `cat${i}`,
|
||||
name: "Just For Fun",
|
||||
slug: `just-for-fun-${i}`,
|
||||
icon: "smile"
|
||||
})
|
||||
.create("Post", postAttributes);
|
||||
if (disabled) {
|
||||
const moderatorParams = {
|
||||
@ -218,6 +229,7 @@ When(
|
||||
Given("I previously created a post", () => {
|
||||
lastPost.title = "previously created post";
|
||||
lastPost.content = "with some content";
|
||||
lastPost.categoryIds = "cat1";
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Post", lastPost);
|
||||
@ -233,6 +245,12 @@ When("I type in the following text:", text => {
|
||||
cy.get(".editor .ProseMirror").type(lastPost.content);
|
||||
});
|
||||
|
||||
Then("I select a category", () => {
|
||||
cy.get("span")
|
||||
.contains("Just for Fun")
|
||||
.click();
|
||||
});
|
||||
|
||||
Then("the post shows up on the landing page at position {int}", index => {
|
||||
cy.openPage("landing");
|
||||
const selector = `.post-card:nth-child(${index}) > .ds-card-content`;
|
||||
@ -260,7 +278,9 @@ Then("the first post on the landing page has the title:", title => {
|
||||
Then(
|
||||
"the page {string} returns a 404 error with a message:",
|
||||
(route, message) => {
|
||||
cy.request({ url: route, failOnStatusCode: false }).its('status').should('eq', 404)
|
||||
cy.request({ url: route, failOnStatusCode: false })
|
||||
.its("status")
|
||||
.should("eq", 404);
|
||||
cy.visit(route, { failOnStatusCode: false });
|
||||
cy.get(".error").should("contain", message);
|
||||
}
|
||||
@ -422,7 +442,7 @@ Given('"Spammy Spammer" wrote a post {string}', title => {
|
||||
email: "spammy-spammer@example.org",
|
||||
password: "1234"
|
||||
})
|
||||
.create("Post", { title });
|
||||
.create("Post", { title, categoryIds: ["cat2"] });
|
||||
});
|
||||
|
||||
Then("the list of posts of this user is empty", () => {
|
||||
@ -441,7 +461,7 @@ Then("nobody is following the user profile anymore", () => {
|
||||
Given("I wrote a post {string}", title => {
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Post", { title });
|
||||
.create("Post", { title, categoryIds: ["cat2"] });
|
||||
});
|
||||
|
||||
When("I block the user {string}", name => {
|
||||
@ -466,3 +486,14 @@ Then("I see only one post with the title {string}", title => {
|
||||
.should("have.length", 1);
|
||||
cy.get(".main-container").contains(".post-link", title);
|
||||
});
|
||||
|
||||
And("some categories exist", () => {
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create("Category", {
|
||||
id: "cat1",
|
||||
name: "Just For Fun",
|
||||
slug: `just-for-fun`,
|
||||
icon: "smile"
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,20 +7,20 @@ Feature: Hide Posts
|
||||
Given we have the following posts in our database:
|
||||
| id | title | deleted | disabled |
|
||||
| p1 | This post should be visible | | |
|
||||
| p2 | This post is disabled | | x |
|
||||
| p3 | This post is deleted | x | |
|
||||
| p2 | This post is disabled | | x |
|
||||
| p3 | This post is deleted | x | |
|
||||
|
||||
Scenario: Disabled posts don't show up on the landing page
|
||||
Given I am logged in with a "user" role
|
||||
Then I should see only 1 post on the landing page
|
||||
And the first post on the landing page has the title:
|
||||
"""
|
||||
This post should be visible
|
||||
"""
|
||||
"""
|
||||
This post should be visible
|
||||
"""
|
||||
|
||||
Scenario: Visiting a disabled post's page should return 404
|
||||
Given I am logged in with a "user" role
|
||||
Then the page "/post/this-post-is-disabled" returns a 404 error with a message:
|
||||
"""
|
||||
This post could not be found
|
||||
"""
|
||||
"""
|
||||
This post could not be found
|
||||
"""
|
||||
|
||||
@ -6,6 +6,7 @@ Feature: Create a post
|
||||
Background:
|
||||
Given I have a user account
|
||||
And I am logged in
|
||||
And we have a selection of categories
|
||||
And I am on the "landing" page
|
||||
|
||||
Scenario: Create a post
|
||||
@ -16,6 +17,7 @@ Feature: Create a post
|
||||
Human Connection is a free and open-source social network
|
||||
for active citizenship.
|
||||
"""
|
||||
Then I select a category
|
||||
And I click on "Save"
|
||||
Then I get redirected to ".../my-first-post"
|
||||
And the post was saved successfully
|
||||
|
||||
@ -7,6 +7,7 @@ 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
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CategoryQuery from '~/graphql/CategoryQuery.js'
|
||||
import CategoryQuery from '~/graphql/CategoryQuery'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@ -87,8 +87,8 @@ export default {
|
||||
query() {
|
||||
return CategoryQuery()
|
||||
},
|
||||
result(result) {
|
||||
this.categories = result.data.Category
|
||||
result({ data: { Category } }) {
|
||||
this.categories = Category
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
<no-ssr>
|
||||
<hc-editor
|
||||
:users="users"
|
||||
:hashtags="hashtags"
|
||||
:value="form.content"
|
||||
:hashtags="hashtags"
|
||||
@input="updateEditorContent"
|
||||
/>
|
||||
<small class="smallTag">{{ form.contentLength }}/{{ contentMax }}</small>
|
||||
@ -177,8 +177,8 @@ export default {
|
||||
.then(({ data }) => {
|
||||
this.loading = false
|
||||
this.$toast.success(this.$t('contribution.success'))
|
||||
this.failedValidations = true
|
||||
const result = data[this.id ? 'UpdatePost' : 'CreatePost']
|
||||
this.failedValidations = false
|
||||
|
||||
this.$router.push({
|
||||
name: 'post-id-slug',
|
||||
@ -188,7 +188,7 @@ export default {
|
||||
.catch(err => {
|
||||
this.$toast.error(err.message)
|
||||
this.loading = false
|
||||
this.failedValidations = false
|
||||
this.failedValidations = true
|
||||
})
|
||||
},
|
||||
updateEditorContent(value) {
|
||||
@ -234,7 +234,7 @@ export default {
|
||||
User: {
|
||||
query() {
|
||||
return gql`
|
||||
{
|
||||
query {
|
||||
User(orderBy: slug_asc) {
|
||||
id
|
||||
slug
|
||||
@ -242,22 +242,22 @@ export default {
|
||||
}
|
||||
`
|
||||
},
|
||||
result(result) {
|
||||
this.users = result.data.User
|
||||
result({ data: { User } }) {
|
||||
this.users = User
|
||||
},
|
||||
},
|
||||
Tag: {
|
||||
query() {
|
||||
return gql`
|
||||
{
|
||||
query {
|
||||
Tag(orderBy: id_asc) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
result(result) {
|
||||
this.hashtags = result.data.Tag
|
||||
result({ data: { Tag } }) {
|
||||
this.hashtags = Tag
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export default () => {
|
||||
return gql(`{
|
||||
Category {
|
||||
id
|
||||
slug
|
||||
icon
|
||||
return gql`
|
||||
query {
|
||||
Category {
|
||||
id
|
||||
slug
|
||||
icon
|
||||
}
|
||||
}
|
||||
}`)
|
||||
`
|
||||
}
|
||||
|
||||
@ -3,16 +3,46 @@ import gql from 'graphql-tag'
|
||||
export default i18n => {
|
||||
const lang = i18n.locale().toUpperCase()
|
||||
return gql`
|
||||
query Post($slug: String!) {
|
||||
Post(slug: $slug) {
|
||||
query Post($id: ID!) {
|
||||
Post(id: $id) {
|
||||
id
|
||||
title
|
||||
content
|
||||
createdAt
|
||||
disabled
|
||||
deleted
|
||||
slug
|
||||
image
|
||||
author {
|
||||
id
|
||||
title
|
||||
slug
|
||||
name
|
||||
avatar
|
||||
disabled
|
||||
deleted
|
||||
shoutedCount
|
||||
contributionsCount
|
||||
commentedCount
|
||||
followedByCount
|
||||
followedByCurrentUser
|
||||
location {
|
||||
name: name${lang}
|
||||
}
|
||||
badges {
|
||||
id
|
||||
icon
|
||||
}
|
||||
}
|
||||
tags {
|
||||
id
|
||||
}
|
||||
comments(orderBy: createdAt_asc) {
|
||||
id
|
||||
contentExcerpt
|
||||
content
|
||||
createdAt
|
||||
disabled
|
||||
deleted
|
||||
slug
|
||||
image
|
||||
author {
|
||||
id
|
||||
slug
|
||||
@ -33,48 +63,18 @@ export default i18n => {
|
||||
icon
|
||||
}
|
||||
}
|
||||
tags {
|
||||
id
|
||||
}
|
||||
comments(orderBy: createdAt_asc) {
|
||||
id
|
||||
contentExcerpt
|
||||
content
|
||||
createdAt
|
||||
disabled
|
||||
deleted
|
||||
author {
|
||||
id
|
||||
slug
|
||||
name
|
||||
avatar
|
||||
disabled
|
||||
deleted
|
||||
shoutedCount
|
||||
contributionsCount
|
||||
commentedCount
|
||||
followedByCount
|
||||
followedByCurrentUser
|
||||
location {
|
||||
name: name${lang}
|
||||
}
|
||||
badges {
|
||||
id
|
||||
icon
|
||||
}
|
||||
}
|
||||
}
|
||||
categories {
|
||||
id
|
||||
name
|
||||
icon
|
||||
}
|
||||
shoutedCount
|
||||
shoutedByCurrentUser
|
||||
emotionsCount
|
||||
}
|
||||
categories {
|
||||
id
|
||||
name
|
||||
icon
|
||||
}
|
||||
shoutedCount
|
||||
shoutedByCurrentUser
|
||||
emotionsCount
|
||||
}
|
||||
`
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
export const filterPosts = i18n => {
|
||||
|
||||
@ -159,7 +159,7 @@ export default {
|
||||
},
|
||||
variables() {
|
||||
return {
|
||||
slug: this.$route.params.slug,
|
||||
id: this.$route.params.id,
|
||||
}
|
||||
},
|
||||
fetchPolicy: 'cache-and-network',
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import gql from 'graphql-tag'
|
||||
import HcContributionForm from '~/components/ContributionForm/ContributionForm'
|
||||
import PostQuery from '~/graphql/PostQuery'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -36,38 +36,11 @@ export default {
|
||||
apollo: {
|
||||
Post: {
|
||||
query() {
|
||||
return gql(`
|
||||
query($id: ID!) {
|
||||
Post(id: $id) {
|
||||
id
|
||||
title
|
||||
content
|
||||
createdAt
|
||||
disabled
|
||||
deleted
|
||||
slug
|
||||
image
|
||||
language
|
||||
author {
|
||||
id
|
||||
disabled
|
||||
deleted
|
||||
}
|
||||
tags {
|
||||
name
|
||||
}
|
||||
categories {
|
||||
id
|
||||
name
|
||||
icon
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
return PostQuery(this.$i18n)
|
||||
},
|
||||
variables() {
|
||||
return {
|
||||
id: this.$route.params.id || 'p1',
|
||||
id: this.$route.params.id,
|
||||
}
|
||||
},
|
||||
fetchPolicy: 'cache-and-network',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user