chore: format
This commit is contained in:
@@ -40,7 +40,7 @@ describe('AuthManager Singleton', () => {
|
||||
|
||||
const instance = AuthManager.getInstance(config);
|
||||
expect(instance).toBeDefined();
|
||||
|
||||
|
||||
// Verify the config is passed to internal components
|
||||
// This would be observable when attempting operations that use the config
|
||||
// For example, getCredentials would look in the configured file path
|
||||
|
||||
@@ -56,7 +56,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -79,7 +81,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -100,7 +104,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -120,7 +126,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -140,7 +148,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -160,7 +170,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -181,7 +193,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials();
|
||||
|
||||
@@ -203,7 +217,9 @@ describe('CredentialStore', () => {
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
JSON.stringify(mockCredentials)
|
||||
);
|
||||
|
||||
const result = store.getCredentials({ allowExpired: true });
|
||||
|
||||
@@ -239,7 +255,8 @@ describe('CredentialStore', () => {
|
||||
);
|
||||
|
||||
// Check that the written data contains a valid ISO string
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||
.calls[0][1] as string;
|
||||
const parsed = JSON.parse(writtenData);
|
||||
expect(typeof parsed.expiresAt).toBe('string');
|
||||
expect(new Date(parsed.expiresAt).toISOString()).toBe(parsed.expiresAt);
|
||||
@@ -257,7 +274,8 @@ describe('CredentialStore', () => {
|
||||
|
||||
store.saveCredentials(credentials);
|
||||
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||
.calls[0][1] as string;
|
||||
const parsed = JSON.parse(writtenData);
|
||||
expect(typeof parsed.expiresAt).toBe('string');
|
||||
expect(new Date(parsed.expiresAt).getTime()).toBe(futureTimestamp);
|
||||
@@ -272,8 +290,12 @@ describe('CredentialStore', () => {
|
||||
savedAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
AuthenticationError
|
||||
);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
'Invalid expiresAt format'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject NaN timestamp when saving', () => {
|
||||
@@ -285,8 +307,12 @@ describe('CredentialStore', () => {
|
||||
savedAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
AuthenticationError
|
||||
);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
'Invalid expiresAt format'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject Infinity timestamp when saving', () => {
|
||||
@@ -298,8 +324,12 @@ describe('CredentialStore', () => {
|
||||
savedAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
AuthenticationError
|
||||
);
|
||||
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||
'Invalid expiresAt format'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle missing expiresAt when saving', () => {
|
||||
@@ -313,7 +343,8 @@ describe('CredentialStore', () => {
|
||||
|
||||
store.saveCredentials(credentials);
|
||||
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
||||
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||
.calls[0][1] as string;
|
||||
const parsed = JSON.parse(writtenData);
|
||||
expect(parsed.expiresAt).toBeUndefined();
|
||||
});
|
||||
@@ -394,8 +425,12 @@ describe('CredentialStore', () => {
|
||||
|
||||
store.cleanupCorruptFiles();
|
||||
|
||||
expect(fs.unlinkSync).toHaveBeenCalledWith(expect.stringContaining(oldFile));
|
||||
expect(fs.unlinkSync).not.toHaveBeenCalledWith(expect.stringContaining(newFile));
|
||||
expect(fs.unlinkSync).toHaveBeenCalledWith(
|
||||
expect.stringContaining(oldFile)
|
||||
);
|
||||
expect(fs.unlinkSync).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining(newFile)
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle cleanup errors gracefully', () => {
|
||||
@@ -411,4 +446,4 @@ describe('CredentialStore', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,9 @@ export class CredentialStore {
|
||||
// Normalize/migrate timestamps to numeric (handles both number and ISO string)
|
||||
let expiresAtMs: number | undefined;
|
||||
if (typeof authData.expiresAt === 'number') {
|
||||
expiresAtMs = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined;
|
||||
expiresAtMs = Number.isFinite(authData.expiresAt)
|
||||
? authData.expiresAt
|
||||
: undefined;
|
||||
} else if (typeof authData.expiresAt === 'string') {
|
||||
const parsed = Date.parse(authData.expiresAt);
|
||||
expiresAtMs = Number.isNaN(parsed) ? undefined : parsed;
|
||||
@@ -97,25 +99,27 @@ export class CredentialStore {
|
||||
|
||||
// Add timestamp without mutating caller's object
|
||||
authData = { ...authData, savedAt: new Date().toISOString() };
|
||||
|
||||
|
||||
// Validate and normalize expiresAt timestamp
|
||||
if (authData.expiresAt !== undefined) {
|
||||
let validTimestamp: number | undefined;
|
||||
|
||||
|
||||
if (typeof authData.expiresAt === 'number') {
|
||||
validTimestamp = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined;
|
||||
validTimestamp = Number.isFinite(authData.expiresAt)
|
||||
? authData.expiresAt
|
||||
: undefined;
|
||||
} else if (typeof authData.expiresAt === 'string') {
|
||||
const parsed = Date.parse(authData.expiresAt);
|
||||
validTimestamp = Number.isNaN(parsed) ? undefined : parsed;
|
||||
}
|
||||
|
||||
|
||||
if (validTimestamp === undefined) {
|
||||
throw new AuthenticationError(
|
||||
`Invalid expiresAt format: ${authData.expiresAt}`,
|
||||
'SAVE_FAILED'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Store as ISO string for consistency
|
||||
authData.expiresAt = new Date(validTimestamp).toISOString();
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ export class ConfigManager {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: storageType,
|
||||
basePath,
|
||||
apiConfigured: false
|
||||
return {
|
||||
type: storageType,
|
||||
basePath,
|
||||
apiConfigured: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ export class ConfigManager {
|
||||
|
||||
/**
|
||||
* Check if explicitly configured to use API storage
|
||||
* Excludes 'auto' type
|
||||
* Excludes 'auto' type
|
||||
*/
|
||||
isApiExplicitlyConfigured(): boolean {
|
||||
return this.getStorageConfig().type === 'api';
|
||||
|
||||
@@ -112,8 +112,8 @@ export interface StorageSettings
|
||||
type: StorageType;
|
||||
/** Base path for file storage */
|
||||
basePath?: string;
|
||||
/**
|
||||
* Indicates whether API is configured
|
||||
/**
|
||||
* Indicates whether API is configured
|
||||
* @computed Derived automatically from presence of apiEndpoint or apiAccessToken
|
||||
* @internal Should not be set manually in user config - computed by ConfigManager
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user