catalog(github): add test get request options
This commit is contained in:
@@ -60,6 +60,30 @@ describe('GithubReaderProcessor', () => {
|
||||
});
|
||||
|
||||
it('should return request options', () => {
|
||||
// todo
|
||||
const tests = [
|
||||
{
|
||||
token: '0123456789',
|
||||
expect: {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3.raw',
|
||||
Authorization: 'token 0123456789',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
token: '',
|
||||
expect: {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3.raw',
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
process.env.GITHUB_PRIVATE_TOKEN = test.token;
|
||||
const processor = new GithubReaderProcessor();
|
||||
expect(processor.getRequestOptions()).toEqual(test.expect);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,15 +19,16 @@ import fetch, { RequestInit, HeadersInit } from 'node-fetch';
|
||||
import * as result from './results';
|
||||
import { LocationProcessor, LocationProcessorEmit } from './types';
|
||||
|
||||
const privateToken: string = process.env.GITHUB_PRIVATE_TOKEN || '';
|
||||
|
||||
export class GithubReaderProcessor implements LocationProcessor {
|
||||
private privateToken: string = process.env.GITHUB_PRIVATE_TOKEN || '';
|
||||
|
||||
getRequestOptions(): RequestInit {
|
||||
const headers: HeadersInit = {
|
||||
Accept: 'application/vnd.github.v3.raw',
|
||||
};
|
||||
if (privateToken) {
|
||||
headers.Authorization = `token ${privateToken}`;
|
||||
|
||||
if (this.privateToken !== '') {
|
||||
headers.Authorization = `token ${this.privateToken}`;
|
||||
}
|
||||
|
||||
const requestOptions: RequestInit = {
|
||||
|
||||
Reference in New Issue
Block a user