test: cover post-merge gaps in utils, services, and hooks
All checks were successful
CI / verify (push) Successful in 59s
All checks were successful
CI / verify (push) Successful in 59s
Adds specs for the files added or modified in the recent merge that
weren't yet covered: oauthReturnPath, withATProtoImages, link,
displayLanguage, and the useGitHubContent / useImageUpload /
useNoteFreshness hooks. Locks in the new pullLatest contract
({raw, failureStatus}) and the fetchLatestSha branch semantics
(ok/unauthorized/offline).
This commit is contained in:
55
src/modules/atproto/withATProtoImages.spec.ts
Normal file
55
src/modules/atproto/withATProtoImages.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { withATProtoImages } from "./withATProtoImages"
|
||||
|
||||
const PDS = "https://pds.example.com"
|
||||
const DID = "did:plc:abc123"
|
||||
|
||||
describe("withATProtoImages", () => {
|
||||
it("rewrites a bafkrei CID image to a getBlob URL", () => {
|
||||
const out = withATProtoImages(
|
||||
"",
|
||||
{ pds: PDS, did: DID }
|
||||
)
|
||||
|
||||
expect(out).toContain(
|
||||
`${PDS}/xrpc/com.atproto.sync.getBlob`
|
||||
)
|
||||
expect(out).toContain("did=did%3Aplc%3Aabc123")
|
||||
expect(out).toContain(
|
||||
"cid=bafkreigh2akiscaildc7r4apx2t6q4t6n6kxjpw3xhqxkfvvbprdaezz4i"
|
||||
)
|
||||
})
|
||||
|
||||
it("preserves the alt text", () => {
|
||||
const out = withATProtoImages("", {
|
||||
pds: PDS,
|
||||
did: DID
|
||||
})
|
||||
expect(out).toMatch(/!\[my cover\]/)
|
||||
})
|
||||
|
||||
it("rewrites multiple images in one pass", () => {
|
||||
const md = " and "
|
||||
const out = withATProtoImages(md, { pds: PDS, did: DID })
|
||||
|
||||
expect(out.match(/com\.atproto\.sync\.getBlob/g)).toHaveLength(2)
|
||||
expect(out).toContain("cid=bafkreiaaa")
|
||||
expect(out).toContain("cid=bafkreibbb")
|
||||
})
|
||||
|
||||
it("leaves regular image URLs untouched", () => {
|
||||
const md = ""
|
||||
expect(withATProtoImages(md, { pds: PDS, did: DID })).toBe(md)
|
||||
})
|
||||
|
||||
it("leaves CIDs that don't match the bafkrei prefix untouched", () => {
|
||||
const md = ""
|
||||
expect(withATProtoImages(md, { pds: PDS, did: DID })).toBe(md)
|
||||
})
|
||||
|
||||
it("preserves an empty alt text", () => {
|
||||
const out = withATProtoImages("", { pds: PDS, did: DID })
|
||||
expect(out).toMatch(/^!\[\]/)
|
||||
})
|
||||
})
|
||||
30
src/modules/user/service/oauthReturnPath.spec.ts
Normal file
30
src/modules/user/service/oauthReturnPath.spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest"
|
||||
|
||||
import {
|
||||
consumeGithubOAuthReturnPath,
|
||||
GITHUB_OAUTH_RETURN_PATH_KEY
|
||||
} from "./oauthReturnPath"
|
||||
|
||||
describe("consumeGithubOAuthReturnPath", () => {
|
||||
beforeEach(() => {
|
||||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
it("returns the stored path and clears the key", () => {
|
||||
sessionStorage.setItem(GITHUB_OAUTH_RETURN_PATH_KEY, "/alice/notes")
|
||||
|
||||
expect(consumeGithubOAuthReturnPath()).toBe("/alice/notes")
|
||||
expect(sessionStorage.getItem(GITHUB_OAUTH_RETURN_PATH_KEY)).toBeNull()
|
||||
})
|
||||
|
||||
it("returns null when nothing is stored", () => {
|
||||
expect(consumeGithubOAuthReturnPath()).toBeNull()
|
||||
})
|
||||
|
||||
it("returns null on the second call (consume-once semantics)", () => {
|
||||
sessionStorage.setItem(GITHUB_OAUTH_RETURN_PATH_KEY, "/x")
|
||||
|
||||
expect(consumeGithubOAuthReturnPath()).toBe("/x")
|
||||
expect(consumeGithubOAuthReturnPath()).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user