Fix cypress test, unique category ids/slugs

This commit is contained in:
Matt Rider 2019-08-21 10:50:56 +02:00
parent e8871f51d4
commit c2d6723837
2 changed files with 16 additions and 18 deletions

View File

@ -22,11 +22,11 @@ Given("I am logged in", () => {
}); });
Given("we have a selection of categories", () => { Given("we have a selection of categories", () => {
cy.createCategories(); cy.createCategories("cat0", "just-for-fun");
}); });
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() cy.createCategories("cat12")
.factory() .factory()
.authenticateAs(loginCredentials) .authenticateAs(loginCredentials)
.create("Tag", { id: "Ecology" }) .create("Tag", { id: "Ecology" })
@ -45,15 +45,15 @@ Given("we have a selection of tags and categories as well as posts", () => {
cy.factory() cy.factory()
.create("User", someAuthor) .create("User", someAuthor)
.authenticateAs(someAuthor) .authenticateAs(someAuthor)
.create("Post", { id: "p0", categoryIds: ["cat1"] }) .create("Post", { id: "p0", categoryIds: ["cat12"] })
.create("Post", { id: "p1", categoryIds: ["cat2"] }); .create("Post", { id: "p1", categoryIds: ["cat121"] });
cy.factory() cy.factory()
.create("User", yetAnotherAuthor) .create("User", yetAnotherAuthor)
.authenticateAs(yetAnotherAuthor) .authenticateAs(yetAnotherAuthor)
.create("Post", { id: "p2", categoryIds: ["cat1"] }); .create("Post", { id: "p2", categoryIds: ["cat12"] });
cy.factory() cy.factory()
.authenticateAs(loginCredentials) .authenticateAs(loginCredentials)
.create("Post", { id: "p3", categoryIds: ["cat3"] }) .create("Post", { id: "p3", categoryIds: ["cat122"] })
.relate("Post", "Tags", { from: "p0", to: "Ecology" }) .relate("Post", "Tags", { from: "p0", to: "Ecology" })
.relate("Post", "Tags", { from: "p0", to: "Nature" }) .relate("Post", "Tags", { from: "p0", to: "Nature" })
.relate("Post", "Tags", { from: "p0", to: "Democracy" }) .relate("Post", "Tags", { from: "p0", to: "Democracy" })
@ -209,7 +209,7 @@ When(
Given("I previously created a post", () => { Given("I previously created a post", () => {
lastPost.title = "previously created post"; lastPost.title = "previously created post";
lastPost.content = "with some content"; lastPost.content = "with some content";
lastPost.categoryIds = "cat1"; lastPost.categoryIds = "cat0";
cy.factory() cy.factory()
.authenticateAs(loginCredentials) .authenticateAs(loginCredentials)
.create("Post", lastPost); .create("Post", lastPost);
@ -417,13 +417,13 @@ 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() cy.createCategories("cat21")
.factory() .factory()
.authenticateAs({ .authenticateAs({
email: "spammy-spammer@example.org", email: "spammy-spammer@example.org",
password: "1234" password: "1234"
}) })
.create("Post", { title, categoryIds: ["cat2"] }); .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", () => {
@ -440,10 +440,10 @@ Then("nobody is following the user profile anymore", () => {
}); });
Given("I wrote a post {string}", title => { Given("I wrote a post {string}", title => {
cy.createCategories() cy.createCategories(`cat213`, title)
.factory() .factory()
.authenticateAs(loginCredentials) .authenticateAs(loginCredentials)
.create("Post", { title, categoryIds: ["cat2"] }); .create("Post", { title, categoryIds: ["cat213"] });
}); });
When("I block the user {string}", name => { When("I block the user {string}", name => {

View File

@ -62,24 +62,22 @@ Cypress.Commands.add("openPage", page => {
cy.visit(`/${page}`); cy.visit(`/${page}`);
}); });
Cypress.Commands.add("createCategories", () => { Cypress.Commands.add("createCategories", (id, slug) => {
cy.neode() cy.neode()
.create("Category", { .create("Category", {
id: "cat1", id: `${id}`,
name: "Just For Fun", name: "Just For Fun",
slug: "just-for-fun", slug: `${slug}`,
icon: "smile" icon: "smile"
}) })
.create("Category", { .create("Category", {
id: "cat2", id: `${id}1`,
name: "Happiness & Values", name: "Happiness & Values",
slug: "happiness-values",
icon: "heart-o" icon: "heart-o"
}) })
.create("Category", { .create("Category", {
id: "cat3", id: `${id}2`,
name: "Health & Wellbeing", name: "Health & Wellbeing",
slug: "health-wellbeing",
icon: "medkit" icon: "medkit"
}); });
}); });