/ opencodehub / tests / e2e / full-flow.spec.ts
swadhinbiswas Initial commit of OpenCodeHub source · 12/11/2025
1110042
56 lines · 1.9 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.click('button[type="submit"]');

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

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

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

    // 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", { 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")).toBeVisible();
    await expect(page.locator("text=Hello World")).toBeVisible();
  });
});