Add id and name to GitCredentials

This commit is contained in:
Alex Gleason committed 2025-12-20 23:54:00 -06:00
1 parent 6dfedaa97e
commit 9c2f4f9eb6
8 files changed
+204 -193

No files matched your search

+20 -7
View File
@@ -14,10 +14,12 @@ vi.mock('@/lib/configUtils', () => ({
// Test component that uses the hook
function TestComponent() {
const { settings, addCredential, removeCredential, updateCredential, isConfigured } = useGitSettings();
const { settings, addCredential, removeCredential, setCredentials, isConfigured } = useGitSettings();
const handleAdd = () => {
const credential: GitCredential = {
id: crypto.randomUUID(),
name: 'GitHub',
protocol: 'https',
host: 'github.com',
username: 'git',
@@ -27,11 +29,20 @@ function TestComponent() {
};
const handleUpdate = () => {
updateCredential(0, { password: 'updated-token' });
const githubCred = settings.credentials.find(c => c.host === 'github.com');
if (githubCred) {
const updatedCredentials = settings.credentials.map((cred) =>
cred.id === githubCred.id ? { ...cred, password: 'updated-token' } : cred
);
setCredentials(updatedCredentials);
}
};
const handleRemove = () => {
removeCredential(0);
const githubCred = settings.credentials.find(c => c.host === 'github.com');
if (githubCred) {
removeCredential(githubCred.id);
}
};
const githubCred = settings.credentials.find(c => c.host === 'github.com');
@@ -168,14 +179,14 @@ describe('GitSettingsProvider', () => {
expect(writeGitSettings).toHaveBeenCalledWith(
expect.anything(), // fs instance
expect.objectContaining({
credentials: [
{
credentials: expect.arrayContaining([
expect.objectContaining({
protocol: 'https',
host: 'github.com',
username: 'git',
password: 'test-token',
}
]
})
])
}),
'/config' // configPath
);
@@ -186,6 +197,8 @@ describe('GitSettingsProvider', () => {
const settings = {
credentials: [
{
id: crypto.randomUUID(),
name: 'GitLab',
protocol: 'https',
host: 'gitlab.com',
username: 'git',
+2 -17
View File
@@ -61,27 +61,13 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
}));
};
const removeCredential = (index: number) => {
const removeCredential = (id: string) => {
setSettings(prev => ({
...prev,
credentials: prev.credentials.filter((_, i) => i !== index),
credentials: prev.credentials.filter((cred) => cred.id !== id),
}));
};
const updateCredential = (index: number, credential: Partial<GitCredential>) => {
setSettings(prev => {
const newCredentials = [...prev.credentials];
newCredentials[index] = {
...newCredentials[index],
...credential,
};
return {
...prev,
credentials: newCredentials,
};
});
};
const setCredentials = (credentials: GitCredential[]) => {
setSettings(prev => ({
...prev,
@@ -96,7 +82,6 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
updateSettings,
addCredential,
removeCredential,
updateCredential,
setCredentials,
isConfigured,
isInitialized,