/ opencodehub / tests / e2e / full-flow.spec.ts
swadhinbiswas fix: remove trailing garbage characters from full-flow.spec.ts · 7/15/2026
d8121f4
56 lines · 2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { expect, test } from "@playwright/test";
import { execSync } from "child_process";
import fs from "fs";
import os from "os";
import path from "path";

const USERNAME = `user${Date.now()}`;
const PASSWORD = "Password123";
const EMAIL = `${USERNAME}@example.com`;
const REPO_NAME = `repo-${Date.now()}`;

test.describe("Full Flow", () => {
  test("Register, Create Repo, Push Code", async ({ page }) => {
    // 1. Register
    await page.goto("/register");
    await page.fill("#username", USERNAME);
    await page.fill("#email", EMAIL);
    await page.fill("#password", PASSWORD);
    await page.locator('#register-form button[type="submit"]').first().click();

    // Wait for navigation to dashboard
    await page.waitForURL("**/dashboard");

    // 2. Create Repo
    await page.goto("/new");
    await page.fill("#name", REPO_NAME);
    await page.locator('#create-repo-form button[type="submit"]').first().click();

    // Wait for repo page
    await page.waitForURL(`**/${USERNAME}/${REPO_NAME}`, { timeout: 15000 });

    // 3. Push Code
    const repoUrl = `http://${USERNAME}:${PASSWORD}@localhost:4321/${USERNAME}/${REPO_NAME}.git`;
    const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "opencodehub-test-"));

    try {
      execSync("git init -b main", { cwd: tmpDir });
      execSync('git config user.name "Test User"', { cwd: tmpDir });
      execSync('git config user.email "[email protected]"', { cwd: tmpDir });

      fs.writeFileSync(path.join(tmpDir, "README.md"), "# Hello World");
      execSync("git add .", { cwd: tmpDir });
      execSync('git commit -m "Initial commit"', { cwd: tmpDir });
      execSync(`git remote add origin ${repoUrl}`, { cwd: tmpDir });
      execSync("git push -u origin main", { cwd: tmpDir });
    } finally {
      fs.rmSync(tmpDir, { recursive: true, force: true });
    }

    // 4. Verify in UI
    await page.reload();
    await expect(page.locator("text=README.md").first()).toBeVisible({ timeout: 10000 });
    await expect(page.locator("text=Hello World").first()).toBeVisible({ timeout: 10000 });
  });
});