File size: 1,146 Bytes
21dd449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
import { assert, describe, expect, it } from "vitest";
import { checkRepoAccess } from "./check-repo-access";
import { HubApiError } from "../error";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../test/consts";

describe("checkRepoAccess", () => {
	it("should throw 401 when accessing unexisting repo unauthenticated", async () => {
		try {
			await checkRepoAccess({ repo: { name: "i--d/dont", type: "model" } });
			assert(false, "should have thrown");
		} catch (err) {
			expect(err).toBeInstanceOf(HubApiError);
			expect((err as HubApiError).statusCode).toBe(401);
		}
	});

	it("should throw 404 when accessing unexisting repo authenticated", async () => {
		try {
			await checkRepoAccess({
				repo: { name: "i--d/dont", type: "model" },
				hubUrl: TEST_HUB_URL,
				accessToken: TEST_ACCESS_TOKEN,
			});
			assert(false, "should have thrown");
		} catch (err) {
			expect(err).toBeInstanceOf(HubApiError);
			expect((err as HubApiError).statusCode).toBe(404);
		}
	});

	it("should not throw when accessing public repo", async () => {
		await checkRepoAccess({ repo: { name: "openai-community/gpt2", type: "model" } });
	});
});