catalog(github): add test get request options

This commit is contained in:
danztran
2020-07-08 14:57:03 +07:00
parent af33400021
commit 48addc9259
2 changed files with 30 additions and 5 deletions
@@ -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 = {