Skip to content

Ban · E2E tests

0 modules · 0 exports · 0 repositories · 2 e2e tests · 1 route

  • SSendou
  • NN-ZAP
  • Arrange data setup
  • Act what the user does
  • Assert what is expected

User banning

banned user is redirected to suspended page and cannot access site

SendouN-ZAPban.spec.ts:10

Renders//admin/suspended

SSendou
Admin ban page
Act
  1. Open the admin ban page
    await adminBan.goto();
  2. Ban user “N-ZAP”, reason “Test ban reason”
    await adminBan.banUser("N-ZAP", { reason: "Test ban reason" });
NN-ZAP
Act
  1. Go to “/”
    await navigate({ page, url: "/" });
Assert
  1. the page URL is SUSPENDED_PAGE
    await expect(page).toHaveURL(SUSPENDED_PAGE);
Suspended page
Assert
  1. heading is visible
    await expect(suspended.locators.heading).toBeVisible();
  2. reason “Test ban reason” is visible
    await expect(suspended.reason("Test ban reason")).toBeVisible();
  3. no end time is visible
    await expect(suspended.locators.noEndTime).toBeVisible();
Act
  1. Go to “/builds”
    await navigate({ page, url: "/builds" });
Assert
  1. the page URL is SUSPENDED_PAGE
    await expect(page).toHaveURL(SUSPENDED_PAGE);
Act
  1. Go to “/calendar”
    await navigate({ page, url: "/calendar" });
Assert
  1. the page URL is SUSPENDED_PAGE
    await expect(page).toHaveURL(SUSPENDED_PAGE);
SSendou
Admin ban page
Act
  1. Open the admin ban page
    await adminBan.goto();
  2. Unban user “N-ZAP”
    await adminBan.unbanUser("N-ZAP");
NN-ZAP
Act
  1. Go to “/”
    await navigate({ page, url: "/" });
Assert
  1. the page URL is not SUSPENDED_PAGE
    await expect(page).not.toHaveURL(SUSPENDED_PAGE);
Source
test("banned user is redirected to suspended page and cannot access site", async ({
	page,
}) => {
	await impersonate(page, ADMIN_ID);

	const adminBan = new AdminBanPage(page);
	await adminBan.goto();
	await adminBan.banUser("N-ZAP", { reason: "Test ban reason" });

	await impersonate(page, NZAP_TEST_ID);
	await navigate({ page, url: "/" });

	const suspended = new SuspendedPage(page);
	await expect(page).toHaveURL(SUSPENDED_PAGE);
	await expect(suspended.locators.heading).toBeVisible();
	await expect(suspended.reason("Test ban reason")).toBeVisible();
	await expect(suspended.locators.noEndTime).toBeVisible();

	await navigate({ page, url: "/builds" });
	await expect(page).toHaveURL(SUSPENDED_PAGE);

	await navigate({ page, url: "/calendar" });
	await expect(page).toHaveURL(SUSPENDED_PAGE);

	await impersonate(page, ADMIN_ID);
	await adminBan.goto();
	await adminBan.unbanUser("N-ZAP");

	await impersonate(page, NZAP_TEST_ID);
	await navigate({ page, url: "/" });

	await expect(page).not.toHaveURL(SUSPENDED_PAGE);
})

timed ban shows expiration date on suspended page

SendouN-ZAPban.spec.ts:44

Renders/admin/suspended

SSendou
Admin ban page
Act
  1. Open the admin ban page
    await adminBan.goto();
  2. Ban user “N-ZAP”, expires at startOfHour(setHours(addDays(new Date(), 1), 12)) reason “Temporary ban”
    await adminBan.banUser("N-ZAP", {
    	expiresAt: startOfHour(setHours(addDays(new Date(), 1), 12)),
    	reason: "Temporary ban",
    });
NN-ZAP
Act
  1. Go to “/”
    await navigate({ page, url: "/" });
Assert
  1. the page URL is SUSPENDED_PAGE
    await expect(page).toHaveURL(SUSPENDED_PAGE);
Suspended page
Assert
  1. heading is visible
    await expect(suspended.locators.heading).toBeVisible();
  2. reason “Temporary ban” is visible
    await expect(suspended.reason("Temporary ban")).toBeVisible();
  3. no end time is not visible
    await expect(suspended.locators.noEndTime).not.toBeVisible();
  4. ends at is visible
    await expect(suspended.locators.endsAt).toBeVisible();
Source
test("timed ban shows expiration date on suspended page", async ({
	page,
}) => {
	await impersonate(page, ADMIN_ID);

	const adminBan = new AdminBanPage(page);
	await adminBan.goto();
	await adminBan.banUser("N-ZAP", {
		expiresAt: startOfHour(setHours(addDays(new Date(), 1), 12)),
		reason: "Temporary ban",
	});

	await impersonate(page, NZAP_TEST_ID);
	await navigate({ page, url: "/" });

	const suspended = new SuspendedPage(page);
	await expect(page).toHaveURL(SUSPENDED_PAGE);
	await expect(suspended.locators.heading).toBeVisible();
	await expect(suspended.reason("Temporary ban")).toBeVisible();
	await expect(suspended.locators.noEndTime).not.toBeVisible();
	await expect(suspended.locators.endsAt).toBeVisible();

	// the time based expiration logic itself is covered by app/features/ban/core/banned.test.ts
})