-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathdownloadUtils.spec.ts
34 lines (26 loc) · 1.06 KB
/
downloadUtils.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { expect } from "chai";
import { readFileSync } from "fs-extra";
import * as nock from "nock";
import { gunzipSync, gzipSync } from "zlib";
import { downloadToTmp } from "./downloadUtils";
import { FirebaseError } from "./error";
describe("downloadToTmp", () => {
it("should download a file", async () => {
const content = "hello world";
const gzipContent = gzipSync(content);
nock("https://example.com").get("/foo.gzip").reply(200, gzipContent);
const fName = await downloadToTmp("https://example.com/foo.gzip");
const fileContent = readFileSync(fName);
const gunzipFileContent = gunzipSync(fileContent).toString("utf-8");
expect(gunzipFileContent).to.equal(content);
expect(nock.isDone()).to.be.true;
});
it("should throw an error on non-200 code", async () => {
nock("https://example.com").get("/foo.gzip").reply(404, "Not Found");
await expect(downloadToTmp("https://example.com/foo.gzip")).to.eventually.be.rejectedWith(
FirebaseError,
/Not Found/,
);
expect(nock.isDone()).to.be.true;
});
});