Files
renovate/lib/modules/datasource/utils.spec.ts
Sebastian Poxhofer d57843c60d refactor(oxlint): enable typescript/no-unnecessary-type-arguments (#44555)
Enable the type-aware typescript/no-unnecessary-type-arguments rule as
error and remove all 44 pre-existing redundant type arguments (type
arguments identical to the type parameter default), e.g.
HttpResponse<string>, ZodError<unknown>,
PackageDependency<Record<string, any>>.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 12:33:42 +00:00

86 lines
2.2 KiB
TypeScript

import { GoogleAuth as _googleAuth } from 'google-auth-library';
import type { HttpResponse } from '../../util/http/types.ts';
import { getGoogleAuthToken, isArtifactoryServer } from './util.ts';
vi.mock('google-auth-library');
const googleAuth = vi.mocked(_googleAuth);
describe('modules/datasource/utils', () => {
it('is artifactory server invalid', () => {
const response: HttpResponse = {
statusCode: 200,
body: 'test',
headers: { 'invalid-header': 'version' },
};
expect(isArtifactoryServer(response)).toBeFalse();
});
it('is artifactory server valid', () => {
const response: HttpResponse = {
statusCode: 200,
body: 'test',
headers: { 'x-jfrog-version': 'version' },
};
expect(isArtifactoryServer(response)).toBeTrue();
});
it('retrieves a Google Access token', async () => {
googleAuth.mockImplementationOnce(
// TODO: fix typing
vi.fn<any>(
class {
getAccessToken = vi.fn().mockResolvedValue('some-token');
},
),
);
const res = await getGoogleAuthToken();
expect(res).toBe('b2F1dGgyYWNjZXNzdG9rZW46c29tZS10b2tlbg==');
});
it('no Google Access token results in null', async () => {
googleAuth.mockImplementationOnce(
// TODO: fix typing
vi.fn<any>(
class {
getAccessToken = vi.fn().mockResolvedValue('');
},
),
);
const res = await getGoogleAuthToken();
expect(res).toBeNull();
});
it('Google Access token error throws an exception', async () => {
const err = 'some-error';
googleAuth.mockImplementationOnce(
// TODO: fix typing
vi.fn<any>(
class {
getAccessToken = vi.fn().mockRejectedValue(new Error(err));
},
),
);
await expect(getGoogleAuthToken()).rejects.toThrow('some-error');
});
it('Google Access token could not load default credentials', async () => {
googleAuth.mockImplementationOnce(
// TODO: fix typing
vi.fn<any>(
class {
getAccessToken = vi.fn().mockRejectedValue({
message: 'Could not load the default credentials',
});
},
),
);
const res = await getGoogleAuthToken();
expect(res).toBeNull();
});
});