|
1 | 1 | import { describe, expect, it } from "@effect/vitest"; |
2 | | -import { type AssetCreateUrlResult, EnvironmentId } from "@t3tools/contracts"; |
| 2 | +import { type AssetCreateUrlResult, type AssetResource, EnvironmentId } from "@t3tools/contracts"; |
3 | 3 | import * as Cause from "effect/Cause"; |
4 | 4 | import * as Option from "effect/Option"; |
5 | 5 | import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity"; |
6 | 6 |
|
7 | | -import { createProjectFaviconUrlAtomFamily } from "./assets.ts"; |
| 7 | +import { createProjectFaviconUrlAtomFamily, projectFaviconResource } from "./assets.ts"; |
8 | 8 |
|
9 | 9 | describe("project favicon URL cache", () => { |
10 | 10 | it("does not reuse another environment, workspace, or selected icon's cached URL", () => { |
@@ -37,4 +37,45 @@ describe("project favicon URL cache", () => { |
37 | 37 | registry.dispose(); |
38 | 38 | } |
39 | 39 | }); |
| 40 | + |
| 41 | + it("resolves the icon again when its resource's URL query is refreshed", () => { |
| 42 | + const registry = AtomRegistry.make(); |
| 43 | + const answers = ["/api/assets/token/project-favicon-missing", "/api/assets/token/v1-icon.svg"]; |
| 44 | + const query = Atom.family((key: string) => |
| 45 | + Atom.make(() => |
| 46 | + AsyncResult.success({ expiresAt: 4_000_000_000_000, relativeUrl: answers.shift()! }), |
| 47 | + ).pipe(Atom.withLabel(key)), |
| 48 | + ); |
| 49 | + const createUrl = (target: { |
| 50 | + readonly environmentId: EnvironmentId; |
| 51 | + readonly input: { readonly resource: AssetResource }; |
| 52 | + }) => query(JSON.stringify([target.environmentId, target.input.resource])); |
| 53 | + const favicon = createProjectFaviconUrlAtomFamily({ |
| 54 | + createUrl, |
| 55 | + preparedConnection: () => Atom.make(Option.some({ httpBaseUrl: "https://remote.test" })), |
| 56 | + }); |
| 57 | + const target = { |
| 58 | + environmentId: EnvironmentId.make("remote"), |
| 59 | + cwd: "/workspace", |
| 60 | + faviconPath: "icon.svg", |
| 61 | + }; |
| 62 | + const unmount = registry.mount(favicon(target)); |
| 63 | + try { |
| 64 | + expect(registry.get(favicon(target))).toBe( |
| 65 | + "https://remote.test/api/assets/token/project-favicon-missing", |
| 66 | + ); |
| 67 | + registry.refresh( |
| 68 | + createUrl({ |
| 69 | + environmentId: target.environmentId, |
| 70 | + input: { resource: projectFaviconResource(target.cwd, target.faviconPath) }, |
| 71 | + }), |
| 72 | + ); |
| 73 | + expect(registry.get(favicon(target))).toBe( |
| 74 | + "https://remote.test/api/assets/token/v1-icon.svg", |
| 75 | + ); |
| 76 | + } finally { |
| 77 | + unmount(); |
| 78 | + registry.dispose(); |
| 79 | + } |
| 80 | + }); |
40 | 81 | }); |
0 commit comments