feat(14-06): convert all 9 service test files to async PGlite
- All beforeEach now use async/await createTestDb() - All service calls in tests now awaited - All direct DB calls (.run()/.all()) replaced with await - All test callbacks made async - Fixed PostgreSQL GROUP BY strictness in totals.service.ts (categories.name and categories.icon added to groupBy) - db type changed to 'any' to accommodate PGlite type differences Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,15 +17,15 @@ function generatePkce() {
|
||||
}
|
||||
|
||||
describe("OAuth Service", () => {
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: any;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
beforeEach(async () => {
|
||||
db = await createTestDb();
|
||||
});
|
||||
|
||||
describe("Client Registration", () => {
|
||||
it("registers a client and returns clientId (string, non-empty)", () => {
|
||||
const result = registerClient(db, "Test App", [
|
||||
it("registers a client and returns clientId (string, non-empty)", async () => {
|
||||
const result = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
|
||||
@@ -34,32 +34,32 @@ describe("OAuth Service", () => {
|
||||
expect(result.clientId.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("getClient returns registered client with correct clientName and redirectUris (JSON parsed)", () => {
|
||||
it("getClient returns registered client with correct clientName and redirectUris (JSON parsed)", async () => {
|
||||
const redirectUris = ["http://localhost:8080/callback"];
|
||||
const { clientId } = registerClient(db, "Test App", redirectUris);
|
||||
const { clientId } = await registerClient(db, "Test App", redirectUris);
|
||||
|
||||
const client = getClient(db, clientId);
|
||||
const client = await getClient(db, clientId);
|
||||
|
||||
expect(client).not.toBeNull();
|
||||
expect(client!.clientName).toBe("Test App");
|
||||
expect(JSON.parse(client!.redirectUris)).toEqual(redirectUris);
|
||||
});
|
||||
|
||||
it("getClient returns null for unknown client", () => {
|
||||
const client = getClient(db, "unknown-client-id");
|
||||
it("getClient returns null for unknown client", async () => {
|
||||
const client = await getClient(db, "unknown-client-id");
|
||||
|
||||
expect(client).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Authorization Code + PKCE", () => {
|
||||
it("creates an authorization code (non-empty)", () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
it("creates an authorization code (non-empty)", async () => {
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { challenge } = generatePkce();
|
||||
|
||||
const result = createAuthorizationCode(
|
||||
const result = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -73,12 +73,12 @@ describe("OAuth Service", () => {
|
||||
});
|
||||
|
||||
it("exchanges code for tokens with valid PKCE verifier (returns accessToken, refreshToken, expiresIn=3600)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -103,12 +103,12 @@ describe("OAuth Service", () => {
|
||||
});
|
||||
|
||||
it("rejects code exchange with wrong PKCE verifier (returns null)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -128,12 +128,12 @@ describe("OAuth Service", () => {
|
||||
});
|
||||
|
||||
it("rejects code exchange with wrong redirect_uri (returns null)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -153,12 +153,12 @@ describe("OAuth Service", () => {
|
||||
});
|
||||
|
||||
it("rejects replayed code - single use (second exchange returns null)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -190,12 +190,12 @@ describe("OAuth Service", () => {
|
||||
|
||||
describe("Token Verification", () => {
|
||||
it("verifies a valid access token (returns true)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -223,12 +223,12 @@ describe("OAuth Service", () => {
|
||||
|
||||
describe("Token Refresh", () => {
|
||||
it("refreshes a valid refresh token and returns new tokens (different accessToken)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
@@ -257,12 +257,12 @@ describe("OAuth Service", () => {
|
||||
});
|
||||
|
||||
it("rejects refresh with wrong clientId (returns null)", async () => {
|
||||
const { clientId } = registerClient(db, "Test App", [
|
||||
const { clientId } = await registerClient(db, "Test App", [
|
||||
"http://localhost:8080/callback",
|
||||
]);
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
const { code } = createAuthorizationCode(
|
||||
const { code } = await createAuthorizationCode(
|
||||
db,
|
||||
clientId,
|
||||
challenge,
|
||||
|
||||
Reference in New Issue
Block a user