Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9af8e3f70 |
No files matched your search
+4
-25
@@ -4,12 +4,11 @@
|
|||||||
* each with the callbacks that log its requests and retries, for `quak files`
|
* each with the callbacks that log its requests and retries, for `quak files`
|
||||||
* taking its collection ID as an optional argument, for `quak get` and
|
* taking its collection ID as an optional argument, for `quak get` and
|
||||||
* `quak get-thumb` refusing `--collection`, and for `quak login` taking
|
* `quak get-thumb` refusing `--collection`, and for `quak login` taking
|
||||||
* `--server` and sending its first request to the server it names.
|
* `--server`.
|
||||||
*
|
*
|
||||||
* Each test runs `bin/quak.ts`, as the smoke test does, with its session loader
|
* Each test runs `bin/quak.ts`, as the smoke test does, with its session loader
|
||||||
* replaced by one that records the options it is given and reports no session,
|
* replaced by one that records the options it is given and reports no session,
|
||||||
* so the command stops before it makes any request. `quak login` reads no
|
* so the command stops before it makes any request.
|
||||||
* session, so its test stubs `fetch` instead and records each request.
|
|
||||||
*
|
*
|
||||||
* The first load of the sources `bin/quak.ts` imports compiles them, and the
|
* The first load of the sources `bin/quak.ts` imports compiles them, and the
|
||||||
* first `init()` starts libsodium. On a loaded host that takes longer than a
|
* first `init()` starts libsodium. On a loaded host that takes longer than a
|
||||||
@@ -60,8 +59,6 @@ afterEach(() => {
|
|||||||
process.argv = argv;
|
process.argv = argv;
|
||||||
loaded.length = 0;
|
loaded.length = 0;
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
vi.unstubAllGlobals();
|
|
||||||
vi.unstubAllEnvs();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
@@ -122,30 +119,12 @@ describe("bin/quak.ts get and get-thumb", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The command refuses an address that is not a URL before it asks for anything
|
||||||
|
// or sends any request.
|
||||||
describe("bin/quak.ts login", () => {
|
describe("bin/quak.ts login", () => {
|
||||||
// The command refuses an address that is not a URL before it asks for
|
|
||||||
// anything or sends any request.
|
|
||||||
it("hands --server to the command", async () => {
|
it("hands --server to the command", async () => {
|
||||||
expect(await quak("login", "--server", "ente.example.com")).toMatch(
|
expect(await quak("login", "--server", "ente.example.com")).toMatch(
|
||||||
/^Invalid server address "ente\.example\.com"/,
|
/^Invalid server address "ente\.example\.com"/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// `fetch` answers 404, so the login fails at its first request. A login
|
|
||||||
// that succeeded would save its session in this user's real data
|
|
||||||
// directory, since env-paths is not mocked here.
|
|
||||||
it("sends its first request to the server --server names", async () => {
|
|
||||||
const requests: string[] = [];
|
|
||||||
vi.stubGlobal("fetch", async (input: string) => {
|
|
||||||
const { origin, pathname } = new URL(input);
|
|
||||||
requests.push(origin + pathname);
|
|
||||||
return new Response("not found", { status: 404 });
|
|
||||||
});
|
|
||||||
vi.stubEnv("QUAK_EMAIL", "login@example.com");
|
|
||||||
vi.stubEnv("QUAK_PASSWORD", "password");
|
|
||||||
await quak("login", "--server", "https://ente.example.com");
|
|
||||||
expect(requests).toEqual([
|
|
||||||
"https://ente.example.com/users/srp/attributes",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
@@ -32,8 +32,7 @@
|
|||||||
* fetched.
|
* fetched.
|
||||||
* 10. A cache another account filled starts empty. One filled from another
|
* 10. A cache another account filled starts empty. One filled from another
|
||||||
* server also loses its originals and thumbnails, since two servers can
|
* server also loses its originals and thumbnails, since two servers can
|
||||||
* give two files the same ID. `thumbnailOf` on an empty cache saves the
|
* give two files the same ID.
|
||||||
* account's user ID and server.
|
|
||||||
*
|
*
|
||||||
* The client is a mock: no crypto, no network. It serves scripted pages and
|
* The client is a mock: no crypto, no network. It serves scripted pages and
|
||||||
* records the `sinceTime` each call carried so cursor threading is provable.
|
* records the `sinceTime` each call carried so cursor threading is provable.
|
||||||
@@ -982,38 +981,4 @@ describe("Library.open and background refresh", () => {
|
|||||||
await lib.close();
|
await lib.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// `quak get-thumb` on an empty cache stores a thumbnail before any refresh
|
|
||||||
// runs. `open()` for an account on another server deletes that thumbnail
|
|
||||||
// only if the cache names the account that stored it.
|
|
||||||
it("thumbnailOf on an empty cache saves the account's user ID and server in metadata.json", async () => {
|
|
||||||
const client = new MockClient();
|
|
||||||
client.apiOrigin = "https://ente.example.com";
|
|
||||||
const lib = await Library.open({
|
|
||||||
client,
|
|
||||||
cacheDirectory,
|
|
||||||
refreshOnOpen: false,
|
|
||||||
refreshIntervalSeconds: Infinity,
|
|
||||||
contentSource: {
|
|
||||||
original: async () => {
|
|
||||||
throw new Error("original not expected");
|
|
||||||
},
|
|
||||||
thumbnail: async ({ destination }) => {
|
|
||||||
writeFileSync(destination, "thumb");
|
|
||||||
return { bytesWritten: 5 };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await lib.thumbnailOf(file(1001, 1, 400));
|
|
||||||
} finally {
|
|
||||||
await lib.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
const saved = await MetadataStore.load(
|
|
||||||
join(cacheDirectory, "metadata.json"),
|
|
||||||
);
|
|
||||||
expect(saved.userID).toBe(USER_ID);
|
|
||||||
expect(saved.apiOrigin).toBe("https://ente.example.com");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user