mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-10-11 04:41:17 +02:00
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import * as Cloudflare from "alchemy/Cloudflare";
|
|
import * as Test from "alchemy/Test/Bun";
|
|
import { expect } from "bun:test";
|
|
import * as Effect from "effect/Effect";
|
|
import * as HttpApiClient from "effect/http-api/HttpApiClient";
|
|
import { RepoApi } from "../src/Api.ts";
|
|
import Stack from "../alchemy.run.ts";
|
|
|
|
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
|
providers: Cloudflare.providers(),
|
|
state: Cloudflare.state(),
|
|
});
|
|
|
|
const stack = beforeAll(deploy(Stack));
|
|
afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
|
|
|
|
// Deterministic repo name — the same on every run (never Date.now()/random)
|
|
// so a crashed run's leftover repo is purged below instead of leaking.
|
|
const repoName = "tutorial-integ-lifecycle";
|
|
|
|
test(
|
|
"repo lifecycle",
|
|
Effect.gen(function* () {
|
|
const { url } = yield* stack;
|
|
const client = yield* HttpApiClient.make(RepoApi, { baseUrl: url });
|
|
|
|
// Purge any leftover from a previously crashed run so createRepo
|
|
// doesn't fail with RepoConflict.
|
|
yield* client.repos
|
|
.deleteRepo({ params: { name: repoName } })
|
|
.pipe(Effect.catchTag("RepoNotFound", () => Effect.void));
|
|
|
|
const created = yield* client.repos.createRepo({
|
|
payload: { name: repoName, description: "tutorial repo" },
|
|
});
|
|
expect(created.name).toBe(repoName);
|
|
expect(created.remote).toBeString();
|
|
expect(created.token).toBeString();
|
|
|
|
const info = yield* client.repos.getRepo({ params: { name: repoName } });
|
|
expect(info.name).toBe(repoName);
|
|
expect(info.defaultBranch).toBe("main");
|
|
expect(info.metadata?.description).toBe("tutorial repo");
|
|
expect(info.metadata?.stars).toBe(0);
|
|
|
|
const token = yield* client.repos.cloneToken({
|
|
params: { name: repoName },
|
|
payload: { scope: "read", ttl: 600 },
|
|
});
|
|
expect(token.plaintext).toBeString();
|
|
expect(token.scope).toBe("read");
|
|
|
|
const updated = yield* client.repos.updateRepo({
|
|
params: { name: repoName },
|
|
payload: { description: "now with stars", topics: ["demo", "alchemy"] },
|
|
});
|
|
expect(updated.description).toBe("now with stars");
|
|
expect(updated.topics).toEqual(["demo", "alchemy"]);
|
|
|
|
const starred = yield* client.repos.starRepo({
|
|
params: { name: repoName },
|
|
});
|
|
expect(starred.stars).toBe(1);
|
|
|
|
yield* client.repos.deleteRepo({ params: { name: repoName } });
|
|
}),
|
|
{ timeout: 120_000 },
|
|
);
|