change getOptional to getOptionalString
This commit is contained in:
@@ -89,6 +89,8 @@ describe('AzureApiReaderProcessor', () => {
|
||||
expect: {
|
||||
headers: {},
|
||||
},
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.azureApi.privateToken' in '', got empty-string, wanted string",
|
||||
},
|
||||
{
|
||||
token: undefined,
|
||||
@@ -99,8 +101,14 @@ describe('AzureApiReaderProcessor', () => {
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const processor = new AzureApiReaderProcessor(createConfig(test.token));
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
if (test.err) {
|
||||
expect(
|
||||
() => new AzureApiReaderProcessor(createConfig(test.token)),
|
||||
).toThrowError(test.err);
|
||||
} else {
|
||||
const processor = new AzureApiReaderProcessor(createConfig(test.token));
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,9 +25,8 @@ export class AzureApiReaderProcessor implements LocationProcessor {
|
||||
|
||||
constructor(config: Config) {
|
||||
this.privateToken =
|
||||
(config.getOptional(
|
||||
'catalog.processors.azureApi.privateToken',
|
||||
) as string) ?? '';
|
||||
config.getOptionalString('catalog.processors.azureApi.privateToken') ??
|
||||
'';
|
||||
}
|
||||
|
||||
getRequestOptions(): RequestInit {
|
||||
|
||||
+19
-4
@@ -89,6 +89,8 @@ describe('BitbucketApiReaderProcessor', () => {
|
||||
expect: {
|
||||
headers: {},
|
||||
},
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.bitbucketApi.username' in '', got empty-string, wanted string",
|
||||
},
|
||||
{
|
||||
username: 'only-user-provided',
|
||||
@@ -96,6 +98,8 @@ describe('BitbucketApiReaderProcessor', () => {
|
||||
expect: {
|
||||
headers: {},
|
||||
},
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.bitbucketApi.appPassword' in '', got empty-string, wanted string",
|
||||
},
|
||||
{
|
||||
username: '',
|
||||
@@ -103,6 +107,8 @@ describe('BitbucketApiReaderProcessor', () => {
|
||||
expect: {
|
||||
headers: {},
|
||||
},
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.bitbucketApi.username' in '', got empty-string, wanted string",
|
||||
},
|
||||
{
|
||||
username: 'some-user',
|
||||
@@ -137,10 +143,19 @@ describe('BitbucketApiReaderProcessor', () => {
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const processor = new BitbucketApiReaderProcessor(
|
||||
createConfig(test.username, test.password),
|
||||
);
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
if (test.err) {
|
||||
expect(
|
||||
() =>
|
||||
new BitbucketApiReaderProcessor(
|
||||
createConfig(test.username, test.password),
|
||||
),
|
||||
).toThrowError(test.err);
|
||||
} else {
|
||||
const processor = new BitbucketApiReaderProcessor(
|
||||
createConfig(test.username, test.password),
|
||||
);
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,13 +26,11 @@ export class BitbucketApiReaderProcessor implements LocationProcessor {
|
||||
|
||||
constructor(config: Config) {
|
||||
this.username =
|
||||
(config.getOptional(
|
||||
'catalog.processors.bitbucketApi.username',
|
||||
) as string) ?? '';
|
||||
config.getOptionalString('catalog.processors.bitbucketApi.username') ??
|
||||
'';
|
||||
this.password =
|
||||
(config.getOptional(
|
||||
'catalog.processors.bitbucketApi.appPassword',
|
||||
) as string) ?? '';
|
||||
config.getOptionalString('catalog.processors.bitbucketApi.appPassword') ??
|
||||
'';
|
||||
}
|
||||
|
||||
getRequestOptions(): RequestInit {
|
||||
|
||||
@@ -95,6 +95,16 @@ describe('GithubApiReaderProcessor', () => {
|
||||
},
|
||||
{
|
||||
token: '',
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.githubApi.privateToken' in '', got empty-string, wanted string",
|
||||
expect: {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3.raw',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
token: undefined,
|
||||
expect: {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3.raw',
|
||||
@@ -104,8 +114,16 @@ describe('GithubApiReaderProcessor', () => {
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const processor = new GithubApiReaderProcessor(createConfig(test.token));
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
if (test.err) {
|
||||
expect(
|
||||
() => new GithubApiReaderProcessor(createConfig(test.token)),
|
||||
).toThrowError(test.err);
|
||||
} else {
|
||||
const processor = new GithubApiReaderProcessor(
|
||||
createConfig(test.token),
|
||||
);
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,9 +25,8 @@ export class GithubApiReaderProcessor implements LocationProcessor {
|
||||
|
||||
constructor(config: Config) {
|
||||
this.privateToken =
|
||||
(config.getOptional(
|
||||
'catalog.processors.githubApi.privateToken',
|
||||
) as string) ?? '';
|
||||
config.getOptionalString('catalog.processors.githubApi.privateToken') ??
|
||||
'';
|
||||
}
|
||||
|
||||
getRequestOptions(): RequestInit {
|
||||
|
||||
@@ -100,6 +100,8 @@ describe('GitlabApiReaderProcessor', () => {
|
||||
},
|
||||
{
|
||||
token: '',
|
||||
err:
|
||||
"Invalid type in config for key 'catalog.processors.gitlabApi.privateToken' in '', got empty-string, wanted string",
|
||||
expect: {
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': '',
|
||||
@@ -117,8 +119,16 @@ describe('GitlabApiReaderProcessor', () => {
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const processor = new GitlabApiReaderProcessor(createConfig(test.token));
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
if (test.err) {
|
||||
expect(
|
||||
() => new GitlabApiReaderProcessor(createConfig(test.token)),
|
||||
).toThrowError(test.err);
|
||||
} else {
|
||||
const processor = new GitlabApiReaderProcessor(
|
||||
createConfig(test.token),
|
||||
);
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,9 +25,8 @@ export class GitlabApiReaderProcessor implements LocationProcessor {
|
||||
|
||||
constructor(config: Config) {
|
||||
this.privateToken =
|
||||
(config.getOptional(
|
||||
'catalog.processors.gitlabApi.privateToken',
|
||||
) as string) ?? '';
|
||||
config.getOptionalString('catalog.processors.gitlabApi.privateToken') ??
|
||||
'';
|
||||
}
|
||||
|
||||
getRequestOptions(): RequestInit {
|
||||
|
||||
Reference in New Issue
Block a user