-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathreadOwner.test.ts
51 lines (38 loc) · 1.61 KB
/
readOwner.test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, expect, it, vi } from "vitest";
import { readOwner } from "./readOwner.js";
describe(readOwner, () => {
it("returns git defaults organization when it exists", async () => {
const take = vi.fn();
const organization = "test-organization";
const getGitDefaults = vi.fn().mockResolvedValueOnce({ organization });
const getPackageAuthor = vi.fn();
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
expect(actual).toBe(organization);
expect(take).not.toHaveBeenCalled();
expect(getPackageAuthor).not.toHaveBeenCalled();
});
it("returns package data author when only it exists", async () => {
const take = vi.fn();
const name = "test-author";
const getGitDefaults = vi.fn();
const getPackageAuthor = vi.fn().mockResolvedValueOnce({ name });
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
expect(actual).toBe(name);
expect(take).not.toHaveBeenCalled();
});
it("returns the gh config value when only it resolves", async () => {
const user = "test-user";
const take = vi.fn().mockResolvedValueOnce({ stdout: user });
const getGitDefaults = vi.fn();
const getPackageAuthor = vi.fn().mockResolvedValueOnce({});
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
expect(actual).toBe(user);
});
it("returns undefined when no values exist", async () => {
const take = vi.fn().mockResolvedValueOnce({});
const getGitDefaults = vi.fn();
const getPackageAuthor = vi.fn().mockResolvedValueOnce({});
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
expect(actual).toBe(undefined);
});
});