Skip to content

Commit ee34a5b

Browse files
committed
Fix TypeScript errors in api-suite.test.ts
- Narrow claTextSha256 (string | null) with explicit null guard - Replace catch (e) + assert instanceof with if (!(e instanceof)) throw e so TypeScript narrows the error type correctly in all 8 catch blocks - Add explicit undefined guards after assert() for find() results (fiveOneFourSig, latestFiveOneFour, historySignature) https://claude.ai/code/session_01EK2y5FsU6reHJY6rLbewFf
1 parent cc9ac79 commit ee34a5b

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

tests/integration/api-suite.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ test("Org detail returns org details, signers, and archives", async (baseUrl) =>
361361
assertEqual(org.isActive, true, "org is active")
362362
assert(org.claText.includes("Contributor License Agreement"), "CLA content present")
363363
assert(typeof org.claTextSha256 === "string", "claTextSha256 is a string")
364-
assert(org.claTextSha256.length === 64, "sha256 is 64 hex chars")
364+
if (org.claTextSha256 === null) throw new Error("claTextSha256 is null")
365+
const claTextSha256 = org.claTextSha256
366+
assert(claTextSha256.length === 64, "sha256 is 64 hex chars")
365367
const signers = await getSignaturesByOrg(org.id)
366368
assertEqual(signers.length, 3, "fiveonefour signers count")
367369
const uniqueSignerCount = new Set(signers.map((s) => s.userId)).size
@@ -371,7 +373,7 @@ test("Org detail returns org details, signers, and archives", async (baseUrl) =>
371373
const archiveSignerCounts = await getSignerCountsByClaSha(org.id)
372374
assert(typeof archiveSignerCounts === "object", "archiveSignerCounts object is present")
373375
assert(
374-
typeof archiveSignerCounts[org.claTextSha256] === "number",
376+
typeof archiveSignerCounts[claTextSha256] === "number",
375377
"archiveSignerCounts contains current CLA count"
376378
)
377379
})
@@ -456,7 +458,7 @@ test("signClaForUser blocks signing on deactivated org", async (baseUrl) => {
456458
await signCla({ orgSlug: "fiveonefour" })
457459
assert(false, "should have thrown SignClaError")
458460
} catch (e) {
459-
assert(e instanceof SignClaError, "SignClaError thrown")
461+
if (!(e instanceof SignClaError)) throw e
460462
assertEqual(e.status, 403, "signing blocked on inactive org")
461463
}
462464
})
@@ -504,7 +506,7 @@ test("signClaForUser prevents duplicate signatures", async (baseUrl) => {
504506
await signCla({ orgSlug: "fiveonefour" })
505507
assert(false, "should have thrown SignClaError")
506508
} catch (e) {
507-
assert(e instanceof SignClaError, "SignClaError thrown")
509+
if (!(e instanceof SignClaError)) throw e
508510
assertEqual(e.status, 409, "duplicate rejected")
509511
}
510512
})
@@ -515,7 +517,7 @@ test("signClaForUser rejects stale acceptedSha256", async (baseUrl) => {
515517
await signCla({ orgSlug: "fiveonefour", acceptedSha256: "deadbeef" })
516518
assert(false, "should have thrown SignClaError")
517519
} catch (e) {
518-
assert(e instanceof SignClaError, "SignClaError thrown")
520+
if (!(e instanceof SignClaError)) throw e
519521
assertEqual(e.status, 409, "stale hash rejected")
520522
}
521523
})
@@ -526,7 +528,7 @@ test("signClaForUser rejects missing orgSlug", async (baseUrl) => {
526528
await signCla({ orgSlug: "" })
527529
assert(false, "should have thrown SignClaError")
528530
} catch (e) {
529-
assert(e instanceof SignClaError, "SignClaError thrown")
531+
if (!(e instanceof SignClaError)) throw e
530532
assertEqual(e.status, 400, "missing orgSlug rejected")
531533
}
532534
})
@@ -537,7 +539,7 @@ test("signClaForUser rejects repoName without prNumber", async (baseUrl) => {
537539
await signCla({ orgSlug: "fiveonefour", repoName: "sdk" })
538540
assert(false, "should have thrown SignClaError")
539541
} catch (e) {
540-
assert(e instanceof SignClaError, "SignClaError thrown")
542+
if (!(e instanceof SignClaError)) throw e
541543
assertEqual(e.status, 400, "repoName without prNumber rejected")
542544
}
543545
})
@@ -548,7 +550,7 @@ test("signClaForUser rejects prNumber without repoName", async (baseUrl) => {
548550
await signCla({ orgSlug: "fiveonefour", prNumber: 12 })
549551
assert(false, "should have thrown SignClaError")
550552
} catch (e) {
551-
assert(e instanceof SignClaError, "SignClaError thrown")
553+
if (!(e instanceof SignClaError)) throw e
552554
assertEqual(e.status, 400, "prNumber without repoName rejected")
553555
}
554556
})
@@ -559,7 +561,7 @@ test("signClaForUser returns NOT_FOUND for nonexistent org", async (baseUrl) =>
559561
await signCla({ orgSlug: "does-not-exist" })
560562
assert(false, "should have thrown SignClaError")
561563
} catch (e) {
562-
assert(e instanceof SignClaError, "SignClaError thrown")
564+
if (!(e instanceof SignClaError)) throw e
563565
assertEqual(e.status, 404, "nonexistent org returns 404")
564566
}
565567
})
@@ -675,6 +677,7 @@ test("Contributor dashboard shows re-sign required after CLA update", async (bas
675677
const { signatures } = await getContributorData(TEST_USERS.contributor.id)
676678
const fiveOneFourSig = signatures.find((s) => s.orgSlug === "fiveonefour")
677679
assert(fiveOneFourSig !== undefined, "fiveonefour signature exists")
680+
if (fiveOneFourSig === undefined) throw new Error("fiveonefour signature missing")
678681
assertEqual(fiveOneFourSig.isCurrentVersion, false, "signature is outdated")
679682
assert(typeof fiveOneFourSig.signedVersionLabel === "string", "signedVersionLabel is a string")
680683
assertEqual(
@@ -737,6 +740,7 @@ test("Contributor dashboard tracks latest signature status per org after re-sign
737740
(s) => s.orgSlug === "fiveonefour" && s.isLatestForOrg
738741
)
739742
assert(latestFiveOneFour !== undefined, "latest fiveonefour signature exists")
743+
if (latestFiveOneFour === undefined) throw new Error("latest fiveonefour signature missing")
740744
assertEqual(latestFiveOneFour.orgNeedsResign, false, "latest signature is compliant")
741745
})
742746

@@ -775,6 +779,7 @@ test("Contributor can view a historical signed CLA version inline", async (baseU
775779
const { signatures } = await getContributorData(TEST_USERS.contributor.id)
776780
const historySignature = signatures.find((s) => s.orgSlug === "fiveonefour" && !s.isLatestForOrg)
777781
assert(historySignature !== undefined, "historical signature exists")
782+
if (historySignature === undefined) throw new Error("historical signature missing")
778783

779784
const viewRes = await fetch(
780785
`${baseUrl}/api/contributor/signatures/${historySignature.id}/download?disposition=inline`
@@ -899,7 +904,7 @@ test("Full flow: deactivate org blocks signing, reactivate allows it", async (ba
899904
await signCla({ orgSlug: "fiveonefour" })
900905
assert(false, "should have thrown SignClaError")
901906
} catch (e) {
902-
assert(e instanceof SignClaError, "SignClaError thrown")
907+
if (!(e instanceof SignClaError)) throw e
903908
assertEqual(e.status, 403, "signing blocked when inactive")
904909
}
905910

0 commit comments

Comments
 (0)