99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
describe("admin actions", function () {
|
|
beforeEach(function () {
|
|
cy.resetDb();
|
|
cy.clearMail();
|
|
cy.seedAdmin({
|
|
email: "admin@example.com",
|
|
displayName: "rootadmin",
|
|
password: "longenoughpassword",
|
|
});
|
|
cy.seedConfirmedUser({
|
|
email: "alice@example.com",
|
|
displayName: "alice",
|
|
password: "longenoughpassword",
|
|
});
|
|
cy.seedConfirmedUser({
|
|
email: "bob@example.com",
|
|
displayName: "bob",
|
|
password: "longenoughpassword",
|
|
});
|
|
cy.seedPostAs({
|
|
email: "alice@example.com",
|
|
password: "longenoughpassword",
|
|
title: "Alice post",
|
|
body: "Body.",
|
|
}).as("alicePost");
|
|
});
|
|
|
|
it("admin promotes another user via the profile page", function () {
|
|
cy.loginViaApi({
|
|
email: "admin@example.com",
|
|
password: "longenoughpassword",
|
|
});
|
|
|
|
cy.visit("/users/alice");
|
|
cy.contains("button", "Promote to admin").click();
|
|
|
|
cy.logoutViaApi();
|
|
cy.loginViaApi({
|
|
email: "alice@example.com",
|
|
password: "longenoughpassword",
|
|
});
|
|
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
|
cy.visit(`/posts/${post.id}`);
|
|
cy.contains("button", "Feature in slot 1").should("be.visible");
|
|
});
|
|
});
|
|
|
|
it("admin features a post and it shows up on the home page", function () {
|
|
cy.loginViaApi({
|
|
email: "admin@example.com",
|
|
password: "longenoughpassword",
|
|
});
|
|
|
|
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
|
cy.visit(`/posts/${post.id}`);
|
|
cy.contains("button", "Feature in slot 1").click();
|
|
cy.contains(".badge", "Featured (slot 1)").should("be.visible");
|
|
});
|
|
|
|
cy.logoutViaApi();
|
|
cy.visit("/");
|
|
cy.contains("h2", "Featured").should("be.visible");
|
|
cy.get(".featured .post-card").should("have.length", 1);
|
|
cy.contains(".featured .post-card", "Alice post").should("be.visible");
|
|
});
|
|
|
|
it("admin unfeaturing a post removes it from the home page", function () {
|
|
cy.loginViaApi({
|
|
email: "admin@example.com",
|
|
password: "longenoughpassword",
|
|
});
|
|
|
|
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
|
cy.visit(`/posts/${post.id}`);
|
|
cy.contains("button", "Feature in slot 1").click();
|
|
cy.contains(".badge", "Featured (slot 1)").should("be.visible");
|
|
cy.contains("button", "Unfeature").click();
|
|
cy.contains(".badge", "Featured").should("not.exist");
|
|
});
|
|
|
|
cy.logoutViaApi();
|
|
cy.visit("/");
|
|
cy.contains("h2", "Featured").should("not.exist");
|
|
});
|
|
|
|
it("a newly promoted admin can also feature posts", function () {
|
|
cy.promoteAdmin("bob@example.com");
|
|
cy.loginViaApi({
|
|
email: "bob@example.com",
|
|
password: "longenoughpassword",
|
|
});
|
|
|
|
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
|
cy.visit(`/posts/${post.id}`);
|
|
cy.contains("button", "Feature in slot 2").click();
|
|
cy.contains(".badge", "Featured (slot 2)").should("be.visible");
|
|
});
|
|
});
|
|
});
|