Skip to content

Commit edfde67

Browse files
committed
style: fix prettier formatting
1 parent d279324 commit edfde67

7 files changed

Lines changed: 92 additions & 122 deletions

File tree

src/commands/project/resolve-org.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ export function extractUniqueOrgs(projects: Array<{ organization: OrganizationIn
1414
return orgs;
1515
}
1616

17-
export async function resolveOrg(
18-
projects: ApiProject[],
19-
orgFlag: string | undefined,
20-
): Promise<{ slug: string; orgs: OrganizationInfo[] }> {
17+
export async function resolveOrg(projects: ApiProject[], orgFlag: string | undefined): Promise<{ slug: string; orgs: OrganizationInfo[] }> {
2118
if (orgFlag) {
2219
return { slug: orgFlag, orgs: [] };
2320
}

src/prompts/project-create.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ export function needsInteractiveMode(options: CreateProjectOptions): boolean {
1010
return !options.url && !options.github;
1111
}
1212

13-
export async function runInteractiveFlow(
14-
client: YavyApiClient,
15-
options: CreateProjectOptions,
16-
): Promise<CreateProjectOptions> {
13+
export async function runInteractiveFlow(client: YavyApiClient, options: CreateProjectOptions): Promise<CreateProjectOptions> {
1714
const source = await collectSourceFromPrompts();
1815
const orgSlug = await resolveOrgInteractively(client, options.org);
1916

@@ -36,10 +33,7 @@ export async function collectSourceFromPrompts(): Promise<Pick<CreateProjectOpti
3633
return { github };
3734
}
3835

39-
export async function resolveOrgInteractively(
40-
client: YavyApiClient,
41-
orgFlag: string | undefined,
42-
): Promise<string> {
36+
export async function resolveOrgInteractively(client: YavyApiClient, orgFlag: string | undefined): Promise<string> {
4337
if (orgFlag) {
4438
return orgFlag;
4539
}

src/utils/errors.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ function formatValidationErrors(body: unknown): string {
4646
}
4747

4848
function isValidationError(body: unknown): body is ApiValidationError {
49-
return (
50-
typeof body === 'object' &&
51-
body !== null &&
52-
'errors' in body &&
53-
typeof (body as ApiValidationError).errors === 'object'
54-
);
49+
return typeof body === 'object' && body !== null && 'errors' in body && typeof (body as ApiValidationError).errors === 'object';
5550
}
5651

5752
function extractMessage(body: unknown): string {

tests/commands/project/build-request.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ describe('buildCreateProjectPayload', () => {
9696
});
9797

9898
it('throws when neither --url nor --github is provided', () => {
99-
expect(() => buildCreateProjectPayload({})).toThrow(
100-
'Either --url or --github is required.',
101-
);
99+
expect(() => buildCreateProjectPayload({})).toThrow('Either --url or --github is required.');
102100
});
103101
});

tests/commands/project/create.test.ts

Lines changed: 79 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ import { getAccessToken } from '@/auth/store';
2222
import { needsInteractiveMode, runInteractiveFlow } from '@/prompts/project-create';
2323

2424
function mockFetchResponse(status: number, body: unknown): void {
25-
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
26-
ok: status >= 200 && status < 300,
27-
status,
28-
json: () => Promise.resolve(body),
29-
headers: new Headers(),
30-
}));
25+
vi.stubGlobal(
26+
'fetch',
27+
vi.fn().mockResolvedValue({
28+
ok: status >= 200 && status < 300,
29+
status,
30+
json: () => Promise.resolve(body),
31+
headers: new Headers(),
32+
}),
33+
);
3134
}
3235

3336
describe('executeCreateProject', () => {
@@ -45,57 +48,60 @@ describe('executeCreateProject', () => {
4548
it('throws when no token is available', async () => {
4649
vi.mocked(getAccessToken).mockResolvedValue(null);
4750

48-
await expect(executeCreateProject({ url: 'https://docs.example.com' }))
49-
.rejects.toThrow('Not authenticated');
51+
await expect(executeCreateProject({ url: 'https://docs.example.com' })).rejects.toThrow('Not authenticated');
5052
});
5153

5254
it('throws when both --url and --github are provided', async () => {
5355
vi.mocked(getAccessToken).mockResolvedValue('test-token');
5456
mockFetchResponse(200, { data: [] });
5557

56-
await expect(executeCreateProject({
57-
url: 'https://docs.example.com',
58-
github: 'owner/repo',
59-
})).rejects.toThrow('not both');
58+
await expect(
59+
executeCreateProject({
60+
url: 'https://docs.example.com',
61+
github: 'owner/repo',
62+
}),
63+
).rejects.toThrow('not both');
6064
});
6165

6266
it('throws when no source is provided and interactive mode is skipped', async () => {
6367
vi.mocked(getAccessToken).mockResolvedValue('test-token');
6468
vi.mocked(needsInteractiveMode).mockReturnValue(false);
6569
mockFetchResponse(200, { data: [] });
6670

67-
await expect(executeCreateProject({}))
68-
.rejects.toThrow('--url or --github is required');
71+
await expect(executeCreateProject({})).rejects.toThrow('--url or --github is required');
6972
});
7073

7174
it('creates a project successfully with --url and --org', async () => {
7275
vi.mocked(getAccessToken).mockResolvedValue('test-token');
7376

74-
const fetchMock = vi.fn()
77+
const fetchMock = vi
78+
.fn()
7579
.mockResolvedValueOnce({
7680
ok: true,
7781
status: 200,
78-
json: () => Promise.resolve({
79-
data: [{ organization: { name: 'My Org', slug: 'my-org' } }],
80-
}),
82+
json: () =>
83+
Promise.resolve({
84+
data: [{ organization: { name: 'My Org', slug: 'my-org' } }],
85+
}),
8186
headers: new Headers(),
8287
})
8388
.mockResolvedValueOnce({
8489
ok: true,
8590
status: 201,
86-
json: () => Promise.resolve({
87-
data: {
88-
id: 1,
89-
name: 'Example Docs',
90-
slug: 'example-docs',
91-
description: null,
92-
organization: { name: 'My Org', slug: 'my-org' },
93-
pages_count: 0,
94-
last_indexed_at: null,
95-
has_indexed_content: false,
96-
mcp_url: 'https://yavy.dev/mcp/my-org/example-docs',
97-
},
98-
}),
91+
json: () =>
92+
Promise.resolve({
93+
data: {
94+
id: 1,
95+
name: 'Example Docs',
96+
slug: 'example-docs',
97+
description: null,
98+
organization: { name: 'My Org', slug: 'my-org' },
99+
pages_count: 0,
100+
last_indexed_at: null,
101+
has_indexed_content: false,
102+
mcp_url: 'https://yavy.dev/mcp/my-org/example-docs',
103+
},
104+
}),
99105
headers: new Headers(),
100106
});
101107
vi.stubGlobal('fetch', fetchMock);
@@ -105,39 +111,40 @@ describe('executeCreateProject', () => {
105111
org: 'my-org',
106112
});
107113

108-
expect(consoleSpy).toHaveBeenCalledWith(
109-
expect.stringContaining('Project created successfully!'),
110-
);
114+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Project created successfully!'));
111115
});
112116

113117
it('auto-selects org when user has exactly one', async () => {
114118
vi.mocked(getAccessToken).mockResolvedValue('test-token');
115119

116-
const fetchMock = vi.fn()
120+
const fetchMock = vi
121+
.fn()
117122
.mockResolvedValueOnce({
118123
ok: true,
119124
status: 200,
120-
json: () => Promise.resolve({
121-
data: [{ organization: { name: 'Solo Org', slug: 'solo-org' } }],
122-
}),
125+
json: () =>
126+
Promise.resolve({
127+
data: [{ organization: { name: 'Solo Org', slug: 'solo-org' } }],
128+
}),
123129
headers: new Headers(),
124130
})
125131
.mockResolvedValueOnce({
126132
ok: true,
127133
status: 201,
128-
json: () => Promise.resolve({
129-
data: {
130-
id: 2,
131-
name: 'Docs',
132-
slug: 'docs',
133-
description: null,
134-
organization: { name: 'Solo Org', slug: 'solo-org' },
135-
pages_count: 0,
136-
last_indexed_at: null,
137-
has_indexed_content: false,
138-
mcp_url: 'https://yavy.dev/mcp/solo-org/docs',
139-
},
140-
}),
134+
json: () =>
135+
Promise.resolve({
136+
data: {
137+
id: 2,
138+
name: 'Docs',
139+
slug: 'docs',
140+
description: null,
141+
organization: { name: 'Solo Org', slug: 'solo-org' },
142+
pages_count: 0,
143+
last_indexed_at: null,
144+
has_indexed_content: false,
145+
mcp_url: 'https://yavy.dev/mcp/solo-org/docs',
146+
},
147+
}),
141148
headers: new Headers(),
142149
});
143150
vi.stubGlobal('fetch', fetchMock);
@@ -159,40 +166,41 @@ describe('executeCreateProject', () => {
159166
name: 'Interactive Project',
160167
});
161168

162-
const fetchMock = vi.fn()
169+
const fetchMock = vi
170+
.fn()
163171
.mockResolvedValueOnce({
164172
ok: true,
165173
status: 200,
166-
json: () => Promise.resolve({
167-
data: [{ organization: { name: 'My Org', slug: 'my-org' } }],
168-
}),
174+
json: () =>
175+
Promise.resolve({
176+
data: [{ organization: { name: 'My Org', slug: 'my-org' } }],
177+
}),
169178
headers: new Headers(),
170179
})
171180
.mockResolvedValueOnce({
172181
ok: true,
173182
status: 201,
174-
json: () => Promise.resolve({
175-
data: {
176-
id: 3,
177-
name: 'Interactive Project',
178-
slug: 'interactive-project',
179-
description: null,
180-
organization: { name: 'My Org', slug: 'my-org' },
181-
pages_count: 0,
182-
last_indexed_at: null,
183-
has_indexed_content: false,
184-
mcp_url: 'https://yavy.dev/mcp/my-org/interactive-project',
185-
},
186-
}),
183+
json: () =>
184+
Promise.resolve({
185+
data: {
186+
id: 3,
187+
name: 'Interactive Project',
188+
slug: 'interactive-project',
189+
description: null,
190+
organization: { name: 'My Org', slug: 'my-org' },
191+
pages_count: 0,
192+
last_indexed_at: null,
193+
has_indexed_content: false,
194+
mcp_url: 'https://yavy.dev/mcp/my-org/interactive-project',
195+
},
196+
}),
187197
headers: new Headers(),
188198
});
189199
vi.stubGlobal('fetch', fetchMock);
190200

191201
await executeCreateProject({});
192202

193203
expect(runInteractiveFlow).toHaveBeenCalled();
194-
expect(consoleSpy).toHaveBeenCalledWith(
195-
expect.stringContaining('Project created successfully!'),
196-
);
204+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Project created successfully!'));
197205
});
198206
});

tests/commands/project/resolve-org.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ describe('extractUniqueOrgs', () => {
2222
});
2323

2424
it('returns single org when all projects belong to one', () => {
25-
const projects = [
26-
{ organization: { name: 'Solo', slug: 'solo' } },
27-
{ organization: { name: 'Solo', slug: 'solo' } },
28-
];
25+
const projects = [{ organization: { name: 'Solo', slug: 'solo' } }, { organization: { name: 'Solo', slug: 'solo' } }];
2926

3027
const orgs = extractUniqueOrgs(projects);
3128

@@ -42,20 +39,15 @@ describe('resolveOrg', () => {
4239
});
4340

4441
it('auto-selects when user has exactly one org', async () => {
45-
const projects = [
46-
{ organization: { name: 'Solo Org', slug: 'solo-org' } },
47-
] as never[];
42+
const projects = [{ organization: { name: 'Solo Org', slug: 'solo-org' } }] as never[];
4843

4944
const result = await resolveOrg(projects, undefined);
5045

5146
expect(result.slug).toBe('solo-org');
5247
});
5348

5449
it('returns empty slug with orgs list when multiple orgs exist', async () => {
55-
const projects = [
56-
{ organization: { name: 'Org A', slug: 'org-a' } },
57-
{ organization: { name: 'Org B', slug: 'org-b' } },
58-
] as never[];
50+
const projects = [{ organization: { name: 'Org A', slug: 'org-a' } }, { organization: { name: 'Org B', slug: 'org-b' } }] as never[];
5951

6052
const result = await resolveOrg(projects, undefined);
6153

tests/prompts/project-create.test.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ vi.mock('@/commands/project/resolve-org', () => ({
2727

2828
import * as p from '@clack/prompts';
2929
import { resolveOrg } from '@/commands/project/resolve-org';
30-
import {
31-
collectSourceFromPrompts,
32-
needsInteractiveMode,
33-
resolveOrgInteractively,
34-
runInteractiveFlow,
35-
} from '@/prompts/project-create';
30+
import { collectSourceFromPrompts, needsInteractiveMode, resolveOrgInteractively, runInteractiveFlow } from '@/prompts/project-create';
3631

3732
describe('needsInteractiveMode', () => {
3833
it('returns true when no source flag is provided', () => {
@@ -64,9 +59,7 @@ describe('collectSourceFromPrompts', () => {
6459
const result = await collectSourceFromPrompts();
6560

6661
expect(result).toEqual({ url: 'https://docs.example.com' });
67-
expect(p.select).toHaveBeenCalledWith(
68-
expect.objectContaining({ message: 'What type of documentation source?' }),
69-
);
62+
expect(p.select).toHaveBeenCalledWith(expect.objectContaining({ message: 'What type of documentation source?' }));
7063
});
7164

7265
it('prompts for owner/repo when user selects GitHub', async () => {
@@ -101,9 +94,7 @@ describe('resolveOrgInteractively', () => {
10194
});
10295

10396
it('auto-selects when user has exactly one org', async () => {
104-
mockClient.listProjects.mockResolvedValue([
105-
{ organization: { name: 'Solo Org', slug: 'solo-org' } },
106-
]);
97+
mockClient.listProjects.mockResolvedValue([{ organization: { name: 'Solo Org', slug: 'solo-org' } }]);
10798
vi.mocked(resolveOrg).mockResolvedValue({
10899
slug: 'solo-org',
109100
orgs: [{ name: 'Solo Org', slug: 'solo-org' }],
@@ -119,10 +110,7 @@ describe('resolveOrgInteractively', () => {
119110
{ name: 'Org A', slug: 'org-a' },
120111
{ name: 'Org B', slug: 'org-b' },
121112
];
122-
mockClient.listProjects.mockResolvedValue([
123-
{ organization: orgs[0] },
124-
{ organization: orgs[1] },
125-
]);
113+
mockClient.listProjects.mockResolvedValue([{ organization: orgs[0] }, { organization: orgs[1] }]);
126114
vi.mocked(resolveOrg).mockResolvedValue({ slug: '', orgs });
127115
vi.mocked(p.select).mockResolvedValueOnce('org-b');
128116

@@ -144,9 +132,7 @@ describe('runInteractiveFlow', () => {
144132

145133
it('merges prompt results with existing options', async () => {
146134
const mockClient = {
147-
listProjects: vi.fn().mockResolvedValue([
148-
{ organization: { name: 'My Org', slug: 'my-org' } },
149-
]),
135+
listProjects: vi.fn().mockResolvedValue([{ organization: { name: 'My Org', slug: 'my-org' } }]),
150136
createProject: vi.fn(),
151137
};
152138
vi.mocked(resolveOrg).mockResolvedValue({

0 commit comments

Comments
 (0)